Describe the bug
When using query to get a data A which contains list of another data type B. The type B has an Enum value. The Enum type is missing in the generated queries.js.
To Reproduce
Steps to reproduce the behavior:
And here is the entirety of my amplify/backend/api/appsynctestapp/build/schema.graphql:
type Recipe @model {
id: ID!
title: String!
description: String!
ingredients: [String]
instructions: [String]
photos: [Photo] @connection(name: "RecipePhotosConnection")
pack: Pack @connection(name: "PackRecipesConnection")
}
type Photo @model {
id: ID!
title: String!
description: String
url: String!
type: PhotoType
primary: Boolean
recipe: Recipe @connection(name: "RecipePhotosConnection")
}
type Pack @model {
id: ID!
title: String!
description: String!
recipes: [Recipe] @connection(name: "PackRecipesConnection")
}
enum PhotoType {
PHOTO_TYPE_SMALL
PHOTO_TYPE_LARGE
}
After calling Amplify codegen
I noticed that the ENUM PhotoType (filenname "type") in my Photo objects was not being returned when I made queries using graphqlOperation. I can see that it's present when I query specifically for Photo (getPhoto), but not when I query for Recipe (getRecipe), which has a one-to-many relationship with Photo. Here are the generated queries from src/graphql/queries.js in my amplify project:
export const getPhoto = `query GetPhoto($id: ID!) {
getPhoto(id: $id) {
id
title
description
url
type
primary
recipe {
id
title
description
ingredients
instructions
}
}
}
`;
export const getRecipe = `query GetRecipe($id: ID!) {
getRecipe(id: $id) {
id
title
description
ingredients
instructions
photos {
items {
id
title
description
url
primary
}
nextToken
}
pack {
id
title
description
}
}
}
`;
Expected behavior
When generate the code of getRecipe, the photo should contain the PhotoType value.
Desktop (please complete the following information):
Additional context
npm list -g graphql-versioned-transformer
/usr/local/lib
└─┬ @aws-amplify/[email protected]
└─┬ [email protected]
└── [email protected]
In the meantime, is there a manual workaround that will persist after codegen? (Other than changing the type to a String, which is what I'll do for now.)
I have exactly the same issue. Nested types are missing from the generated listItems query, but not from the single getItem query.
Truncated queries.js, note votes present in getItem but not listItems:
// eslint-disable
// this is an auto generated file. This will be overwritten
export const getItem = `query GetItem($id: ID!) {
getItem(id: $id) {
id
options {
imageKey
base64Preview
votes {
user
at
}
}
}
}
`;
export const listItems = `query ListItems(
$filter: ModelDilemmaFilterInput
$limit: Int
$nextToken: String
) {
listDilemmas(filter: $filter, limit: $limit, nextToken: $nextToken) {
items {
id
options {
imageKey
base64Preview
}
}
nextToken
}
}
`;
Adding it back manually works, but gets overwritten with amplify codegen. Happened after I updated to the multienv version, not sure if that's related.
$ npm list -g graphql-versioned-transformer
/usr/local/lib
└─┬ @aws-amplify/[email protected]
└─┬ [email protected]
└── [email protected]
Being new to amplify and graphql, I could benefit from seeing an example of adding the nested items to the generated queries. I'm OK with altering the queries after each codegen.
Just copy them over from the single item query so they match. See my code above where you would copy votes { … } from getItem and paste it inside options { … } in listItems.
Most helpful comment
Just copy them over from the single item query so they match. See my code above where you would copy
votes { … }fromgetItemand paste it insideoptions { … }inlistItems.