Skip to content

Commit abc9155

Browse files
docs: Adds context computation documentation
1 parent 3014ba0 commit abc9155

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,21 @@ Response:
9898

9999
See the `graphql` function documentation for advanced configuration options.
100100

101+
### Computing GraphQL Context
102+
103+
The required closure in the `graphql` function is used to compute the `GraphQLContext` object, which is injected into each GraphQL resolver. The `inputs` argument passes in data from the request so that the Context can be created dynamically:
104+
105+
```swift
106+
router.graphql(schema: schema) { inputs in
107+
return GraphQLContext(
108+
userID: inputs.hummingbirdContext.userID,
109+
logger: inputs.hummingbirdContext.logger,
110+
debug: inputs.hummingbirdRequest.headers[.init("debug")!] != nil,
111+
operationName: inputs.graphQLRequest.operationName
112+
)
113+
}
114+
```
115+
101116
### WebSockets
102117

103118
Subscription support via WebSockets can be enabled by calling the `graphqlWebSocket` function on a `Router` whose context conforms to `WebSocketRequestContext`, from the `HummingbirdWebSocket` package:

0 commit comments

Comments
 (0)