Skip to content

Instantly share code, notes, and snippets.

@shadowcodex
Last active August 23, 2018 00:34
Show Gist options
  • Select an option

  • Save shadowcodex/587cd0ffbf49cefd3a00a56caf7a5f11 to your computer and use it in GitHub Desktop.

Select an option

Save shadowcodex/587cd0ffbf49cefd3a00a56caf7a5f11 to your computer and use it in GitHub Desktop.

Revisions

  1. shadowcodex revised this gist Aug 23, 2018. 1 changed file with 7 additions and 10 deletions.
    17 changes: 7 additions & 10 deletions prisma.js
    Original file line number Diff line number Diff line change
    @@ -3,17 +3,11 @@ const { Prisma } = require("prisma-binding");
    const prisma = new Prisma({
    typeDefs: "./../generated/prisma.graphql",
    endpoint: "http://localhost:4466",
    // debug: true,
    });

    const handleIty = async (iterator, callback) => {
    const ity = await iterator.catch(error => {
    callback(error, null);
    return;
    });
    // console.log(ity);
    while (true) {
    await ity
    await iterator
    .next()
    .then(value => {
    callback(null, value.value);
    @@ -32,9 +26,12 @@ const handleValue = async (error, value) => {
    console.log(value);
    };

    const run = async () => {
    //console.log(await prisma.query.users({}, "{ id }"));
    handleIty(prisma.subscription.user({}, "{ node { id } }"), handleValue);
    const run = async () => {
    const ity = await prisma.subscription.user({}, "{ node { id } }").catch(err => {
    console.log("error:", err);
    return;
    });
    handleIty(ity, handleValue);
    };

    run();
  2. shadowcodex created this gist Aug 23, 2018.
    40 changes: 40 additions & 0 deletions prisma.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    const { Prisma } = require("prisma-binding");

    const prisma = new Prisma({
    typeDefs: "./../generated/prisma.graphql",
    endpoint: "http://localhost:4466",
    // debug: true,
    });

    const handleIty = async (iterator, callback) => {
    const ity = await iterator.catch(error => {
    callback(error, null);
    return;
    });
    // console.log(ity);
    while (true) {
    await ity
    .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 () => {
    //console.log(await prisma.query.users({}, "{ id }"));
    handleIty(prisma.subscription.user({}, "{ node { id } }"), handleValue);
    };

    run();