1
votes

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

1 Answers

1
votes

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.