Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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();
});
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');
});