question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

amplify codegen creates incomplete statements

See original GitHub issue

Using amplify version 1.1.7

When I run amplify codegen on my schema, it ends up skipping some of the fields in one model and does not include all of the fields for a related model for the “list” statement. I can always go back and manually edit them, but it is a pain to need to do this every time.

So 2 issues/questions.

  1. It seems to me that it should include all of the model fields in the return results for a list or get query.
  2. I would like it to include as many levels deep as I’ve configured it to go for the query result items as well.

Here is the model from Schema.graphql:

type Instrument 
    @model 
    @auth(
    rules: [
      {allow: owner},
      {allow: owner, ownerField: "owner", mutations: [create, update, delete], queries: [get, list]},
      {allow: groups, groups: ["Admin"]}
    ]) 
{
  id: ID!
  owner: String
  name: String!
  category: InstrumentCategory!
  status: InstrumentStatus
  type: InstrumentType!
  manufacturer: String
  model: String
  color: String
  serialNumber: String
  yearManufactured: String
  description: String
  purchasedAt: String
  purchaseLocation: String
  purchasePrice: Float
  purchaseDate: AWSDate
  soldPrice: Float
  soldDate: AWSDate
  images: [S3Object] @connection(name: "InstrumentImages")
}
type S3Object @model {
    id: ID!
    bucket: String!
    key: String!
    region: String!
    order: Int
    instrument: Instrument @connection(name:"InstrumentImages")
}

When I call amplify codegen, the queries look like this:

export const getInstrument = `query GetInstrument($id: ID!) {
  getInstrument(id: $id) {
    id
    owner
    name
    category
    status
    type
    manufacturer
    model
    color
    serialNumber
    yearManufactured
    description
    purchasedAt
    purchaseLocation
    purchasePrice
    purchaseDate
    soldPrice
    soldDate
    images {
      nextToken
    }
  }
}
`;
export const listInstruments = `query ListInstruments(
  $filter: ModelInstrumentFilterInput
  $limit: Int
  $nextToken: String
) {
  listInstruments(filter: $filter, limit: $limit, nextToken: $nextToken) {
    items {
      id
      owner
      name
      manufacturer
      model
      color
      serialNumber
      yearManufactured
      description
      purchasedAt
      purchaseLocation
      purchasePrice
      purchaseDate
      soldPrice
      soldDate
    }
    nextToken
  }
}
`;

Note that for listInstruments, the category and status fields are missing as is images and for getInstrument, the properties of S3Object are missing.

Every time I do amplify codegen I need to go back and manually fix these items.

Graphqlconfig.yml does have maxDepth set to 2 so I would expect that the images fields are filled in for those queries.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
sudeep-quantelaicommented, May 19, 2020

I found that just using amplify codegen --max-depth 6 does not work.

I had to do amplify codegen configure and set the max-depth there and then it worked like a charm.

3reactions
poppybankcommented, Mar 12, 2019

OK, as a user, this is problematic. In order to consistently get the same information back from calls (I always want instruments to include the images) I need to set maxLevel to 4 for listInstruments to work but then calls like getInstrument will include the instrument data multiple times. My recommendation would be to include the items as the level for the thing that includes it so that the getInstruments and listInstruments calls would be much more in sync with the data that is returned.

Read more comments on GitHub >

github_iconTop Results From Across the Web

API (GraphQL) - Client code generation - AWS Amplify Docs
The amplify codegen statements command generates GraphQL statements(queries, mutation and subscription) based on your GraphQL schema.
Read more >
AWS AppSync Developer Guide - Amazon S3
The .graphql files we created above will be used by the AWS AppSync Codegen to generate a strongly typed API code to perform...
Read more >
GENERAL PROVISIONS
The Terre Haute Economic Development Commission is created and shall have the ... 5-11-13-1 must include a Mayor's statement that the City has...
Read more >
All Reports with description
The following script causes a assertion fault in the code generator for ... is the end of the CREATE TRIGGER, tries to execute...
Read more >
Elm Packages
ianmackenzie/elm-step-file … 1.0.1. Create and parse data in ISO 10303-21 (STEP file) format ... Fork of: A (woefully-incomplete) parser for RFC5988 Links ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found