Connect to AppSync Subscriptions
This guide shows how to connect to the Legalesign AppSync websocket endpoint and start consuming GraphQL subscriptions.
Use this page for connection setup.
Use these pages for payload handling:
Before You Start
You need:
- a valid access token
- the Legalesign GraphQL endpoint
- a websocket-capable GraphQL client
Get an access token first:
Endpoints
HTTP GraphQL endpoint:
https://graphql.uk.legalesign.com/graphql
Websocket endpoint:
wss://graphql.uk.legalesign.com/graphql
Authentication
Pass your access token when opening the websocket connection.
Typical connection params:
{
"Authorization": "Bearer <access-token>"
}
Subscription Operations
User Feed
subscription SubscribeUserFeed {
subscribeUserFeed {
userId
data
}
}
Group Feed
subscription SubscribeGroupFeed($groupId: String!) {
subscribeGroupFeed(groupId: $groupId) {
groupId
data
}
}
JavaScript Example
This example uses graphql-ws:
import { createClient } from 'graphql-ws';
import WebSocket from 'ws';
const accessToken = '<access-token>';
const client = createClient({
url: 'wss://graphql.uk.legalesign.com/graphql',
webSocketImpl: WebSocket,
connectionParams: {
Authorization: `Bearer ${accessToken}`,
},
});
const unsubscribeUser = client.subscribe(
{
query: `
subscription SubscribeUserFeed {
subscribeUserFeed {
userId
data
}
}
`,
},
{
next: ({ data }) => {
console.log('user feed message', data);
},
error: (err) => {
console.error('user feed error', err);
},
complete: () => {
console.log('user feed closed');
},
}
);
const unsubscribeGroup = client.subscribe(
{
query: `
subscription SubscribeGroupFeed($groupId: String!) {
subscribeGroupFeed(groupId: $groupId) {
groupId
data
}
}
`,
variables: {
groupId: '<your-group-id>',
},
},
{
next: ({ data }) => {
console.log('group feed message', data);
},
error: (err) => {
console.error('group feed error', err);
},
complete: () => {
console.log('group feed closed');
},
}
);
// Later:
// unsubscribeUser();
// unsubscribeGroup();
Parse the Inner Payload
The subscription field returns a wrapper plus a JSON string in data.
Parse the inner payload before routing on category or event:
const parseEnvelope = (payload) => {
const raw = payload?.data;
if (!raw) return null;
return typeof raw === 'string' ? JSON.parse(raw) : raw;
};
Example:
next: ({ data }) => {
const wrapper = data?.subscribeGroupFeed;
const event = parseEnvelope(wrapper);
console.log(event.category, event.event, event.data);
}
Reconnect and Token Refresh
Production clients should:
- reconnect automatically if the websocket drops
- refresh expired access tokens
- reopen subscriptions after reconnect
If subscriptions stop receiving updates after a long-running session, the first thing to check is token expiry.