jcrygier / graphql-jpa

JPA Implementation of GraphQL (builds on graphql-java)
MIT License
165 stars 46 forks source link

"Attribute could not be mapped to GraphQL" with @Enumerated Enum #5

Closed timtebeek closed 8 years ago

timtebeek commented 8 years ago

As seen in: https://github.com/timtebeek/graphql-jpa-enum When using the following:

public enum Genre {
    DRAMA, HORROR, MYSTERY, THRILLER
}
@Entity
public class Book {
    @Id
    Long id;

    String title;

    @ManyToOne
    Author author;

    @Enumerated(EnumType.STRING)
    Genre genre;
}

And loading my application context in a test, I get the following stacktrace:

...
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.crygier.graphql.GraphQLExecutor]: Factory method 'graphQLExecutor' threw exception; nested exception is java.lang.UnsupportedOperationException: Attribute could not be mapped to GraphQL: org.hibernate.jpa.internal.metamodel.SingularAttributeImpl@54ae1240
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    ... 42 common frames omitted
Caused by: java.lang.UnsupportedOperationException: Attribute could not be mapped to GraphQL: org.hibernate.jpa.internal.metamodel.SingularAttributeImpl@54ae1240
    at org.crygier.graphql.GraphQLSchemaBuilder.getAttributeType(GraphQLSchemaBuilder.java:151) ~[classes/:na]
    at org.crygier.graphql.GraphQLSchemaBuilder.getObjectField(GraphQLSchemaBuilder.java:96) ~[classes/:na]
...

Trace debugging reveals that the expection is raised for Book.genre. How can the model generation be updated to allow for such a mapped enum field?