我是graphQL的新手,当我尝试使用连字符/破折号定义模式时,它显示错误。但是下划线没有任何问题。
# 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
答案 0 :(得分:0)
在GraphQL中命名实体时,有意的 - per the specification连字符不是有效字符。名称应该符合这种模式:
/[_A-Za-z][_0-9A-Za-z]*/
这意味着只允许使用字母,数字和下划线,名称不能以数字开头。
答案 1 :(得分:0)
我们可以在架构部分中指定所需的枚举,并在解析器部分中编写相应的自定义。
const typeDefs = `
enum Color {
RED
};
`
const resolvers = {
Color: {
RED: '#FF0000',
}
};