-
-
Notifications
You must be signed in to change notification settings - Fork 800
Description
Transport Context Data
In some cases, we want to pass in extra information with a GraphQL request that can be used in the client middleware to enrich the request.
Since Strawberry Shake supports multiple transports we want to do it in a way that does not bind this to a specific transport technology.
Context Directives
This is where context directives come in that we can use on operation definitions.
Let's say we have the following query request where we want to pass along some extra context-data that we can use in the request pipeline to either enrich the transport or even to enrich local processing.
query GetSessions {
sessions {
nodes {
... SessionInfo
}
}
}
fragment SessionInfo on Session {
id
title
}In our example, we want to pass in an object that shall be used to create request headers when this request is executed over HTTP.
For this we will introduce a directive and an input type in the schema.extensions.graphql.
directive @myCustomHeaders(input: MyCustomHeaders!) on QUERY
input MyCustomHeaders {
someProp: String!
}This new directive can now be used on queries and allows us to tell the Strawberry Shake compiler to generate the C# request in a way that we need to pass in the extra information.
query GetSessions($headers: MyCustomHeaders!) @myCustomHeaders(input: $headers) {
sessions {
nodes {
... SessionInfo
}
}
}
fragment SessionInfo on Session {
id
title
}This will result in the generation of a required new parameter on the client.
await conferenceClient.GetSessions.ExecuteAsync(new MyCustomHeaders { SomeProp = "Hello" });This proposal is dependant on work to make the middleware accessible by the user.