Skip to content

Instantly share code, notes, and snippets.

@vejrj
Last active August 31, 2021 14:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vejrj/1393cc81fd229065420a98e82119510f to your computer and use it in GitHub Desktop.
Save vejrj/1393cc81fd229065420a98e82119510f to your computer and use it in GitHub Desktop.

When the context is patched outside of apollo-client, then subscribeToMore doesn't inherit this context by Query with the current solution.

Our application wraps all queries and extends their context with services and some extra data. However, it isn't possible to easily wrap subscribeToMore, because it is made with its own empty context inside the ObservableQuery. For this reason, when we want to use these data inside the subscription, we are not able to do so.

Currently, the only way is to use links, but would the following change be a valid resolution of this problem ?

// src/core/ObservableQuery.ts  

public subscribeToMore< 
      TSubscriptionData = TData, 
      TSubscriptionVariables = TVariables 
    >( 
      options: SubscribeToMoreOptions< 
        TData, 
        TSubscriptionVariables, 
        TSubscriptionData 
      >, 
    ) { 
      const subscription = this.queryManager 
        .startGraphQLSubscription({ 
          query: options.document, 
          variables: options.variables, 
-        context: options.context, 
+        context: options.context || _this.options.context, 
        }) 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment