Skip to content
Advertisement

GraphQL Input type declaration for Mutation

I’m new to GraphQL and after some coding I bumped into a problem with declaring an Input type for a Mutation. Here’s my Schema:

type Test {
  id: ID!
  label: String!
}

extend type Query {
  test(id : ID!): Test
  listTests (where: myWhereCondition, orderBy: myOrderByCondition): [Test!]!
}

extend type Mutation {
  createTest(label: String!, testTypes: TestTypesInput): Test!
}

input TestTypesInput {
  testTypes: [IdInput]
}

input IdInput {
  id: ID!
}

When I run my app, I get the error

Caused by: graphql.kickstart.tools.SchemaError: Expected type ‘IdInput’ to be a GraphQLInputType, but it wasn’t! Was a type only permitted for object types incorrectly used as an input type, or vice-versa? at graphql.kickstart.tools.SchemaParser.determineType(SchemaParser.kt:400) ~[graphql-java-tools-11.0.1.jar:na] at graphql.kickstart.tools.SchemaParser.determineInputType(SchemaParser.kt:417) ~[graphql-java-tools-11.0.1.jar:na] at graphql.kickstart.tools.SchemaParser.determineInputType(SchemaParser.kt:410) ~[graphql-java-tools-11.0.1.jar:na] at graphql.kickstart.tools.SchemaParser.createInputObject(SchemaParser.kt:179) ~[graphql-java-tools-11.0.1.jar:na] at graphql.kickstart.tools.SchemaParser.parseSchemaObjects(SchemaParser.kt:79) ~[graphql-java-tools-11.0.1.jar:na] at graphql.kickstart.tools.SchemaParser.makeExecutableSchema(SchemaParser.kt:112) ~[graphql-java-tools-11.0.1.jar:na] at graphql.kickstart.tools.boot.GraphQLJavaToolsAutoConfiguration.graphQLSchema(GraphQLJavaToolsAutoConfiguration.java:143) ~[graphql-kickstart-spring-boot-autoconfigure-tools-11.1.0.jar:na]

I can’t understand what I’m missing, to me the “IdInput” is well declared as input and reading some other examples it looks correct to me, but it clearly isn’t. I tried to declare che IdInput as type insted of input, but it obviously doesn’t work. How can I pass a list of input objects into an input array? If you need more informations I’ll add them, at the moment I’m just mixing some declaration to come up with the correct one, with no success. Thank you in advance for your help!

Advertisement

Answer

Find out this was a misleading error, since the GraphQL schema couldn’t fetch with the Mutation Resolver’s signature method. Instead of pointing out that part, it kept to break in the GraphQL Schema declaration. Once declared the signature method accordingly to the Schema, everything worked out like a charm. Hope it may help someone with this misleading error handling.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement