My understanding is that null is an acceptable value in a graphql response. So I must either have misunderstood something or i am doing something fundamentally wrong because now i am getting "java.lang.Object@7deb1b9" instead of null.
schema {
query: Query
}
type Query {
greeting: String
}
Graphql looking like this:
final Builder vContextBuilder = new Builder()
.of("locale", mLocale)
.of("securityContext", mSecurityContext);
final ExecutionInput vExecutionInput = ExecutionInput
.newExecutionInput()
.query(mQuery)
.context(vContextBuilder)
.build();
final InputStream vSchemaInputStream = Thread
.currentThread()
.getContextClassLoader()
.getResourceAsStream(SCHEMA_FILE_URI);
final TypeDefinitionRegistry vTypeDefinitionRegistry = new SchemaParser()
.parse(new InputStreamReader(vSchemaInputStream));
final RuntimeWiring vRuntimeWiring = RuntimeWiring.newRuntimeWiring()
.type("Query", typeWiring -> typeWiring
.dataFetcher("greeting", new GreetingFetcher())
)
.build();
final GraphQLSchema vGraphQLSchema = new SchemaGenerator()
.makeExecutableSchema(vTypeDefinitionRegistry, vRuntimeWiring);
final GraphQL vGraphQL = GraphQL.newGraphQL(vGraphQLSchema)
.build();
final ExecutionResult vExecutionResult = vGraphQL.execute(vExecutionInput);
final Map<String, Object> toSpecificationResult = vExecutionResult.toSpecification();
And the Greetingfetcher:
public class GreetingFetcher extends StaticDataFetcher {
public GreetingFetcher() {
super("Hello!");
//super(null);
}
}
Query:
query {
greeting
}
Response from super("Hello!");
:
{
"data": {
"greeting": "Hello!"
}
}
Response from super(null);
:
{
"data": {
"greeting": "java.lang.Object@7deb1b9"
}
}
Should the response not be:
{
"data": {
"greeting": null
}
}
Anyone got any ideas?
Problem was with the imports.
Eclipse had added import graphql.nextgen.GraphQL;
when i changed that to import graphql.GraphQL;
everything worked fine.