Skip to content

Running a mutation query against a schema without defined mutations throws NullPointerException. #345

Closed

Description

@apottere

With 2.3.0:

java.lang.NullPointerException
	at graphql.execution.ExecutionStrategy.getFieldDef(ExecutionStrategy.java:150)
	at graphql.execution.ExecutionStrategy.resolveField(ExecutionStrategy.java:25)
	at graphql.execution.SimpleExecutionStrategy.execute(SimpleExecutionStrategy.java:18)
	at graphql.execution.Execution.executeOperation(Execution.java:56)
	at graphql.execution.Execution.execute(Execution.java:31)
	at graphql.GraphQL.execute(GraphQL.java:84)

It looks like parentType passed to the execution context is null, causing the error. I'm not quite sure what should be returned, but some GraphQL error should be returned instead (field missing?).

Activity

  1. apottere commented on Mar 20, 2017

    @apottere
    ContributorAuthor

    Note that this is only when using the 1-arg constructor for GraphQLSchema or passing null as the mutation type in the 3-arg constructor. If you pass an "empty" mutation object type, the exception goes away and a GraphQL error is returned to the caller:

    {"errors":[{"validationErrorType":"FieldUndefined","message":"Validation error of type FieldUndefined: Field echo is undefined","errorType":"ValidationError","locations":[{"line":1,"column":12}]}]}
    
  2. bbakerman commented on Mar 21, 2017

    @bbakerman
    Member

    Can you give a code example to help with reproduction.

  3. apottere commented on Mar 21, 2017

    @apottere
    ContributorAuthor

    This throws a NullPointerException:

    public static void main(String[] args) {
        GraphQLObjectType query = GraphQLObjectType.newObject().name("Query").build();
        GraphQLSchema schema = new GraphQLSchema(query);
    
        new GraphQL(schema).execute("mutation { doesNotExist }");
    }

    As does this:

    public static void main(String[] args) {
        GraphQLObjectType query = GraphQLObjectType.newObject().name("Query").build();
        GraphQLSchema schema = new GraphQLSchema(query, null, Stream.of(query).collect(Collectors.toSet()));
    
        new GraphQL(schema).execute("mutation { doesNotExist }");
    }

    This does not:

    public static void main(String[] args) {
        GraphQLObjectType query = GraphQLObjectType.newObject().name("Query").build();
        GraphQLObjectType mutation = GraphQLObjectType.newObject().name("Mutation").build();
        GraphQLSchema schema = new GraphQLSchema(query, mutation, Stream.of(query, mutation).collect(Collectors.toSet()));
    
        new GraphQL(schema).execute("mutation { doesNotExist }");
    }
  4. added 4 commits that reference this issue on Mar 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions