mjzone / bookstore-v2

137 stars 178 forks source link

Amplify Graphql schema issue #34

Open Usmaelabdureman opened 1 year ago

Usmaelabdureman commented 1 year ago

Can anyone solved this issues?

🛑 Your GraphQL Schema is using "@connection", "@key" direct ives from an older version of the GraphQL Transformer. Visit https://docs.amplify.aws/cli/migration/transformer-migratio n/ to learn how to migrate your GraphQL schema.

coldfingersnz commented 5 months ago

I have this same issue as well, any update? Cheers

mblevu commented 3 months ago

Hey, this is how i workaround that... Ref: https://docs.amplify.aws/gen1/javascript/tools/cli/migration/transformer-migration/

Migrate @connection to @hasMany, @hasOne, or @belongsTo as appropriate. For example, if you have:

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! order_id: ID! book: Book @connection(fields: ["book_id"]) order: Order @connection(fields: ["order_id"]) }

You would update it to:

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", queryField: "bookOrdersByBook") order_id: ID! @index(name: "byOrder", queryField: "bookOrdersByOrder") book: Book @belongsTo(fields: ["book_id"]) order: Order @belongsTo(fields: ["order_id"]) }

In this updated schema, the @index directives are applied to the book_id and order_id fields, creating secondary indexes byBook and byOrder that you can use to query BookOrder records by book_id and order_id, respectively. The @belongsTo directives establish one-to-one connections between BookOrder and Book, and between BookOrder and Order