I am trying to find the best way for a microservice to communicate with GraphQL
Basic scenario:
- Client subscribed to GraphQL via Subscriptions (WebSockets)
- Client creates an Item using Mutation which will notify all the subscribed clients that the Item was created.
- There is a case when a Worker microservice would need to create an Item { type: "external" }.
How would a worker talk to GraphQL?
GraphQL uses a token authentication, so if were to set up direct communication, we would need to generate a specific token for a worker, but it also doesn't feel right for a microservice to talk to GraphQL directly using Apollo Client for requests.
Potential ideas:
- From Worker push events to a queue and GraphQL server to implement a polling mechanism to pull events from the queue. A concern here is that GraphQL is running as a stateless web app and now needs to implement that stateful polling functionality.
- From Worker push events to a queue and implement a separate event handler that will perform the same work as GraphQL is doing, e.g. create an Item and notify GraphQL via PubsSb mechanism, so that GraphQL can notify clients.