#✅ - Please help: can't query many to many using generated API (listArts)

5 messages · Page 1 of 1 (latest)

scenic pike
#

I have a simple setup where each art contains many artists and each artist contains many arts.
I made the schema and generated the data using the web GUI.
When I use the generated API.graphql(graphqlOperation(listArts)) to fetch a list of the artworks, the createdBy field is no where to be found.

This is a cut-down verion of the generated schema.

type Artist @model @auth(rules: [{allow: public}]) {
  id: ID!
  name: String
  arts: [Art] @manyToMany(relationName: "ArtArtist")
}

type Art @model @auth(rules: [{allow: public}]) {
  id: ID!
  name: String
  createdBy: [Artist] @manyToMany(relationName: "ArtArtist")
}

I noticed that there is no createdBy for the generated code

export const listArts = /* GraphQL */ `
  query ListArts(
    $filter: ModelArtFilterInput
    $limit: Int
    $nextToken: String
  ) {
    listArts(filter: $filter, limit: $limit, nextToken: $nextToken) {
      items {
        id
        name
        createdAt
        updatedAt
        _version
        _deleted
        _lastChangedAt
      }
      nextToken
      startedAt
    }
  }
`;

This tutorial clearly claims that you can just list the entries and access the many to many field. (https://docs.amplify.aws/cli/graphql/data-modeling/#many-to-many-relationship). Any help on this is hugely appriciate!

scenic pike
#

Please help: can't query many to many using generated API (listArts)

sage hull
#

Try running "amplify codegen", sometimes I have to do that manually to update the local queries

scenic pike
#

Solved, the issue is that depth is set to 2. I ran amplify codegen config to increase the depth and now it's fine.

little pivotBOT
#

✅ - Please help: can't query many to many using generated API (listArts)