Skip to content

DataFetchingEnvironment.getSelectionSet().getFields() is broken from Mutations after upgrade to graphql-java 16 #2117

@artem-ag

Description

@artem-ag

Describe the bug
Trying to invoke dataFetchingEnvironment.getSelectionSet().getFields() from a Mutation results in graphql.AssertException: no field with name mutationFieldName found in object Query exception being thrown out.

This seems be caused by https://github.com/graphql-java/graphql-java/blob/master/src/main/java/graphql/normalized/NormalizedQueryTreeFactory.java#L55 that assume that root is always a Query.

This worked fine in graphql-java 15, and is broken after upgrade to graphql-java 16.

To Reproduce
From a DataFetcher that's registered to resolve a Mutation field invoke something like below:

DataFetchingFieldSelectionSet selectionSet = environment.getSelectionSet();
if (selectionSet.getFields().stream().allMatch(field -> SUPPORTED_FIELDS.contains(field.getName()))) { return "xyz"; }

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