【问题标题】:Exception using nested Input Types in GraphQL and Spring Boot在 GraphQL 和 Spring Boot 中使用嵌套输入类型的异常
【发布时间】:2020-05-06 14:18:58
【问题描述】:

我正在尝试创建一个接收如下输入类型的 Mutation:

input Cart {
    items: [CartItem!]!
    client: String!
}

input CartItem {
    productId: Int!
    qty: Int!
}

我的变异是这样的:

type Mutation {
    createOrder(cart: Cart!): Order!
}

但是当我尝试运行我的应用程序时,出现以下异常:

Caused by: com.coxautodev.graphql.tools.SchemaError: Expected type 'CartItem' to be a GraphQLOutputType, but it wasn't!  Was a type only permitted for object types incorrectly used as an input type, or vice-versa?

发生了什么事?

【问题讨论】:

  • 您是否在架构中的其他任何地方使用 CartItem,例如作为 Order 的一部分?
  • 不,在这种情况下只是作为输入类型
  • 你确定你的 Cart 和 CartItem java 类有公共的 getter 吗?

标签: spring-boot graphql graphql-java


【解决方案1】:

Graphql-java-tools的一个已知bug:https://github.com/graphql-java-kickstart/graphql-java-tools/issues/216

输入的 java 类型应该有公共的 getter。

【讨论】:

    【解决方案2】:

    您应该为其各自的 graphql 架构声明启动一个适当的类实现。

    您可以在此处查看示例:https://github.com/MerNat/graphql-spring-boot-nested-input-types-example

    【讨论】:

    • 您好!虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接的答案可能会失效。
    猜你喜欢
    • 2021-02-09
    • 1970-01-01
    • 2021-01-23
    • 1970-01-01
    • 2021-04-24
    • 2018-05-04
    • 2017-01-15
    • 2020-09-01
    • 2019-06-18
    相关资源
    最近更新 更多