How to use @hapi/nes - 3 common examples

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');
  });
github brightleaf / react-hooks / src / use-nes.js View on Github external
const useNes = (url = 'ws://localhost:4567', subscribe) => {
  const [state, dispatch] = useReducer(reducer, {
    messages: [],
    error: null,
    connecting: true,
    connected: false,
  })
  var client = new Nes.Client(url)

  useEffect(() => {
    const connectClient = async () => {
      dispatch({ type: 'connecting', payload: {} })
      return new Promise(async resolve => {
        client.onConnect = () => {
          dispatch({ type: 'connected' })
          return resolve()
        }
        client.onDisconnect = () => {
          dispatch({ type: 'disconnected' })
          return resolve()
        }
        await client.connect()

        client.onUpdate = update => {

@hapi/nes

WebSocket adapter plugin for hapi routes

BSD-3-Clause
Latest version published 4 months ago

Package Health Score

78 / 100
Full package analysis