Amplify Push GraphQl架构错误@Connection和@key

发布于 2025-02-11 14:31:27 字数 2530 浏览 2 评论 0原文

我一直在关注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:

https://youtu.be/cWDJoK8zw58

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

∞梦里开花 2025-02-18 14:31:27

看来您的模式缺少一些逻辑语句,因此无需在那里提出@manytomany语句。更新的模式可以如下所示,

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] @hasMany(fields: ["id"])
}

type BookOrder
  @model(queries: null, subscriptions: null)
  @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: ["order_id"])
  order_id: ID! @index(name: "byOrder", sortKeyFields: ["book_id"])
  book: Book @belongsTo(fields: ["book_id"])
  order: Order @belongsTo(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"] }
    ]
 )
  {
  id: ID!
  user: String! @index(name: "byUser")
  date: String
  total: Float
  books: [BookOrder] @hasMany(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}")
}

您现在不应面对问题。

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

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] @hasMany(fields: ["id"])
}

type BookOrder
  @model(queries: null, subscriptions: null)
  @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: ["order_id"])
  order_id: ID! @index(name: "byOrder", sortKeyFields: ["book_id"])
  book: Book @belongsTo(fields: ["book_id"])
  order: Order @belongsTo(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"] }
    ]
 )
  {
  id: ID!
  user: String! @index(name: "byUser")
  date: String
  total: Float
  books: [BookOrder] @hasMany(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}")
}

You should not be facing the issue now.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文