mercurius-js / mercurius

Implement GraphQL servers and gateways with Fastify
https://mercurius.dev/
MIT License
2.35k stars 237 forks source link

Subscriptions in federation mode with different pubsub does not work as expected #413

Open valdestron opened 3 years ago

valdestron commented 3 years ago

I am trying to migrate apollo gateway to mercurius gateway.

Federated service schema is built using @apollo/federation.

Using remote rabbitmq pubsub based on graphql-subscriptions and susbcriptions-transport-ws.

Subscriptions works correctly over federated server. If subscription is used over gateway, GQL_STOP event is not forwarded to the federated server, thus federated server resolver is hanging and will handle messages until server restart.

Reproduction: Source code https://github.com/valdestron/mercurius-subscriptions-test

Steps

  1. Initialize subscription in the gateway

    init_subscription
  2. Send mutation to resolver which will publish a message

    send_mutation
  3. Receive a message in subscription

    receive_message
  4. Disconnect subscription and send few more mutations

    disconnect_subscription_and_send_more_mutations

If you do the same in federation service, you would see that messages are stored in the rabbitmq queue and will be consumed only after subscription is reconnected. In gateway mode, the messages goes to devnull until subscription is reconnected.

mcollina commented 3 years ago

Good spot! Would you like to send a Pull Request to address this issue? Remember to add unit tests.