Closed
Description
Description
Consider the following schema:
type Query {
testOmittedBoolean(value: Boolean): Boolean
}
and the following resolver method:
boolean testOmittedBoolean(boolean value) {
return value;
}
When executing the following query:
query {
testOmittedBoolean
}
we get an exception:
[main] WARN notprivacysafe.graphql.execution.SimpleDataFetcherExceptionHandler - Exception while fetching data (/testOmittedBoolean) : null
java.lang.IllegalArgumentException: null
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at graphql.kickstart.tools.resolver.MethodFieldResolverDataFetcher.get(MethodFieldResolver.kt:261)
at graphql.execution.ExecutionStrategy.fetchField(ExecutionStrategy.java:277)
at graphql.execution.ExecutionStrategy.resolveFieldWithInfo(ExecutionStrategy.java:202)
at graphql.execution.AsyncExecutionStrategy.execute(AsyncExecutionStrategy.java:74)
at graphql.execution.Execution.executeOperation(Execution.java:167)
at graphql.execution.Execution.execute(Execution.java:108)
at graphql.GraphQL.execute(GraphQL.java:598)
at graphql.GraphQL.parseValidateAndExecute(GraphQL.java:529)
at graphql.GraphQL.executeAsync(GraphQL.java:493)
at graphql.GraphQL.execute(GraphQL.java:426)
at graphql.GraphQL.execute(GraphQL.java:398)
at graphql.kickstart.tools.ArgumentsTest.testOmittedBooleanArgument(ArgumentsTest.java:29)
Please note, that in the schema, the argument is optional, and in the resolver it is defined as a primitive ('boolean')
Expected behavior
In past releases, this used to work. If the argument was omitted, a default value of 'false' was passed in.
It broke recently due to the fixes related to #367
The expectation is that this query continues to work as before
Actual behavior
The query fails with an unexpected IllegalArgumentException
Steps to reproduce the bug
Run the following unit test:
public class ArgumentsTest {
@Test
public void testOmittedBooleanArgument() {
GraphQLSchema schema = SchemaParser.newParser()
.schemaString("" +
"type Query {" +
" testOmittedBoolean(bool: Boolean): Boolean" +
"}")
.resolvers(new Resolver())
.build()
.makeExecutableSchema();
GraphQL gql = GraphQL.newGraphQL(schema).build();
ExecutionResult result = gql
.execute(ExecutionInput.newExecutionInput()
.query("" +
"query { " +
" testOmittedBoolean" +
"}")
.context(new Object())
.root(new Object()));
assertTrue(result.getErrors().isEmpty());
assertEquals(false, ((Map<?, ?>) result.getData()).get("testOmittedBoolean"));
}
static class Resolver implements GraphQLQueryResolver {
@SuppressWarnings("unused")
public boolean testOmittedBoolean(boolean bool) {
return bool;
}
}
}