ChilliCream / ChilliCream/graphql-platform
Strawberry Shake request context data.
@michaelstaib is already working on this.
Since Apr 9, 2021.
- Dominant language
- C#
- Stars
- 5.8k
- Forks
- 810
- Avg merge
- 15h 39m
- Merged PRs (30d)
- 98
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.