Skip to content

doyleyoung/apollo-graphql-subscriptions-example

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 

Repository files navigation

Apollo GraphQL Subscriptions Example

Simple application used to demonstrate minimalistic setup for an Apollo GraphQL Subscriptions architecture.

System Architecture

  .---------.                            .--------.
  | Client  |-.        GET /             | Web    |
  | Browser | | -----------------------> | Server |
  '---------' |                          '--------'
    '---------'
         |
         |                               .---------.
         |          GET /graphiql        | GraphQL |
         '-----------------------------> | Server  |
                    Websocket            '---------'
  • Browser starts by connecting to Web App and fetch available messages
  • Web page opens websocket tunnel to GraphQL server and subscribes to new messages
  • GraphQL mutations can then be submitted to the GraphQL server and new messages submitted to websocket clients for browser update

Start Susbcription Client and Server apps

In a terminal do:

cd server-app
yarn start

In another terminal

cd client-app
yarn start

Test it

  1. Open a browser window with the client page
  2. Open another browser window with GraphiQL and press ►

Your client page should now be displaying the new message.

Using CURL to exercise GraphQL Mutation:

curl -k -H "Content-Type: application/json" -X POST -d '{ "operationName": null, "query": "mutation { addMessage(message: \"My CURL message\") }", "variables": "{}" }' http://localhost:5060/graphql

Using the withApollo decorator

For an example using the withApollo decorator see the withApollo branch.

Using Apollo's susbcribeToMore

Checkout subscribeToMore branch for an example implementation using Apollo's subscribeToMore subscription callback function.

About

Apollo GraphQL Subscriptions issue

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •