apollographql / apollo-link

:link: Interface for fetching and modifying control flow of GraphQL requests
https://www.apollographql.com/docs/link/
MIT License
1.44k stars 344 forks source link

Feature request: make SchemaLink support subscriptions for integration testing #374

Open jedwards1211 opened 6 years ago

jedwards1211 commented 6 years ago

I'm planning to do this if no one else is already working on it.

Why support subscriptions in SchemaLink?

SchemaLink seems primarily intended for SSR, so it doesn't support subscriptions, because SSR doesn't need them (and should not subscribe to anything anyway).

But SchemaLink is also useful for lightweight integration testing. Right now, to perform end-to-end tests on an Apollo view container component that uses subscriptions, there are two options:

  1. (Heavyweight) Test the running webapp in the browser with Selenium
  2. (Medium weight) Run an HTTP server with subscriptions-transport-ws in test code use enzyme to mount an individual view container inside an <ApolloProvider> connected via WebSocketLink

If SchemaLink supports subscriptions it would provide a third option:

  1. (Lightweight) use enzyme to mount an individual view container inside an <ApolloProvider> connected via SchemaLink

But wouldn't this cause problems with SSR?

It's probably best if SchemaLink subscriptions aren't enabled by default, to ensure that subscribeToMore is a no-op during SSR. Integration tests could simply pass something like a {subscriptions: true} option to turn them on.

praveenweb commented 6 years ago

Any progress on this?

wawhal commented 6 years ago

I can work on a PR if it is not already being worked on. Someone ack please.

jedwards1211 commented 6 years ago

So I said I was planning to do this but...haven't had time 😆

justinmahar commented 4 years ago

An opt-in {subscriptions: true} option for this would be fantastic. I need this for mocking subscriptions during development.

Until then, I'm looking into using the PR @fubhy submitted for support: https://github.com/apollographql/apollo-link/pull/916