【问题标题】:@connection must be on an @model object type field@connection 必须在 @model 对象类型字段上
【发布时间】:2021-10-08 17:19:57
【问题描述】:

我有一个类似 AWS 的小型 graphQL 结构,但是当我尝试推送它时会抛出一个错误提示

✖将资源推送到云端时出错

@connection 必须在 @model 对象类型字段上。

请帮助了解我在哪里犯了错误。

有没有 VS 代码扩展来调试这个?

type Store {
  id: ID!
  products: [Product] @connection(name: "StoreProducts")
}

type Product @model @searchable {
  id: ID!
  name: String!
  description: String!
  price: Float!
  isOnCourse: Boolean!
  isOnOutlet: Boolean!
  store: Store @connection(name: "StoreProducts", sortField: "crearedAt")
  file: S3Object!
}

type S3Object {
  bucket: String!
  region: String!
  key: String!
}

type User
  @model(
    queries: { get: "getUser" }
    mutations: { create: "registredUser", update: "updateUser" }
    subscriptions: null
  ) {
  id: ID!
  username: String!
  email: String!
  phoneNumber: String!
  registred: Boolean
  orders: [Order] @connection(name: "UserOrders", sortField: "createdAt")
}

type Order
  @model(
    queries: null
    mutations: { create: "createOrder" }
    subscriptions: null
  ) {
  id: ID!
  product: Product @connection
  user: User @connection(name: "UserOrders")
  orderLocation: OrderLocation
  crearedAt: String
}

type OrderLocation {
  tableNumber: String
  qrData: String
  holeNumber: String
}

【问题讨论】:

    标签: amazon-web-services graphql aws-amplify


    【解决方案1】:

    当您在 Product 类型上创建关系时

    store: Store @connection(name: "StoreProducts", sortField: "crearedAt")
    

    你必须告诉服务器如何寻找物品。通过哪个字段名称。这就是为什么您会收到此错误“@connection must be on an @model object type field。”

    解决方案是添加fields。如果要带商店产品,请在输入产品时添加“id”字段。

    store: Store @connection(name: "StoreProducts", fields:["id"] sortField: "crearedAt")
    

    在所有其他类型中,如果你想有关系,你必须定义一个方便的字段来查询数据。

    【讨论】:

      猜你喜欢
      • 2017-06-12
      • 1970-01-01
      • 2019-02-25
      • 2020-04-18
      • 2020-04-19
      • 1970-01-01
      • 2017-10-17
      • 1970-01-01
      • 2020-01-01
      相关资源
      最近更新 更多