Skip to content

Instantly share code, notes, and snippets.

@shadowcodex
Last active August 23, 2018 00:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shadowcodex/587cd0ffbf49cefd3a00a56caf7a5f11 to your computer and use it in GitHub Desktop.
Save shadowcodex/587cd0ffbf49cefd3a00a56caf7a5f11 to your computer and use it in GitHub Desktop.
Handle Prisma subscription using prisma-binding v2.1.3
const { Prisma } = require("prisma-binding");
const prisma = new Prisma({
typeDefs: "./../generated/prisma.graphql",
endpoint: "http://localhost:4466",
});
const handleIty = async (iterator, callback) => {
while (true) {
await iterator
.next()
.then(value => {
callback(null, value.value);
})
.catch(err => {
callback(err, null);
});
}
};
const handleValue = async (error, value) => {
if (error) {
console.log(error);
return;
}
console.log(value);
};
const run = async () => {
const ity = await prisma.subscription.user({}, "{ node { id } }").catch(err => {
console.log("error:", err);
return;
});
handleIty(ity, handleValue);
};
run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment