amplify codegen creates incomplete statements
See original GitHub issueUsing 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.
- It seems to me that it should include all of the model fields in the return results for a list or get query.
- 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:
- Created 5 years ago
- Comments:12 (4 by maintainers)
Top GitHub Comments
I found that just using
amplify codegen --max-depth 6
does not work.I had to do
amplify codegen configure
and set themax-depth
there and then it worked like a charm.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.