How to use the @hapi/nes.Client function in @hapi/nes

To help you get started, we’ve selected a few @hapi/nes examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github geek / graphi / test / index.js View on Github external
lastname: String!
        email: String!
      }

      type Subscription {
        personCreated(firstname: String): Person!
      }
    `;

    const server = Hapi.server();
    await server.register(Nes);
    await server.register({ plugin: Graphi, options: { schema } });
    await server.start();

    const barrier = new Barrier();
    const client = new Nes.Client(`http://localhost:${server.info.port}`);
    await client.connect();

    await client.subscribe('/personCreated/john', ({ firstname }) => {
      expect(firstname).to.equal('john');
      client.disconnect();
      barrier.pass();
    });

    server.plugins.graphi.publish('personCreated', { firstname: 'foo', lastname: 'bar', email: 'test@test.com' });
    server.plugins.graphi.publish('personCreated', { firstname: 'john', lastname: 'smith', email: 'test@test.com' });

    await barrier;
    await server.stop();
  });
github geek / graphi / test / index.js View on Github external
const getPerson = function (args, request) {
      expect(args.firstname).to.equal('tom');
      expect(request.path).to.equal('/graphql');
      return { firstname: 'tom', lastname: 'arnold' };
    };

    const resolvers = {
      person: getPerson
    };

    const server = Hapi.server();
    await server.register(Nes);
    await server.register({ plugin: Graphi, options: { schema, resolvers } });
    await server.start();

    const client = new Nes.Client(`http://localhost:${server.info.port}`);
    await client.connect();

    const payload = { query: 'query { person(firstname: "tom") { lastname } }' };
    const result = await client.request({ method: 'POST', path: '/graphql', payload });
    await server.stop();

    expect(result.payload.data.person.lastname).to.equal('arnold');
  });

@hapi/nes

WebSocket adapter plugin for hapi routes

BSD-3-Clause
Latest version published 3 months ago

Package Health Score

85 / 100
Full package analysis