[英]Can't have Input Types with nested fields in GraphQL. Error: Expected type to be a GraphQLInputType, but it wasn't
I have a query where I want to give as input a nested structure of a shopping cart object.我有一个查询,我想将购物车对象的嵌套结构作为输入。 I also defined the very same structure as data classes in Kotlin.
我还定义了与 Kotlin 中的数据类完全相同的结构。
This is the schema.graphqls
:这是
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!
}
And this these are the corresponding classes:这是相应的类:
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
)
However starting the application context always yields:但是启动应用程序上下文总是会产生:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'graphQLSchema' defined in class path resource [graphql/kickstart/tools/boot/GraphQLJavaToolsAutoConfiguration.class]: Bean instantiation via factory method failed;
引起:org.springframework.beans.factory.BeanCreationException:在类路径资源[graphql/kickstart/tools/boot/GraphQLJavaToolsAutoConfiguration.class]中定义名称为“graphQLSchema”的bean创建错误:通过工厂方法的Bean实例化失败; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [graphql.schema.GraphQLSchema]: Factory method 'graphQLSchema' threw exception;
嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [graphql.schema.GraphQLSchema]:工厂方法“graphQLSchema”抛出异常; nested exception is graphql.kickstart.tools.SchemaError: Expected type 'OrderUnitInput' to be a GraphQLInputType, but it wasn't!
嵌套异常是 graphql.kickstart.tools.SchemaError: 预期类型 'OrderUnitInput' 是 GraphQLInputType,但它不是! Was a type only permitted for object types incorrectly used as an input type, or vice-versa?
是否只允许对象类型错误地用作输入类型,反之亦然?
I just realized I had inconsistency in my schema.graphqls
.我刚刚意识到我的
schema.graphqls
不一致。
Schema says:架构说:
input ProductOrderDetailsInput {
orderUnits: [OrderUnitInput]
quantity: Float!
}
But the class was但是班级是
data class ProductOrderDetailsInput(
val orderUnit: OrderUnitInput,
val quantity: Float
)
I matched them both so now it works我把它们都匹配了,所以现在可以用了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.