Subscriptions - context not extended
See original GitHub issueHey,
we have upgraded to apollo server 2 and now have trouble with the GraphQL context in the subscription resolvers. We have an ApolloServer and will extend the GraphQL context with some data the client sent during the first connect. In the docs is an example.
We’ve implemeted the onConnect
and return some data:
...
subscriptions: {
onConnect: (connectionParams: ConnectionParams) => {
// do sth. with the connection params
return { some: 'data' };
}
}
...
The documentation says the return value of the onConnect
function extends the GraphQL context. The onConnect
gets executed when a new client connects.
In our resolver we want to do some filtering based on the extended context:
...
subscribe: withFilter(
() => this.pubSub.subscribe('xxx'),
(payload, _, ctx: IGraphQLContext) => {
// do sth. with `ctx.some`
return true;
},
),
But the context in the resolver is always empty.
We are on the latest version of apollo-server-express and subscriptions-transport-ws.
Thank you very much for your help!
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Subscriptions - Apollo GraphQL Docs
Subscriptions are not currently supported in Apollo Federation. ... The GraphQL context can also be extended with the authenticated user data to enable...
Read more >GraphQL Subscription fields not able to access context of ...
I don't get an error if I use the subscription without the postedBy field. I can only assume that the undefined object is...
Read more >Subscription Classes - GraphQL Ruby
You can extend GraphQL::Schema::Subscription to create fields that can be subscribed to. These classes support several behaviors:.
Read more >How GraphQL Subscriptions Work: Tips, Best Practices and ...
This will open up a long-lived connection to the server by sending the subscription query specifying which event it is interested in.
Read more >Context | XState Docs
In XState, extended state is known as context. ... i.e., the context will not be created until the machine is actually created/used:.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The return value of the
onConnect
callback is available in thecontext
function. So you can return it if you build the context for subscriptions.Apollo Server v3 does not have built-in support for subscriptions (we felt that the superficial integration with the unmaintained
subscriptions-transport-ws
package was not up to our standards). https://www.apollographql.com/docs/apollo-server/data/subscriptions/ documents how to integrate Apollo Server with the newergraphql-ws
package, including a whole section on the context value. There’s a link at the bottom to the previous version of the docs which explains how to integrate AS with the unmaintainedsubscriptions-transport-ws
package too if you need to.