Skip to main content

Subscriptions

GraphQL Subscriptions allow you to establish a bidirectional communication channel between your application and the server, enabling real-time data synchronization and immediate updates. With subscriptions, you can easily build reactive and interactive applications.

Unlike traditional REST APIs where clients must periodically poll the server for updates, GraphQL Subscriptions provide a pub/sub mechanism. This means that clients can subscribe to specific data events, and the server will push updates to subscribed clients as soon as those events occur. This approach significantly reduces unnecessary network traffic and latency, providing a more efficient and responsive experience for your users.

Testing subscriptions

This guide demonstrates how to test subscription connections using Altair

Configuring altair

  1. Download and install the altair client.

  2. Start altair and enter https://graph-prod-sandbox.liv.championdata.io/graphql into the url field.

  1. Hover over the headers icon and click 'Set Headers'

  1. Enter your key into a new header 'x-api-key' and hit 'Save'

  1. Hover over the subscription icon and click 'Subscription URL'

  1. Enter https://graph-prod-sandbox.liv.championdata.io/graphql into the top address field.

  2. Select AWS AppSync as the subsciption type.

  3. Enter the following in to the connection parameters. Be sure to use your API key in the last field.

{
"aws_project_region": "us-west-2",
"aws_appsync_region": "us-west-2",
"aws_appsync_graphqlEndpoint": "wss://graph-prod-sandbox.liv.championdata.io/graphql/realtime",
"aws_appsync_authenticationType": "API_KEY",
"aws_appsync_apiKey": "YOUR_API_KEY"
}

  1. Hit 'Save'

You are now ready to run queries and connect to subscriptions!

Subscriptions

  1. Click the 'Docs' button in the top right.

  1. You should see the following, if not try hitting the refresh icon. If that doesn't work try repeating steps 1 - 9 of configuring altair.

  1. Click on 'Subscription'

  2. Hover over a subscription type and click on 'Add Query'. This will auto-populate a subscription query in the left-most pane.

  1. Set the tournament ID to 10 and select which fields you would like returned by the subscription.

  2. Hit 'Send subscription' and wait for data to arrive. Data will stream through as it updates in real time!