-
Notifications
You must be signed in to change notification settings - Fork 322
Description
I recently upgraded my project to Spring Boot 3.5.0, which required removing graphql-java-kickstart and migrating to Spring GraphQL.
The existing GraphQL schema is quite complex, so manually defining the schema is not a viable option.
I've been having trouble getting the schema generated from annotations to work correctly.
a) Here I have test setup where schema is defined in resources (with default configuration).
resources/graphql/schema.gqls
type Query {
hello: String
}
@Controller
@GraphQLName("LocationQuery")
public class LocationQueryV1 {
@GraphQLField
@QueryMapping
public String hello() {
return "Hello, world!";
}
}
Request:
query LocationQuery {
hello
}
Response:
{
"data": {
"hello": "Hello, world!"
}
}
Schema fetched using Apollo Server
Indicates exactly one field must be supplied and this field must not be `null`.
"""
directive @oneOf on INPUT_OBJECT
"""Information about pagination in a connection."""
type PageInfo {
"""When paginating forwards, the cursor to continue."""
endCursor: String
"""When paginating forwards, are there more items?"""
hasNextPage: Boolean!
"""When paginating backwards, are there more items?"""
hasPreviousPage: Boolean!
"""When paginating backwards, the cursor to continue."""
startCursor: String
}
type Query {
hello: String
}
So it work as expected.
**b) Here I have test setup where schema is defined using GraphQL annotations. Here I just add configuration and generate schema using annotations (no resources here) **
Configuration change
@Configuration
public class GraphQlConfig {
@Bean
public GraphQlSource source() {
final GraphQLSchema graphQLSchema = GraphQLSchemaBuilder.build(LocationQueryV1.class);
return GraphQlSource.builder(graphQLSchema).build();
}
}
Schema fetched using Apollo Server
Indicates exactly one field must be supplied and this field must not be `null`.
"""
directive @oneOf on INPUT_OBJECT
"""Information about pagination in a connection."""
type PageInfo {
"""When paginating forwards, the cursor to continue."""
endCursor: String
"""When paginating forwards, are there more items?"""
hasNextPage: Boolean!
"""When paginating backwards, are there more items?"""
hasPreviousPage: Boolean!
"""When paginating backwards, the cursor to continue."""
startCursor: String
}
type Query {
hello: String
}
Here schema should be identical with option a.
Request:
query LocationQuery {
hello
}
Response:
ERROR 13-06-2025 19:59:22.700 [http-nio-9005-exec-1] o.s.g.e.ExceptionResolversExceptionHandler - Unresolved NullPointerException for executionId 6b632ab8-6494-750b-0746-aa78deba5304
java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "obj" is null
at java.base/java.lang.reflect.Method.invoke(Method.java:572)
at graphql.annotations.dataFetchers.MethodDataFetcher.get(MethodDataFetcher.java:87)
at graphql.execution.ExecutionStrategy.invokeDataFetcher(ExecutionStrategy.java:510)
at graphql.execution.ExecutionStrategy.fetchField(ExecutionStrategy.java:464)
at graphql.execution.ExecutionStrategy.fetchField(ExecutionStrategy.java:404)
at graphql.execution.ExecutionStrategy.resolveFieldWithInfo(ExecutionStrategy.java:363)
at graphql.execution.ExecutionStrategy.getAsyncFieldValueInfo(ExecutionStrategy.java:328)
I'm not sure if my configuration is incorrect, and I’ve found it quite difficult to locate proper documentation or references on how this should be set up. I'm unsure whether this is a bug or if I'm doing something wrong.
Could someone please point me in the right direction?"