aws-amplify / amplify-cli

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development.
Apache License 2.0
2.81k stars 820 forks source link

how can front end get all the values declared in an enum #4211

Closed arkllc closed 4 years ago

arkllc commented 4 years ago

Which Category is your question related to? amplify cli

Amplify CLI Version Not alpplicable

What AWS Services are you utilizing? Amplify cli, appsync

Provide additional details e.g. code snippets How should the front end try to get all the allowed values that are declared in an enum as part of the schema? Are there any best practices around this.

I am pretty new to GraphQL and AppSync, so please excuse me if this is a dumb question.

UnleashedMind commented 4 years ago

@arkllc Could you be specific on what you are referring to? Where is the enum defined?

SwaySway commented 4 years ago

Hello @arkllc Our getting started documentation goes over how the Amplify CLI generates code for your GraphQL schema. Docs: https://docs.amplify.aws/start/q/integration/react

Should you have any other questions please comment below.

arkllc commented 4 years ago

Sorry for the delayed response.

Suppose I have the following Schema. How can I get the values of the enum defined in the schema from my front end application? I feel that I am missing something obvious.

type Pricing @model (subscriptions: null)
    @key (fields: [ "tier", "combo" ] ) 
    @auth(rules: [{allow: groups, groups: ["SysAdmin", "Sysops","SysSupport","SysBackend"], operations: [create,read,update,delete]},
                  {allow: private, operations: [read]}
                  ]){
  tier: TierType!
  combo: String!
  cost: Float
}

enum TierType {
  STANDARD
  PREMIUM
  PROMOTION_A
  LIST_PRICE
}
SwaySway commented 4 years ago

@arkllc Currently code-gen does not expose the enums. Please follow the enhancement issue here: https://github.com/aws-amplify/amplify-cli/issues/2412

igorkosta commented 4 years ago

@arkllc

query ListEnumValues($enum: String!) {
  enum: __type(name: $enum) {
    enumValues {
      name
    }
  }
}

//Variable:
{ "enum": "TierType" }
github-actions[bot] commented 3 years ago

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.