Skip to content

Latest commit

 

History

History
38 lines (26 loc) · 1.55 KB

File metadata and controls

38 lines (26 loc) · 1.55 KB

GRAPHQL SUBSCRIPTIONS

DESCRIPTION

EXAMPLE OF NODE.JS USING:

  • GRAPHQL SUBSCRIPTIONS: LIKE QUERIES, SUBSCRIPTIONS ENABLE YOU TO FETCH DATA. UNLIKE QUERIES, SUBSCRIPTIONS ARE LONG-LASTING OPERATIONS THAT CAN CHANGE THEIR RESULT OVER TIME. THEY CAN MAINTAIN AN ACIVE CONNECTION TO YOUR GRAPHQL SERVER (MOST COMMONLY VIA WEBSOCKET), ENABLING THE SERVER TO PUSH UPDATES TO THE SUBSCRIPTION'S RESULT. SUBSCRIPTIONS ARE USEFUL FOR NOTIFYING YOUR CLIENT IN REAL TIMA ABOUT CHANGES TO BACK-END DATA, SUCH AS CREATION OF NEW OBJECT OR UPDATES TO AN IMPORTANT FIELD.
  • ALTAIR GRAPHQL CLIENT: A GRAPHICAL, INTERACTIVE AND IN-BROWSER GRAPHQL IDE.

PREREQUISITES

  • NODEMON: FOLLOW THE INSTRUCTIONS HERE.
  • EXPRESS: FOLLOW THE INSTRUCTIONS HERE.
  • TYPESCRIPT: FOLLOW THE INSTRUCTIONS HERE.
  • GRAPHQL MODULES: FOLLOW THE INSTRUCTIONS HERE.

REQUIRED PACKAGES

  • FOR SUBSCRIPTIONS:
npm install ws
npm install -D @types/ws # ONLY IF WORKING WITH TYPESCRIPT
npm install graphql-ws
npm install graphql-subscriptions
  • FOR ALTAIR GRAPHQL CLIENT:
npm install altair-static

EXAMPLE (GRAPHQL WITH SUBSCRIPTIONS)

npm run tsc-nodemon --jsfile=./folderDist/folderTopics/folderGraphqlSubscriptions/exampleGraphqlSubscriptions.js