Skip to content

SchemaGenerator: improve exception when the wrong type is provided #425

@andimarek

Description

@andimarek

Currently when you try to build a schema and an InputType is expected you get a ClassCastException.

This should be improved by a better Exception, which tells the user what type to expect.
There should also be a test to verify it.

Example:

type MutationType {
    addCharacter(character: CharacterInput): 
}
# CharacterInput must be an input, but is a type
type CharacterInput {
    firstName: String
    lastName: String
    family: Boolean
}
type MutationResult {
   success: Boolean
}

Java:

 SchemaCompiler schemaCompiler = new SchemaCompiler();
 TypeDefinitionRegistry compiledSchema = schemaCompiler.compile(schemaString);
  SchemaGenerator schemaGenerator = new SchemaGenerator();
 schemaGenerator.makeExecutableSchema(compiledSchema, buildRuntimeWiring());

Code hints:
https://github.com/graphql-java/graphql-java/blob/master/src/main/java/graphql/schema/idl/SchemaGenerator.java#L210

https://github.com/graphql-java/graphql-java/blob/master/src/main/java/graphql/schema/idl/SchemaGenerator.java#L244

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions