an Exmaple for Vue.js Apollo Client is also included in the /example/vue-client
directory.
you need to go with the custom http server mode with keystone.js.
then call initSubscriptionServer
with your http server and keystone object.
Example:
keystone
.prepare({
apps: apps,
dev: process.env.NODE_ENV !== 'production',
})
.then(async ({middlewares}) => {
await keystone.connect();
const app = express();
app.use(middlewares)
const httpServer = http.createServer(app);
httpServer.listen(3000, () => {
//first step
initSubscriptionServer(httpServer,keystone);
})
});
to add Model Subscription you need to call addModelToSubscription
method with your list.
Example:
const model = {
fields: {
name: {
type: Text,
isRequired: true,
},
//...
},
};
const list = keystone.createList('Book', model);
//second step
addModelToSubscription({keystone, list});
now you can listen to subscriptions in your GraphQL api.
Example:
subscription {
book : anyBookChange{
id
name
author
date
}
}