在 Neo4j Graphql Apollo 服务器类型定义中如何添加带空格的名称?

In Neo4j Graphql Apollo server type definition how to add names with spaces?

我的类型定义是这样的

type COMPANY {
    "AIRLINE SEGMENT": String             
    AIRLINE_TYPE: String
}

我收到一条错误消息

apollo server GraphQLError: Syntax Error: Expected Name, found :

如果我删除 space 和引号,我就不会收到错误消息。我到处搜索,但我没有办法添加带有 space 的名称。

任何帮助将不胜感激。 谢谢

GraphQL 不支持名称中的 spaces。根据 spec,名称必须匹配以下正则表达式:

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

GraphQL 实际上会忽略文档中的 all 白色 space,字符串和注释中的白色 space 除外:

White space is used to improve legibility of source text and act as separation between tokens, and any amount of white space may appear before or after any token. White space between tokens is not significant to the semantic meaning of a GraphQL Document, however white space characters may appear within a String or Comment token.

您可能一开始就不应该在节点名称中使用 space,即使它们在技术上是受支持的。这是 recommended naming convention:

Camel case, beginning with an upper-case character

如果您的数据源 returns 对象的字段名称包含 space,您可以将它们转换为解析器映射中的 "legal" 字段名称。例如,给定一个名为 Company 的类型和一个名为 airlineSegment:

的字段
const resolvers = {
  Company: {
    airlineSegment: company => company['AIRLINE SEGMENT']
  }
}