简体   繁体   English

获取不支持的令牌`on` [GraphQL]

[英]Getting Unsupported token `on` [GraphQL]

Issue: We goto 'on' in the query, while build apollo is complaining about the on keyword in the query (*.graphql)问题:我们在查询中转到“on”,而 build apollo 抱怨查询中的 on 关键字 (*.graphql)

GraphQL query: GraphQL 查询:

query TimeLine($inputData: InputData!) {
    getTimeLine(inputData: $inputData) {
        on
        updated
 }
}

Error: Unsupported token on (com.apollographql.apollo.compiler.parser.GraphQLDocumentParseException).错误:不支持on令牌(com.apollographql.apollo.compiler.parser.GraphQLDocumentParseException)。

Env: Kotlin, apolloGraphQLVersion: "1.3.2"环境:Kotlin,apolloGraphQLVersion:“1.3.2”

This happens because the on keyword is a reserved keyword in GraphQL.这是因为on关键字是 GraphQL 中的保留关键字。

One of the Type Conditions is on NamedType, see the official spec file of GraphQL .类型条件之一是on NamedType 上,请参阅 GraphQL的官方规范文件

query FragmentTyping {
  profiles(handles: ["zuck", "cocacola"]) {
    handle
    ...userFragment
    ...pageFragment
  }
}

fragment userFragment on User {
  friends {
    count
  }
}

fragment pageFragment on Page {
  likers {
    count
  }
}

See the on used in fragment userFragment on User ?看到fragment userFragment on User on Your GraphQL got confused because you are using on as a field within the query, while it expects to be a fragment.您的 GraphQL 感到困惑,因为您在查询中使用on作为字段,而它期望是一个片段。 Read more about fragments here .在此处阅读有关片段的更多信息 Also, a fragment's name can be anything, except for on , see the official spec file .此外,片段的名称可以是任何名称,除了on ,请参阅官方规范文件

One way to solve this issue might be to rename the field in your query, but I am not sure if GraphQL will complain about this approach as well:解决此问题的一种方法可能是重命名查询中的字段,但我不确定 GraphQL 是否也会抱怨这种方法:

query TimeLine($inputData: InputData!) {
    getTimeLine(inputData: $inputData) {
        dataOn: on
        updated
 }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM