You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When the query plan is executed, the query planner calls each relevant GraphQLDataSource, and it passes to it an object containing request; the new request for the data source, and context; this is the context property from the GraphQLRequestContext.
As there are many contexts involved here, lets call the GraphQLRequestContext the request context, and the context property from that object the user context. The type of this object would be GraphQLRequestContext<UserContext>.
The user context is created from the incoming http request in the contextFn argument to the ApolloServer constructor. This context is 'scoped' to the http request; all graphql operations in a single http request will share this object.
The request context is created for each graphql operation, and will be passed to apollo server plugins via the various lifecycle functions. This provides a good mechanism for adding properties to the request context that are useful for request or application diagnostics. Lets use the queryHash property from the request context as an example of data that we want to consume in a GraphQLDataSource. Our request context looks like:
{queryHash: "1234abcd...",context: {..},// user context
... otherfields}
We can see that the sendOperation above will only pass the user context and not the request context to the GraphQLDataSource, therefore preventing the GraphQLDataSource from accessing any data for the operation; in our example use case the queryHash. We cannot store this information in the user context as it is shared by all operations.
The feature request is to allow customisation of the context object that the gateway passes to the GraphQLDataSource so that information specific to operations can be retrieved, or to expose the original request context.
The text was updated successfully, but these errors were encountered:
abernix
transferred this issue from apollographql/apollo-server
Jan 15, 2021
I think it would make sense to add a third topLevelRequestContext: GraphQLRequestContext option to process. (Arguably we could deprecate the context option if we wanted since it would be redundant.)
When the query plan is executed, the query planner calls each relevant
GraphQLDataSource
, and it passes to it an object containingrequest
; the new request for the data source, andcontext
; this is the context property from theGraphQLRequestContext
.We can see this in the current send operation function:
As there are many contexts involved here, lets call the
GraphQLRequestContext
the request context, and the context property from that object the user context. The type of this object would beGraphQLRequestContext<UserContext>
.The user context is created from the incoming http request in the
contextFn
argument to theApolloServer
constructor. This context is 'scoped' to the http request; all graphql operations in a single http request will share this object.The request context is created for each graphql operation, and will be passed to apollo server plugins via the various lifecycle functions. This provides a good mechanism for adding properties to the request context that are useful for request or application diagnostics. Lets use the
queryHash
property from the request context as an example of data that we want to consume in aGraphQLDataSource
. Our request context looks like:We can see that the
sendOperation
above will only pass the user context and not the request context to theGraphQLDataSource
, therefore preventing theGraphQLDataSource
from accessing any data for the operation; in our example use case thequeryHash
. We cannot store this information in the user context as it is shared by all operations.The feature request is to allow customisation of the context object that the gateway passes to the
GraphQLDataSource
so that information specific to operations can be retrieved, or to expose the original request context.The text was updated successfully, but these errors were encountered: