@connection 必须位于 @model 对象类型字段上
@connection must be on an @model object type field
我有一个像这样的用于 AWS 的小型 graphQL 结构,但是当我尝试推送它时抛出一个错误提示
✖ An error occurred when pushing the resources to the cloud
@connection must be on an @model object type field.
请帮助理解我哪里出错了。
是否有任何 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
}
当您在产品类型上创建关系时
store: Store @connection(name: "StoreProducts", sortField: "crearedAt")
您必须告诉服务器如何查找这些项目。通过哪个字段名称。这就是为什么您收到此错误“@connection 必须位于 @model 对象类型字段上。”
解决方案是添加 fields
。在类型Product上如果你想带Store Products,你需要添加“id”字段。
store: Store @connection(name: "StoreProducts", fields:["id"] sortField: "crearedAt")
在所有其他类型中,如果你想有关系,你必须定义一个方便的字段来查询数据。
我有一个像这样的用于 AWS 的小型 graphQL 结构,但是当我尝试推送它时抛出一个错误提示
✖ An error occurred when pushing the resources to the cloud
@connection must be on an @model object type field.
请帮助理解我哪里出错了。
是否有任何 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
}
当您在产品类型上创建关系时
store: Store @connection(name: "StoreProducts", sortField: "crearedAt")
您必须告诉服务器如何查找这些项目。通过哪个字段名称。这就是为什么您收到此错误“@connection 必须位于 @model 对象类型字段上。”
解决方案是添加 fields
。在类型Product上如果你想带Store Products,你需要添加“id”字段。
store: Store @connection(name: "StoreProducts", fields:["id"] sortField: "crearedAt")
在所有其他类型中,如果你想有关系,你必须定义一个方便的字段来查询数据。