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.

graphql-transformer does not generate enum fields when the item in a nested query.

See original GitHub issue

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):

  • OS: MAC - JavaScript, React

Additional context npm list -g graphql-versioned-transformer /usr/local/lib └─┬ @aws-amplify/cli@0.1.38 └─┬ amplify-provider-awscloudformation@0.1.38 └── graphql-versioned-transformer@1.0.34

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

2reactions
tobivcommented, Dec 31, 2018

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.

1reaction
asciimocommented, Dec 24, 2018

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.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

API (GraphQL) - Setup authorization rules - AWS Amplify Docs
Owner authorization specifies whether a user can access or operate against an object. To do so, each object will get an ownerField field...
Read more >
What you need to know about GraphQL enums
Learn how GraphQL enums can help you build more robust and discoverable APIs, create simple interfaces, maintain slim resolvers, and more.
Read more >
Generate enum from deeply nested xsd elements
When I generate the code during maven build, my enums are of type string. Here's an example. <xs:element name="Car"> <xs:complexType> <xs: ...
Read more >
GraphQL Transform - GitHub Pages
This would create and configure a single query field post(id: ID!): Post and no mutation fields. # Generates. A single @model directive configures...
Read more >
enum in Java - GeeksforGeeks
Enums are used when we know all possible values at compile time, ... It is not necessary that the set of constants in...
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