add POC graphql subscription
This commit is contained in:
41
resolvers/projects.js
Normal file
41
resolvers/projects.js
Normal file
@ -0,0 +1,41 @@
|
||||
const { createClient } = require('graphql-ws');
|
||||
const WebSocket = require('ws');
|
||||
|
||||
const client = createClient({
|
||||
url: 'wss://directus.andert.me/graphql',
|
||||
keepAlive: 30000,
|
||||
webSocketImpl: WebSocket,
|
||||
connectionParams: async () => {
|
||||
return { access_token: 'Mb3NMqKwiyesxDeJRTD72VZZ6f4t3mBr' };
|
||||
},
|
||||
on: {
|
||||
opened: () => console.log('Connection opened'),
|
||||
closed: () => console.log('Connection closed'),
|
||||
error: (error) => console.log('Connection error:', error),
|
||||
},
|
||||
});
|
||||
|
||||
client.subscribe(
|
||||
{
|
||||
query: `
|
||||
subscription {
|
||||
projects_mutated {
|
||||
data {
|
||||
text
|
||||
date_updated
|
||||
user_updated {
|
||||
first_name
|
||||
}
|
||||
}
|
||||
event
|
||||
key
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
next: data => console.log('data:', data),
|
||||
error: error => console.error('error:', error),
|
||||
complete: () => console.log('complete'),
|
||||
}
|
||||
);
|
Reference in New Issue
Block a user