Skip to content

ValuesResolver.getArgumentValues throws exception if query does not ask for field #3020

Description

@kbrooks

Describe the bug
ValuesResolver.getArgumentValues throws a NonNullableValueCoercedAsNullException even when

This behavior was introduced in GraphQL 17 or 18 in #2308. Before that, getArgumentValues would return null if no parameter was present.

To Reproduce

Example toy schema based on my own schema:

type Query {
    friends(userId: ID!): FriendConnection
}

type FriendConnection {
    edges: [FriendEdge]
    aggregatedStats(input: StatsInput!): Stats!
}

type FriendEdge {
    cursor: String!
    node: Friend
}

type Friend {
  name: String!
  stats(input: StatsInput!): Stats!
}

input StatsInput {
  fields: [String!]!
}

We use getArgumentValues in our FriendsDataFetcher (which handles Query.friends) to check if we are fetching Friend.stats so we can pre-load the stats and improve performance. Upgrading to GraphQL-Java 18 caused a regression on this data fetcher in the case where we don't ask for the field at all.

        var valuesResolver = new ValuesResolver();
        GraphQLSchema schema = dataFetchingEnvironment.getGraphQLSchema();
        var parentType = (GraphQLObjectType) schema.getType(parentFieldName);
        GraphQLFieldDefinition fieldDef = Introspection.getFieldDef(schema, parentType, fieldName);

This is a simplified version of the query that triggers the issue. Because we don't ask for Friend.stats, if I want to check getArgumentValues for "stats" it will throw that NonNullableValueCoercedAsNullException.

query FriendAggregatedStatsQuery($userId: ID!, statsInput: StatsInput!) {
  friends(userId: $userId) {
    ... on FriendConnection {
      aggregatedStats {
        value
      }
    }
  }
}

Here is a query that will succeed on getArgumentValues:

query FriendStatsQuery($userId: ID!, statsInput: StatsInput!) {
  friends(userId: $userId) {
    ... on FriendConnection {
      edges {
        node {
          friend {
            stats(input: $statsInput) {
              value
            }
          }
        }
      }
    }
  }
}

Is it possible to return getArgumentValues to its previous behavior, or make an alternative that works with my use case?

Activity

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