微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无权访问IFreightDriver类型的ID

如何解决无权访问IFreightDriver类型的ID

我已经使用其自定义响应定义了一个自定义查询,如下所示:

input ILocations {
  id: String
  address: String
  latitude: String
  longitude: String
  city: String
  state: String
}

type IBox {
  id: ID
  type: String
  depth: Float
  height: Float
  width: Float
}

type ITruck {
  id: ID
  basePrice: Float
  brand: String
  model: String
  yearModel: Int
  axes: Int
  hasGPS: Boolean
  tons: Float
  utilityPercentage: Float
  fuelEfficiency: Float
  fuelType: FuelType
  frontPhoto: String
  sidePhoto: String
  backPhoto: String
  measuresPhoto: String
  truckBoxId: ID
  truckFreightDriverId: ID
  Box: IBox
}

type IFreightDriver {
  id: ID
  state: String
  city: String
  truck: ITruck
}

type Query {
  quotations(
    origin: ILocations
    destination: ILocations
    BoxType: String
    BoxSize: Float
    truckTons: Float
  ): [IFreightDriver]
    @function(name: "quotations-${env}")
    @auth(rules: [{ allow: public,provider: iam }])
}

如果我在AppSync仪表板上执行此查询

query {
  quotations (
    origin: {
        address: "sdas"
        latitude: "sdas"
        longitude: "dsa"
        city: "Guadalajara",state: "Jalisco"
    },destination: {
      address: "sdas"
      latitude: "sdas"
      longitude: "dsa"
      city: "Zapopan",BoxType: "Seca (cerrada)",BoxSize: 64,truckTons: 12
  ) {
    id
  }
}

我收到有关权限的错误消息:

{
  "data": {
    "quotations": [
      {
        "id": null
      }
    ]
  },"errors": [
    {
      "path": [
        "quotations","id"
      ],"data": null,"errorType": "Unauthorized","errorInfo": null,"locations": [
        {
          "line": 20,"column": 5,"sourceName": null
        }
      ],"message": "Not Authorized to access id on type IFreightDriver"
    }
  ]
}

但是,如果我对来自lambda的响应进行了字符串化,然后将查询更改为接收字符串,如下所示:

  quotations(
    origin: ILocations
    destination: ILocations
    BoxType: String
    BoxSize: Float
    truckTons: Float
  ): String
    @function(name: "quotations-${env}")
    @auth(rules: [{ allow: public,provider: iam }])

我正确收到了回复...

{
  "data": {
    "quotations": "[{\"id\":\"19847d0c-185c-48f6-9e5c-435e3907133a\",\"state\":\"Jalisco\",\"city\":\"Zapopan\",\"truck\":{\"__typename\":\"Truck\",\"model\":\"1234\",\"tons\":12,\"yearModel\":2020,\"measuresPhoto\":\"freight-driver/19847d0c-185c-48f6-9e5c-435e3907133a/trucks/qzo1x9g7kvb51.jpg\",\"truckFreightDriverId\":\"19847d0c-185c-48f6-9e5c-435e3907133a\",\"createdAt\":\"2020-08-13T21:02:36.305Z\",\"brand\":\"chevrolet\",\"fuelEfficiency\":12,\"truckBoxId\":\"b3d9000f-0464-4c3d-b436-f380b19d6fd5\",\"backPhoto\":\"freight-driver/19847d0c-185c-48f6-9e5c-435e3907133a/trucks/QCzn1_mWetzZjAFavJYSaug4F2IMAeOAzJa7T6rhC5Q.jpg\",\"frontPhoto\":\"freight-driver/19847d0c-185c-48f6-9e5c-435e3907133a/trucks/dlb0275xqna51.png\",\"utilityPercentage\":12,\"updatedAt\":\"2020-08-13T21:02:36.305Z\",\"sidePhoto\":\"freight-driver/19847d0c-185c-48f6-9e5c-435e3907133a/trucks/ebcpyk19csa51.jpg\",\"fuelType\":\"premium\",\"hasGPS\":true,\"id\":\"b7ec3b05-78c6-4ed9-823d-172a1e9991e5\",\"axes\":12,\"Box\":{\"__typename\":\"Box\",\"width\":4,\"height\":4,\"updatedAt\":\"2020-08-13T21:02:35.840Z\",\"depth\":4,\"createdAt\":\"2020-08-13T21:02:35.840Z\",\"id\":\"b3d9000f-0464-4c3d-b436-f380b19d6fd5\",\"type\":\"Seca (cerrada)\"}},\"basePrice\":null}]"
  }
}

为什么要求这些权限?如果有人需要我收到的回复

[
    {
        "id": "19847d0c-185c-48f6-9e5c-435e3907133a","state": "Jalisco","city": "Zapopan","truck": {
            "__typename": "Truck","model": "1234","tons": 12,"yearModel": 2020,"measuresPhoto": "freight-driver/19847d0c-185c-48f6-9e5c-435e3907133a/trucks/qzo1x9g7kvb51.jpg","truckFreightDriverId": "19847d0c-185c-48f6-9e5c-435e3907133a","createdAt": "2020-08-13T21:02:36.305Z","brand": "chevrolet","fuelEfficiency": 12,"truckBoxId": "b3d9000f-0464-4c3d-b436-f380b19d6fd5","backPhoto": "freight-driver/19847d0c-185c-48f6-9e5c-435e3907133a/trucks/QCzn1_mWetzZjAFavJYSaug4F2IMAeOAzJa7T6rhC5Q.jpg","frontPhoto": "freight-driver/19847d0c-185c-48f6-9e5c-435e3907133a/trucks/dlb0275xqna51.png","utilityPercentage": 12,"updatedAt": "2020-08-13T21:02:36.305Z","sidePhoto": "freight-driver/19847d0c-185c-48f6-9e5c-435e3907133a/trucks/ebcpyk19csa51.jpg","fuelType": "premium","hasGPS": true,"id": "b7ec3b05-78c6-4ed9-823d-172a1e9991e5","axes": 12,"Box": {
                "__typename": "Box","width": 4,"height": 4,"updatedAt": "2020-08-13T21:02:35.840Z","depth": 4,"createdAt": "2020-08-13T21:02:35.840Z","id": "b3d9000f-0464-4c3d-b436-f380b19d6fd5","type": "Seca (cerrada)"
            }
        },"basePrice": null
    }
]

更新:我也尝试更改lambda响应以仅返回一个ID数组,如下所示:

来自lambda的回复[ { id: '19847d0c-185c-48f6-9e5c-435e3907133a' } ]

AppSync错误

{
  "data": {
    "quotations": [
      {
        "id": null
      }
    ]
  },"message": "Not Authorized to access id on type IFreightDriver"
    }
  ]
}

schema.graphql:

type IFreightDriver {
  id: ID
}

type Query {
  quotations(
    origin: ILocations
    destination: ILocations
    BoxType: String
    BoxSize: Float
    truckTons: Float
  ): [IFreightDriver]
    @function(name: "quotations-${env}")
    @auth(rules: [{ allow: public,provider: iam }])
}

解决方法

您必须提供访问IFreightDriver的权限。由于您要为查询设置auth而不是在对象上进行访问/返回(在您的情况下为IFreightDriver),因此它会引发权限错误。但是,当您将查询切换为仅返回字符串时,无需为此设置任何权限,这就是为什么看不到任何错误的原因。仅返回id的{​​{1}}时,情况相同。除非您在IFreightDriver上设置权限,否则它将不允许您访问ID。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。