Skip to content

Commit aa27925

Browse files
authored
Merge pull request #132 from visual-knight/expose-authorization-token-to-subscription
Provide authorization token to the subscription context to be able to…
2 parents 3fce66a + 2e838fb commit aa27925

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ The `props` argument accepts the following fields:
8484
> 1. Provide `typeDefs` and `resolvers` and omit the `schema`, in this case `graphql-yoga` will construct the `GraphQLSchema` instance using [`makeExecutableSchema`](https://www.apollographql.com/docs/graphql-tools/generate-schema.html#makeExecutableSchema) from [`graphql-tools`](https://github.com/apollographql/graphql-tools).
8585
> 2. Provide the `schema` directly and omit `typeDefs` and `resolvers`.
8686
87-
> (\*\*) Notice that the `req` argument is an object of the shape `{ request, connection }` which either carries a `request: Request` property (in case it's a `Query`/`Mutation` resolver) or a `connection: SubscriptionOptions` property (in case it's a `Subscription` resolver). [`Request`](http://expressjs.com/en/api.html#req) is imported from Express.js. `SubscriptionOptions` is from the [`graphql-subscriptions`](https://github.com/apollographql/graphql-subscriptions) package.
87+
> (\*\*) Notice that the `req` argument is an object of the shape `{ request, connection }` which either carries a `request: Request` property (in case it's a `Query`/`Mutation` resolver) or a `connection: SubscriptionOptions` property (in case it's a `Subscription` resolver). [`Request`](http://expressjs.com/en/api.html#req) is imported from Express.js. `SubscriptionOptions` is from the [`graphql-subscriptions`](https://github.com/apollographql/graphql-subscriptions) package. `SubscriptionOptions` are getting the connectionParams automatically injected under `SubscriptionOptions.context.[CONNECTION_PARAMETER_NAME]`
8888
8989
Here is example of creating a new server:
9090

src/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ export class GraphQLServer {
237237
schema: this.executableSchema,
238238
execute,
239239
subscribe,
240+
onConnect: async (connectionParams, webSocket) => {
241+
return { ...connectionParams }
242+
},
240243
onOperation: async (message, connection, webSocket) => {
241244
let context
242245
try {

0 commit comments

Comments
 (0)