Empowering the people to choose their own host. πΊπΈπ¨βπ¨βπ§βπ¦π¨βπ©βπ¦βπ¦πΊπΈ
In this activity, you'll work on adding subscription support to the Election GraphQL API.
- Run
npm installat the root of the project which will install all dependencies for theapiand theclient. - Run
npm startwhich will start the API project. - Open
localhost:4000to find the Playground. - Open
localhost:4000/resultsto see the Client project running. - With the Playground, send a test mutation to the API to vote for one of the hosts:
mutation {
vote(host: ALEX)
}- Refresh
localhost:4000/resultsto see the vote registered in the graph.
Q: Can we live in a world where this app needs to be refreshed every time there is a change?
A: No, we cannot. We need to enable GraphQL Subscriptions for the server.
The Client is already set up for subscriptions. All changes should be made to the API.
- Add a Subscription to the schema that will watch for a change in the
Resultstype. - Set up the server to handle subscriptions.
- Adjust the resolvers to handle that subscription.