1

How is a Java enum correctly registered with GraphQL when using the kickstart framework with spring?

In attempting to use a GraphQL schema enum with an equivalent Java enum in a simple Java Spring application, the following exception is thrown:

Caused by: graphql.kickstart.tools.SchemaError: Expected enum with name 'CarType' but found none!
at graphql.kickstart.tools.SchemaParser.createEnumObject(SchemaParser.kt:191)
at graphql.kickstart.tools.SchemaParser.parseSchemaObjects(SchemaParser.kt:85)
at graphql.kickstart.tools.SchemaParser.makeExecutableSchema(SchemaParser.kt:112)
at graphql.kickstart.tools.boot.GraphQLJavaToolsAutoConfiguration.graphQLSchema(GraphQLJavaToolsAutoConfiguration.java:147)
at graphql.kickstart.tools.boot.GraphQLJavaToolsAutoConfiguration$$EnhancerBySpringCGLIB$$1b4eddf2.CGLIB$graphQLSchema$1(<generated>)

How is the Java side enum class registered? I've seen examples with RuntimeWiring and registering them via this but the schema creation is done automatically for my usage so I cannot find a way (or the correct hook) to achieve this.

The GraphQL schema is:

extend type Query {
    cars : [Car]
}

type Car {
    type : CarType
}

enum CarType {
    AUDI,
    BMW,
    VOLKSWAGEN
}

And the Java enum:

public enum CarType {
    AUDI, BMW, VOLKSWAGEN
}

1 Answer 1

0

So in the code I didn't post, I was deliberately using a HashMap instead of a Dto pojo class with the enum residing inside:

public class CarsResolver implements GraphQLQueryResolver {
    public Collection<HashMap> cars() {
        return emptyList();
    }
}

This meant (I think) that the class in the collection wasn't ever traversed by the framework to create the resolver for the enum auto-magically... this resulted in the above exception.

The reason (by the way) I was deliberately using a HashMap was to avoid a generic graphql gateway from knowing about the Dto types in our broader system. I am now rethinking this decision :-)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.