[放大] 在创建多对多关系之后,查询未正确生成

首先

这也是一个不熟悉数据库操作的弱弱前端工程师的跌倒记录~~~

环境

放大
GraphQL
Next.js

情况

    • GraphQLスキーマ にて多対多のリレーションを作成した後に、createやdeleteはできるが、ローカルだとquery叩くとリレーションしたデータが返ってこない、、、

 

    amplify mock apiして、モックURL上でクエリを叩く分には、多対多のリレーションデータも返ってくる
スクリーンショット 2021-12-20 8.49.56.png

type Resource @model {
  id: ID!
  categoryId: ID!
  userId: ID!
  title: String!
  url: String!
  category: Category @connection(fields: ["categoryId"])
  users: [ResourceUser] @connection(keyName: "byResource", fields: ["id"])
}

type ResourceUser
  @model(queries: null)
  @key(name: "byResource", fields: ["resourceId", "userId"])
  @key(name: "byUser", fields: ["userId", "resourceId"]) {
  id: ID!
  resourceId: ID!
  userId: ID!
  resource: Resource! @connection(fields: ["resourceId"])
  user: User! @connection(fields: ["userId"])
}
type User @model {
  id: ID!
  name: String!
  email: String!
  profileImagePath: String!
  progressRate: Int!
  resourcesCount: Int!
  posts: [Post] @connection(keyName: "postsByUserId", fields: ["id"])
  resources: [ResourceUser] @connection(keyName: "byUser", fields: ["id"])
}


结论

我会在以下说明解决!!



$ amplify configure codegen
? Choose the code generation language target javascript
? Enter the file name pattern of graphql queries, mutations and subscriptions src/graphql/**/*.js
? Enter maximum statement depth [increase from default if your schema is deeply nested] 4

$ amplify codegen
â Downloaded the schema
â Generated GraphQL operations successfully and saved at src/graphql


请提供参考文献。

结束

我真心希望”amplify”默认设为4,笑了起来。

广告
将在 10 秒后关闭
bannerAds