Joaquín L. Robles
Joaquín L. Robles

Reputation: 6494

Exception using nested Input Types in GraphQL and Spring Boot

I'm trying to create a Mutation that receives an input type like this:

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

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

And my Mutation goes like this:

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

But when I try to run my Application I get the following exception:

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?

What's going on?

Upvotes: 0

Views: 2682

Answers (3)

Ldbmcs
Ldbmcs

Reputation: 1

except the input java types should have public getters, the input java types should also implement Serializable interface

Upvotes: 0

MWA
MWA

Reputation: 51

You should initiate a proper class implementation for their respective graphql schema declaration.

You can check an example here: https://github.com/MerNat/graphql-spring-boot-nested-input-types-example

Upvotes: 0

AllirionX
AllirionX

Reputation: 1143

It is a known bug of Graphql-java-tools: https://github.com/graphql-java-kickstart/graphql-java-tools/issues/216

The input java types should have public getters.

Upvotes: 1

Related Questions