LoginSignup
4
0

More than 1 year has passed since last update.

[Amplify] 多対多のリレーション作成後、queriesが正しく生成されない

Last updated at Posted at 2021-12-19

はじめに

これもDB操作に不慣れな弱々フロントエンドエンジニアのつまづき記録です~~~

環境

amplify
GraphQL
Next.js

状況

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

  • amplify mock apiして、モックURL上でクエリを叩く分には、多対多のリレーションデータも返ってくる

スクリーンショット 2021-12-20 8.49.56.png

schema.graphQL

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


参考資料

終わりに

「デフォルトで4で設定しといてよ、amplifyさん」って心から思いました笑

4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0