我想允许其中一个字段为1,2或3.我不确定如何在http://graphql.org/graphql-js/type/
中执行此操作因为我需要做类似的事情:
var AgeType = new GraphQLEnumType({
name: 'Age',
values: {
1: { value: 0 },
2: { value: 1 },
3: { value: 2 }
}
});
这不起作用,因为密钥是一个数字......
答案 0 :(得分:0)
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.