Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ValidationError FieldUndefined SPQR GraphQL

I am getting the following and cant seem to find an answer.

Error [ValidationError{validationErrorType=FieldUndefined, queryPath=[find_by_id], message=Validation error of type FieldUndefined: Field 'find_by_id' in type 'Query' is undefined @ 'find_by_id', locations=[SourceLocation{line=1, column=2}], description='Field 'find_by_id' in type 'Query' is undefined'}]

My Code.

Query

@GraphQLQuery(name = "find_by_id")
public Event findById(@GraphQLArgument(name = "id") Long id) {

Schema Gen

@EJB
private EventFacade eventFacade; // Normal stateless bean 

GraphQLSchema guestSchema = new GraphQLSchemaGenerator()
            .withOperationsFromSingleton(eventFacade)
            .withValueMapperFactory(new JacksonValueMapperFactory())
            .withDefaults()
            .generate();

GraphQL graphQL = GraphQL.newGraphQL(guestSchema).build();

Code to Execute

String query = "{find_by_id (id: 1){eventName}}";
ExecutionResult result = graphQL.execute(query);

Using the SPQR lib

Event POJO is basic with eventName as a String and an id from the abstract (Parent) class. Entity class is in a different jar (Entity Jar). Code to execute Query and build schema are in the EJB Jar.

Any help / indication where i went wrong will be appreciated.

UPDATE Created a git issue to help solve Git Issue

like image 441
Tinus Jackson Avatar asked Apr 26 '18 12:04

Tinus Jackson


2 Answers

I found this solution here: https://github.com/leangen/graphql-spqr/wiki/Errors#ambiguous-member-type

Reference: To treat all missing type arguments as Object or apply custom type transformation logic, supply a TypeTransformer:

This should work for you.

    GraphQLSchema schema = new GraphQLSchemaGenerator()
           .withBasePackages(basePackages)
           .withTypeTransformer(new DefaultTypeTransformer(true, true))
           .withOperationsFromSingleton(eventFacade).generate();
like image 70
T.Kruger Avatar answered Nov 19 '22 00:11

T.Kruger


I believe you must change this String query = "{find_by_id (id: 1){eventName}}"; to String query = "\"query\": {find_by_id (id: 1){eventName}}";

like image 1
Manav Bhanot Avatar answered Nov 19 '22 02:11

Manav Bhanot