Last active
August 23, 2018 00:34
-
-
Save shadowcodex/587cd0ffbf49cefd3a00a56caf7a5f11 to your computer and use it in GitHub Desktop.
Handle Prisma subscription using prisma-binding v2.1.3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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