Spring-Boot GraphQL QueryResolver is not called

1.8k Views Asked by At

When I call a query in graphiQL i get the following response

{
  "errors": [
    {
      "message": "The field at path '/customers' was declared as a non null type, but the code involved in retrieving data has wrongly returned a null value.  The graphql specification requires that the parent field be set to null, or if that is non nullable that it bubble up null to its parent and so on. The non-nullable type is '[Customer!]' within parent type 'Query'",
      "path": [
        "customers"
      ],
      "extensions": {
        "classification": "NullValueInNonNullableField"
      }
    }
  ],
  "data": null
}

Query:

    query{
     customers {
      id
      email
     }

}

The Problem is that my GraphQLQuery Resolver dont get called. I did a Breakpoint and the Application doesnt break there.

GraphQLQueryResolver:

@RequiredArgsConstructor
@Component
public class Query implements GraphQLQueryResolver {

    private final CustomerRepository customerRepository;
    
    public Flux<Customer> customers() {
        return customerRepository.findAll();
    }
    
}

query.graphqls:

type Query{
    customers: [Customer!]!
}

customer.graphqls:

type Customer {
    id: ID!,
    email: String!
}
1

There are 1 best solutions below

3
On

This is expected as GraphQLQueryResolver is a type from the graphql-java-kickstart project. Spring for GraphQL is not related at all to this project.