Amplify-js: How to access AppSync (Amplify graphql API) enum values

Created on 11 Mar 2019  路  2Comments  路  Source: aws-amplify/amplify-js

* Which Category is your question related to? *
API

* What AWS Services are you utilizing? *
Appsync via Amplify

* Provide additional details e.g. code snippets *
I want to access possible enum values in order to programmatically generate React components, e.g. a dropdown input with option tags. What is the advised way of accessing and/or exposing enums via Appsync? Access to the enums is not included in the generated code.

AppSync question

Most helpful comment

On advice from @jordanranz and some more research into graphql introspection, I was able to get at my enums with this query:

export const listEnumValues = `query ListEnumValues($enum: String!) {
  enum: __type(name: $enum) {
    enumValues {
      name
    }
  }
}`;

All 2 comments

Hey @kwhitejr,

There are two ways to do this:

  1. Through aws cli: https://docs.aws.amazon.com/cli/latest/reference/appsync/get-introspection-schema.html
  2. Creating an introspection query in your Appsync api: https://graphql.org/learn/introspection/
    example: https://github.com/graphql/graphql-js/blob/master/src/utilities/introspectionQuery.js#L20

I believe your use case calls for option 2.

On advice from @jordanranz and some more research into graphql introspection, I was able to get at my enums with this query:

export const listEnumValues = `query ListEnumValues($enum: String!) {
  enum: __type(name: $enum) {
    enumValues {
      name
    }
  }
}`;
Was this page helpful?
0 / 5 - 0 ratings

Related issues

cosmosof picture cosmosof  路  3Comments

benevolentprof picture benevolentprof  路  3Comments

TheRealRed7 picture TheRealRed7  路  3Comments

romainquellec picture romainquellec  路  3Comments

cgarvis picture cgarvis  路  3Comments