Subscription Examples
User Feed Subscription
Subscribe to user-specific events and updates.
subscription SubscribeUserFeed {
subscribeUserFeed {
userId
data
}
}
Group Feed Subscription
Subscribe to group-specific events and updates.
subscription SubscribeGroupFeed($groupId: String!) {
subscribeGroupFeed(groupId: $groupId) {
groupId
data
}
}
Usage Example
Here's how you might use subscriptions in a JavaScript application:
import { createClient } from 'graphql-ws';
import WebSocket from 'ws';
const client = createClient({
url: 'wss://graphql.uk.legalesign.com/graphql',
webSocketImpl: WebSocket,
connectionParams: {
Authorization: `Bearer ${accessToken}`,
},
});
// Subscribe to user feed
const unsubscribeUser = client.subscribe(
{
query: `
subscription SubscribeUserFeed {
subscribeUserFeed {
userId
data
}
}
`,
},
{
next: (data) => {
console.log('User feed update:', data);
},
error: (err) => {
console.error('User feed error:', err);
},
complete: () => {
console.log('User feed subscription completed');
},
}
);
// Subscribe to group feed
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 update:', data);
},
error: (err) => {
console.error('Group feed error:', err);
},
complete: () => {
console.log('Group feed subscription completed');
},
}
);
// Clean up subscriptions when done
// unsubscribeUser();
// unsubscribeGroup();