gqlws-client
v0.9.0
Published
gqlws-client
Downloads
3
Readme
GQLWS Server
GraphQL over WebSockets (Client)
:warning: Work In Progress
Install
yarn add gqlws-client
or
npm i gqlws-client --save
Use
import gqlws, { setupGQLWS } from 'gqlws-client';
setupGQLWS({
url: `ws://localhost:8080`,
ioOptions: {
transports: ['websocket']
}
});
Events
gqlws.on('connect', () => {
console.log('Connected');
});
gqlws.on('disconnect', () => {
console.log('Disconnected');
});
Query
gqlws.query(gql, variables, callback)
gqlws.query(`
query IsPass {
isPass
}
`, null, (err, res) => {
if (err) {
throw new Error(err);
} else {
console.log(res.isPass);
}
});
Mutate
gqlws.mutate(gql, variables, callback)
gqlws.mutate(`
mutation getProblem {
getProblem
}
`, null, (err, res) => {
if (err) {
throw new Error(err);
} else {
console.log(res.isPass);
}
});
Subscribe
gqlws.subscribe(gql, variables, observer)
subId = gqlws.subscribe(`
subscription testSub($channelName: String!) {
testSub(channelName: $channelName)
}
`, {
channelName: 'kekChannel'
}, (err, res) => {
if (err) {
throw new Error(err);
} else {
console.log(res.testSub);
}
});
Unsubscribe
gqlws.unsubscribe(id)
gqlws.subscribe(subId);