Skip to content

Commit b3c3033

Browse files
author
Shane Myrick
committed
Update docs wording
1 parent 6d6ef1e commit b3c3033

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

docs/execution/contextual-data.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ title: Contextual Data
44
---
55

66
All GraphQL servers have a concept of a "context". A GraphQL context contains metadata that is useful to the GraphQL
7-
server, but shouldn't necessarily be part of the GraphQL query's API. A prime example of something that is appropriate
7+
server, but shouldn't necessarily be part of the GraphQL schema. A prime example of something that is appropriate
88
for the GraphQL context would be trace headers for an OpenTracing system such as
9-
[Haystack](https://expediadotcom.github.io/haystack). The GraphQL query itself does not need the information to perform
10-
its function, but the server itself needs the information to ensure observability.
9+
[Haystack](https://expediadotcom.github.io/haystack). The GraphQL query does not need the information to perform
10+
its function, but the server needs the information to ensure observability.
1111

1212
The contents of the GraphQL context vary across applications and it is up to the GraphQL server developers to decide
1313
what it should contain. For Spring based applications, `graphql-kotlin-spring-server` provides a simple mechanism to
@@ -20,12 +20,16 @@ for additional details
2020

2121
## GraphQLContext Interface
2222

23-
Once your application is configured to build your custom `MyGraphQLContext`, simply mark the class with the `GraphQLContext` interface and the
24-
corresponding GraphQL context from the environment will be automatically injected during execution.
23+
The easiest way to specify a context class is to use the `GraphQLContext` marker interface. This interface does not require any implementations,
24+
it is just used to inform the schema generator that this is the class that should be used as the context for every request.
2525

2626
```kotlin
2727
class MyGraphQLContext(val customValue: String) : GraphQLContext
28+
```
29+
30+
Then you can just use the class as an argument and it will be automaticall injected during execution time.
2831

32+
```kotlin
2933
class ContextualQuery {
3034
fun contextualQuery(
3135
context: MyGraphQLContext,
@@ -51,10 +55,10 @@ Note that the argument that implements `GraphQLContext` is not reflected in the
5155

5256
### GraphQLContext Annotation
5357

54-
From the 1.x.x release we also support marking any argument with the annotaiton `@GraphQLContext`.
55-
If the schema generator sees this annotation on an argument it will assume that this is the class used in the `GraphQLContextFactory` and return the context as this argument value.
56-
This does require though that you mark every usage of the arument with the annotation. This can be helpful if you do no control the implementation of the context
57-
class you are using.
58+
From the 1.0.0 release we also support marking any argument with the annotaiton `@GraphQLContext`.
59+
If the schema generator sees this annotation on an argument, it will assume that this is the context class and inject the context as this argument value.
60+
This does require that you mark **all** usages of the arument with the annotation. This will cause an error if you incorrectly mark the wrong argument,
61+
which is why the interface method may be better, but the annotation can be helpful if you do no control the implementation of the context class you are using.
5862

5963
```kotlin
6064
class MyGraphQLContext(val customValue: String)

0 commit comments

Comments
 (0)