Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apollo Server does not always invoke willResolveField plugin hook #4987

Closed
mgilbey opened this issue Mar 5, 2021 · 1 comment
Closed

Apollo Server does not always invoke willResolveField plugin hook #4987

mgilbey opened this issue Mar 5, 2021 · 1 comment

Comments

@mgilbey
Copy link

mgilbey commented Mar 5, 2021

Observed Behaviour

When an Apollo Server using Apollo Gateway fetches data from a GraphQLDataSource it will not always call the willResolveField (#3988) function of supplied plugins. When the GraphQLDataSource is an instance of LocalGraphQLDataSource then the plugin function is invoked, but for another object implementing the GraphQLDataSource interface this does not occur.

Expected Behaviour

willResolveField should be invoked for each field in the response regardless of the GraphQLDataSource implementation.

Reproduction

https://codesandbox.io/s/gateway-willresolvefield-7y82n

Submit the query { a b } to receive the response

{
  "data": {
    "a": "a",
    "b": "b"
  }
}

Observe the console output never reports will resolve field: b

will resolve field: a
QueryPlan {
  Parallel {
    Fetch(service: "a") {
      {
        a
      }
    },
    Fetch(service: "b") {
      {
        b
      }
    },
  },
}

Other Information

The ApolloServerPluginUsageReporting plugin uses the willResolveField function to track field level data for Apollo Studio metrics. The data for gateways that supply their own GraphQLDataSource has all fields marked with zero traffic.

@glasser
Copy link
Member

glasser commented Mar 5, 2021

This is working as intended. willResolveField is called when you’re actually running a resolver for a field in the process. The gateway doesn’t call this because it’s not running resolvers: it’s just forwarding to the subgraph.

The current way this is expected to work is that your subgraph should be using the inline trace plugin (or an equivalent implementation if you’re not using apollo-server in your subgraph) to include details about execution in its response to the gateway, which the gateway then incorporates into its usage reports. This does require your subgraph to be using a GraphQL implementation that supports inline traces.

We do have a designed but not implemented plan to allow gateways to provide field usage information (but not field performance information) to Studio without needing anything special from subgraphs.

@glasser glasser closed this as completed Mar 5, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants