Datasources missing in the context when using subscriptions
See original GitHub issueIntended outcome: Context in the resolver functions will contain dataSources
field when using subscriptions just like when calling with queries.
Actual outcome: Field dataSources
is missing while using subscriptions in the context (in subscribe
and resolve
functions). The context contains everything except this one field.
How to reproduce the issue:
- set
dataSources
to the server
const server = new ApolloServer({
schema: Schema,
dataSources: () => createDataSources(),
// ...
})
- dump content of the context:
subscribe: (parent, args, context) => {
console.warn(context); // dataSources missing, every other field is there correctly
})
I think this is quite serious because otherwise, I cannot query my data sources at all while using subscriptions.
Issue Analytics
- State:
- Created 5 years ago
- Comments:23 (4 by maintainers)
Top Results From Across the Web
Subscriptions in Apollo Server - Apollo GraphQL Docs
Each subscription operation can subscribe to only one field of the Subscription type. Enabling subscriptions. Subscriptions are not supported by Apollo Server ...
Read more >node.js - Can't access this.context inside a defined class and ...
Show activity on this post. So my issue is trying to access the context inside this class. It always returns undefined. Now I...
Read more >Why ERROR "DefaultDataSource is missing [jboss.naming ...
Issue. If the default datasource ExampleDS is removed from JBoss EAP, applications are not getting deployed successfully, even though those ...
Read more >Handling data source errors (Power Query) - Microsoft Support
Advice on how to identify, deal with, and resolve errors from externals data sources and Power Query when you refresh data.
Read more >Troubleshoot Subscriptions - Tableau Help
However, if the background process is handling an extraordinarily large and complex dashboard, that may not be enough time. You can check the...
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
Unfortunately, this is a known issue. Although we run
SubscriptionServer
as part ofApolloServer
, the request pipeline is completely separate. That means features like persisted queries, data sources, and tracing don’t currently work with subscriptions (or queries and mutations over the WebSocket transport).There is work underway on a refactoring of the
apollo-server-core
request pipeline that will make it transport independent, and that will allow us to build the WebSocket transport on top of it. Until then, I’m afraid there isn’t much we can do.I solved this by using @PatrickStrz method with some little tweak to have each Datasource instance to have the full context, Same way apollo server initializes its Datasources
Hope this helps 😃