【问题标题】:Can't have Input Types with nested fields in GraphQL. Error: Expected type to be a GraphQLInputType, but it wasn't在 GraphQL 中不能有带有嵌套字段的输入类型。错误:预期类型是 GraphQLInputType,但不是
【发布时间】:2021-01-10 11:03:39
【问题描述】:

我有一个查询,我想在其中输入购物车对象的嵌套结构。我还定义了与 Kotlin 中的数据类完全相同的结构。

这是schema.graphqls

type Query {
    calculatePalletDeliveryCosts(input: ShoppingCartInput): Int
}

input ShoppingCartInput {
    products: [ShoppingCartProductInput!]!,
}

input ShoppingCartProductInput {
    productOrderDetails: ProductOrderDetailsInput
}

input ProductOrderDetailsInput {
    orderUnits: [OrderUnitInput]
    quantity: Float!
}

input OrderUnitInput {
    code: String!
}

这些是对应的类:

data class ShoppingCartInput (
    val products: List<ShoppingCartProductInput>,
)

data class ShoppingCartProductInput(
    val productOrderDetails: ProductOrderDetailsInput
)

data class ProductOrderDetailsInput(
    val orderUnit: OrderUnitInput,
    val quantity: Float
)

data class OrderUnitInput(
    val code: String
)

但是启动应用程序上下文总是会产生:

原因:org.springframework.beans.factory.BeanCreationException:在类路径资源 [graphql/kickstart/tools/boot/GraphQLJavaToolsAutoConfiguration.class] 中定义名称为“graphQLSchema”的 bean 创建错误:通过工厂方法实例化 bean 失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [graphql.schema.GraphQLSchema]:工厂方法“graphQLSchema”抛出异常;嵌套异常是 graphql.kickstart.tools.SchemaError: Expected type 'OrderUnitInput' to be a GraphQLInputType,但它不是!一个类型是否只允许用于错误地用作输入类型的对象类型,反之亦然?

【问题讨论】:

    标签: java spring spring-boot kotlin graphql


    【解决方案1】:

    我刚刚意识到我的schema.graphqls 不一致。

    架构说:

    input ProductOrderDetailsInput {
        orderUnits: [OrderUnitInput]
        quantity: Float!
    }
    

    但是课程是

    
    data class ProductOrderDetailsInput(
        val orderUnit: OrderUnitInput,
        val quantity: Float
    )
    

    我都匹配了,所以现在可以了

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-30
      • 2018-11-27
      • 2014-06-04
      • 2018-12-18
      • 2020-12-09
      • 2017-09-21
      • 1970-01-01
      • 2017-08-16
      相关资源
      最近更新 更多