Amplify Push GraphQl架构错误@Connection和@key
我一直在关注YouTube教程,以在线创建和销售书籍。在教程中,有一个为订单设计GraphQL方案的情况。我已经看到,迁移的细节已更新,并试图遵守新法规,我遇到了很多错误。我尝试解决其中的大多数,但有些仍然持久。由于这是我第一次使用GraphQL和AWS,因此我无法进一步进步。 YouTube链接如下:
https://youtu.be/cwdjok8z8zw58
type Book
@model(subscriptions: null)
@auth(
rules: [
#allow admins to create, update and delete books
{ allow: groups, groups: ["Admin"] }
# allow all authenticated users to view books
{ allow: private, operations: [read] }
# allow all guest users (not authenticated) to view books
{ allow: public, operations: [read] }
]
)
{
id: ID!
title: String!
description: String
image: String
author: String
featured: Boolean
price: Float
orders: [BookOrder] @hasOne(keyName: "byBook", fields: ["id"])
}
type BookOrder
@model(queries: null, subscriptions: null)
#@key(name: "byBook", fields: ["book_id", "order_id"])
#@key(name: "byOrder", fields: ["order_id", "book_id"])
@auth(
rules: [
# allow admins to create bookorders for customers by using customer email in lambda
{ allow: owner, identityClaim: "email", ownerField: "customer" }
{ allow: groups, groups: ["Admin"] }
]
)
{
id: ID!
book_id: ID! @index(name: "byBook", sortKeyFields: ["book_id, order_id"])
order_id: ID! @index(name: "byOrder", sortKeyFields: ["order_id, book_id"])
book: Book @hasOne(fields: ["book_id"])
order: Order @hasOne(fields: ["order_id"])
}
type Order
@model(subscriptions: null)
@auth(
rules: [
# only owner can see his orders
{ allow: owner, identityClaim: "email", ownerField: "customer" }
#allow admins to view orders
{ allow: groups, groups: ["Admin"] }
]
)
#@key(name: "byUser", fields: ["user"])
{
id: ID!
user: String! @index(name: "byUser", sortKeyfields: ["user"])
date: String
total: Float
books: [BookOrder] @manyToMany(keyName: "byOrder", fields: ["id"])
}
enum OrderStatus {
SUCCESS
FAILED
}
input CartItem {
id: ID!
title: String
image: String
price: Float
amount: Int
}
input ProcessOrderInput {
id: ID!
cart: [CartItem]
total: Float!
token: String!
address: String
}
type Mutation {
processOrder(input: ProcessOrderInput!): OrderStatus
@function(name: "processPayment-${env}")
@function(name: "createOrder-${env}")
}
显示错误消息如下:如下所示:如下所示:如下::
n error occurred when pushing the resources to the cloud
I have been following a YouTube tutorial to create and sell books online. In the tutorial, there has been a case of designing a GraphQL scheme for the orders. I have seen that the migrate details have been updated and have tried to adhere to the new regulations,I have faced a lot of errors. I tried solving most of them but some remain persistent. As this is my first time working with Graphql and AWS, I cannot progress any further. Youtube Link is provided below:
type Book
@model(subscriptions: null)
@auth(
rules: [
#allow admins to create, update and delete books
{ allow: groups, groups: ["Admin"] }
# allow all authenticated users to view books
{ allow: private, operations: [read] }
# allow all guest users (not authenticated) to view books
{ allow: public, operations: [read] }
]
)
{
id: ID!
title: String!
description: String
image: String
author: String
featured: Boolean
price: Float
orders: [BookOrder] @hasOne(keyName: "byBook", fields: ["id"])
}
type BookOrder
@model(queries: null, subscriptions: null)
#@key(name: "byBook", fields: ["book_id", "order_id"])
#@key(name: "byOrder", fields: ["order_id", "book_id"])
@auth(
rules: [
# allow admins to create bookorders for customers by using customer email in lambda
{ allow: owner, identityClaim: "email", ownerField: "customer" }
{ allow: groups, groups: ["Admin"] }
]
)
{
id: ID!
book_id: ID! @index(name: "byBook", sortKeyFields: ["book_id, order_id"])
order_id: ID! @index(name: "byOrder", sortKeyFields: ["order_id, book_id"])
book: Book @hasOne(fields: ["book_id"])
order: Order @hasOne(fields: ["order_id"])
}
type Order
@model(subscriptions: null)
@auth(
rules: [
# only owner can see his orders
{ allow: owner, identityClaim: "email", ownerField: "customer" }
#allow admins to view orders
{ allow: groups, groups: ["Admin"] }
]
)
#@key(name: "byUser", fields: ["user"])
{
id: ID!
user: String! @index(name: "byUser", sortKeyfields: ["user"])
date: String
total: Float
books: [BookOrder] @manyToMany(keyName: "byOrder", fields: ["id"])
}
enum OrderStatus {
SUCCESS
FAILED
}
input CartItem {
id: ID!
title: String
image: String
price: Float
amount: Int
}
input ProcessOrderInput {
id: ID!
cart: [CartItem]
total: Float!
token: String!
address: String
}
type Mutation {
processOrder(input: ProcessOrderInput!): OrderStatus
@function(name: "processPayment-${env}")
@function(name: "createOrder-${env}")
}
The error message being shown is as follows:
n error occurred when pushing the resources to the cloud
???? An error occurred during the push operation: /
Schema validation failed.
Unknown argument "keyName" on directive "@hasOne".
GraphQL request:21:31
20 | price: Float
21 | orders: [BookOrder] @hasOne(keyName: "byBook", fields: ["id"])
| ^
22 | }
Unknown argument "sortKeyfields" on directive "@index". Did you mean "sortKeyFields"?
GraphQL request:56:40
55 | id: ID!
56 | user: String! @index(name: "byUser", sortKeyfields: ["user"])
| ^
57 | date: String
Unknown argument "keyName" on directive "@manyToMany".
GraphQL request:59:34
58 | total: Float
59 | books: [BookOrder] @manyToMany(keyName: "byOrder", fields: ["id"])
| ^
60 | }
Unknown argument "fields" on directive "@manyToMany".
GraphQL request:59:54
58 | total: Float
59 | books: [BookOrder] @manyToMany(keyName: "byOrder", fields: ["id"])
| ^
60 | }
Directive "@manyToMany" argument "relationName" of type "String!" is required, but it was not provided.
GraphQL request:59:22
58 | total: Float
59 | books: [BookOrder] @manyToMany(keyName: "byOrder", fields: ["id"])
| ^
60 | }
⚠️ Review the Amplify CLI troubleshooting guide for potential next steps: https://docs.amplify.aws/cli/project/troubleshooting/
How do I resolve this error? Following the newly updated was-amplify docs, it seems right. But it is not working
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来您的模式缺少一些逻辑语句,因此无需在那里提出@manytomany语句。更新的模式可以如下所示,
您现在不应面对问题。
It seems like your schema is missing a few logic statements, there is no need of putting up @manyTomany statements there. The updated Schema can be done as shown below
You should not be facing the issue now.