apollographql / apollographql/apollo-server
Expose operationDerivedData from ApolloServerPluginUsageReporting to request context for external reporting capabilities
- Dominant language
- TypeScript
- Stars
- 14k
- Forks
- 2k
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 2
Description
ApolloServerPluginUsageReporting plugin calculates and caches request signature and used fields for safely submit usage to schema registry.
Request signature is used instead of raw query to eliminate risk of exposure literals as well as normalize queries with literals into a single entry.
Unfortunately this information is not getting exposed into request context for other plugins to leverage, e.g. external logging and telemetry.
In our particular case, we've effectively duplicated the effort of calculation request signatures.
Requesting exposing this information, e.g. adding new fields `querySignature?: string` and `querySignatureHash?: string` to `GraphQLRequestContext` interface.
Note 1. `createOperationDerivedDataCache` generates LRU Cache with pretty expensive `sizeCalculation` method implementation, resulting in unnecessary string and byte array instantiation only to calculate a memory footprint, it would be beneficial to allow user to supply LRU cache instance, similar to how it's done in query planner cache.
Note 2. `operationDerivedDataCache.forSchema !== schema` comparison seems a little fragile and possibly expensive, subscribing to `serverWillStart#schemaDidLoadOrUpdate` event and clear the cache seems to be more robust approach.
Contributor guide
Research direction
Begin with ApolloServerPluginUsageReporting and the GraphQLRequestContext interface, then trace createOperationDerivedDataCache and its use of operationDerivedDataCache. Review the serverWillStart#schemaDidLoadOrUpdate entry point for the cache-lifecycle concern. Done means external plugins can consume the calculated request signature data without duplicating the work, with the cache behavior clarified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, typescript
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100