ChilliCream / ChilliCream/graphql-platform

Strawberry Shake request context data.

Open
#3,467 28 comments 23 reactions 1 assignee View on GitHub

@michaelstaib is already working on this.

Since Apr 9, 2021.

🌶️ strawberry shake
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.