react-apollo icon indicating copy to clipboard operation
react-apollo copied to clipboard

Expose context in useSubscription options

Open xEcEz opened this issue 4 years ago • 4 comments

Would it be possible to expose context in useSubscription options?

I have a use case where I need to set the URI dynamically for a given subscription. Currently, I am stuck with having to declare another client that uses it by default, where in a similar scenario but when using useQuery, I can simply set the context's URI on the fly.

xEcEz avatar Nov 02 '19 14:11 xEcEz

@xEcEz I'm having the same issue. Stuck with this. Did you get any workaround for this?

prince3339 avatar Nov 28 '19 16:11 prince3339

No, I am still using another ApolloClient on the side that declares a WebSocketLink which uses the target URI.

xEcEz avatar Nov 29 '19 10:11 xEcEz

@xEcEz I don't understand why the team still hasn't given any attention to this issue :(

prince3339 avatar Dec 06 '19 17:12 prince3339

We can use a very unreliable crutch for now: add a comment to the query string. For instance:

#QUERY_TYPE=${type}#
  subscription f( ...

And check in the split method:

split(
  (op) => {
    const sourceQuery = op.query.loc.source.body;
    return sourceQuery.search(new RegExp('#QUERY_TYPE=${type}#')) !== -1;
  },
  link1,
  link2
)

ReshaSD avatar May 18 '20 16:05 ReshaSD