GraphQL 不支持连字符

Hypen is not supporting GraphQL

我是 graphQL 的新手,当我尝试使用 hyphen/dash 定义模式时它显示错误。但是下划线没有任何问题。

# Type of Hello
enum HowAreYou{
  Hello-Hello
  Hai-Hai
}



throw (0, _error.syntaxError)(source, position, 'Invalid number,         expected digit but got: ' + printCharCode(code) + '.');
 ^
GraphQLError: Syntax Error GraphQL request (176:9) Invalid number,     expected digit but got: "H".

175: enum HowAreYou{
176:   Hello-Hello
         ^
177:   Hai-Hai

这是故意的 -- per the specification,在 GraphQL 中命名实体时,连字符不是有效字符。名称应该符合这种模式:

/[_A-Za-z][_0-9A-Za-z]*/

这意味着只能使用字母、数字和下划线,名称不能以数字开头。

我们可以在我们的架构部分指定需要的枚举,并在我们的解析器部分编写相应的自定义。

const typeDefs = `
  enum Color {
    RED
  };
`

const resolvers = {
  Color: {
    RED: '#FF0000',
  }
};