2

I want to allow one of the fields to be either 1, 2 or 3. I am not exactly sure how to do that in http://graphql.org/graphql-js/type/

Because I would need to do something like:

var AgeType = new GraphQLEnumType({
  name: 'Age',
  values: {
    1: { value: 0 },
    2: { value: 1 },
    3: { value: 2 }
  }
});

And this doesn't work because the key is a number...

1 Answer 1

2

It's not possible as described here: https://github.com/graphql/graphiql/issues/586

GraphQL require enum values to match [_A-Za-z][_0-9A-Za-z] RegExp

Enum variables have to start with a letter, so you will have to use String or Int type. In order to ensure that only 1,2 and 3 are passed, you may implement some kind of validation rules in the resolvers.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.