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

vsrivatsan89 picture vsrivatsan89  路  78Comments

ghost picture ghost  路  84Comments

chuckatc picture chuckatc  路  81Comments

nomadus picture nomadus  路  57Comments

jmandivarapu1 picture jmandivarapu1  路  49Comments