Skip to content

Queries that use a DataLoader executed by a second event of a given subscription returns stale data from the initial event #1210

Closed
@rafd123

Description

Describe the bug
When using subscriptions in conjunction with DataLoaders, queries of subsequent subscription events return stale data.

To Reproduce

  1. Create a query that has a field resolver that leverages a DataLoader
  2. Create a subscription where the field in step 1. is included in the graph
  3. Create a mutation that modifies the underlying data and triggers the subscription in Step 2.
  4. Run the app and subscribe to the subscription in step 2., referencing the field that leverages the DataLoader in Step 1.
  5. With the app running, invoke the mutation in step 3. multiple times with different data each time.
  6. Every time the subscription is triggered, the query run in Step 4. will return stale data after the first event.

The following repo demonstrates the issue: https://github.com/rafd123/SubscriptionIssueRepro

2019-11-16-17 44 05

Expected behavior
When the subscription event is triggered, its query should reflect the current state of the data.

Desktop (please complete the following information):

  • OS: Windows
  • Version 10

Additional context
The issue appears to be caused by the fact that the subscription event queries end up sharing the same service scope as the initial request to create the subscription instead of having their own scope.

Using the example repo, this is what the service scope looks like during the initial subscription event query:

2019-11-16-18 33 43

This is what the service scope looks like after subsequent subscription event queries; note the DataLoader from the initial query is in the scope with the original data:

2019-11-16-18 35 14

2019-11-16-18 39 02

Metadata

Labels

No labels
No labels

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions