New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

graphi

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphi - npm Package Compare versions

Comparing version 5.4.0 to 5.5.0

43

lib/index.js

@@ -36,22 +36,24 @@ 'use strict';

method: () => {
const resolver = async (payload, request, ast) => {
const url = `/${ast.fieldName}`;
const res = await request.server.inject({
method: 'graphql',
url,
payload,
headers: request.headers
});
const resolver = (prefix = '') => {
return async (payload, request, ast) => {
const url = `${prefix}/${ast.fieldName}`;
const res = await request.server.inject({
method: 'graphql',
url,
payload,
headers: request.headers
});
if (res.statusCode < 400) {
return res.result;
}
if (res.statusCode < 400) {
return res.result;
}
return new Boom(res.result.message, {
statusCode: res.statusCode,
data: {
error: res.result.error,
url
}
});
return new Boom(res.result.message, {
statusCode: res.statusCode,
data: {
error: res.result.error,
url
}
});
};
};

@@ -63,4 +65,5 @@

}
const path = route.path.substr(1);
resolvers[path] = resolver;
const prefix = route.realm.modifiers.route.prefix;
const path = prefix ? route.path.substr(prefix.length + 1) : route.path.substr(1);
resolvers[path] = resolver(prefix);
});

@@ -67,0 +70,0 @@

{
"name": "graphi",
"version": "5.4.0",
"version": "5.5.0",
"description": "hapi graphql plugin",

@@ -5,0 +5,0 @@ "main": "lib",

@@ -248,2 +248,104 @@ 'use strict';

it('will handle graphql requests to resolver routes when configured with prefix', async () => {
const schema = `
type Person {
id: ID!
firstname: String!
lastname: String!
}
type Mutation {
createPerson(firstname: String!, lastname: String!): Person!
}
type Query {
person(firstname: String!): Person!
}
`;
const getPerson = function (args, request) {
expect(args.firstname).to.equal('billy');
expect(request.path).to.equal('/graphql');
return { firstname: 'billy', lastname: 'jean' };
};
const resolvers = {
person: getPerson
};
const server = Hapi.server();
await server.register({ plugin: Graphi, options: { schema, resolvers }, routes: { prefix: '/test' } });
server.route({
method: 'graphql',
path: '/createPerson',
handler: (request, h) => {
expect(request.payload.firstname).to.equal('billy');
expect(request.payload.lastname).to.equal('jean');
return { firstname: 'billy', lastname: 'jean' };
}
});
await server.initialize();
const payload = { query: 'mutation { createPerson(firstname: "billy", lastname: "jean") { lastname } }' };
const res = await server.inject({ method: 'POST', url: '/test/graphql', payload });
expect(res.statusCode).to.equal(200);
expect(res.result.data.createPerson.lastname).to.equal('jean');
});
it('will handle graphql requests to resolver routes inside a plugin when configured with prefix', async () => {
const schema = `
type Person {
id: ID!
firstname: String!
lastname: String!
}
type Mutation {
createPerson(firstname: String!, lastname: String!): Person!
}
type Query {
person(firstname: String!): Person!
}
`;
const getPerson = function (args, request) {
expect(args.firstname).to.equal('billy');
expect(request.path).to.equal('/graphql');
return { firstname: 'billy', lastname: 'jean' };
};
const resolvers = {
person: getPerson
};
const server = Hapi.server();
await server.register({ plugin: Graphi, options: { schema, resolvers }, routes: { prefix: '/test' } });
const plugin = {
name: 'test',
version: '0.0.0',
register: (server) => {
server.route({
method: 'graphql',
path: '/createPerson',
handler: (request, h) => {
expect(request.payload.firstname).to.equal('billy');
expect(request.payload.lastname).to.equal('jean');
return { firstname: 'billy', lastname: 'jean' };
}
});
}
};
await server.register({ plugin, routes: { prefix: '/foo' } });
await server.initialize();
const payload = { query: 'mutation { createPerson(firstname: "billy", lastname: "jean") { lastname } }' };
const res = await server.inject({ method: 'POST', url: '/test/graphql', payload });
expect(res.statusCode).to.equal(200);
expect(res.result.data.createPerson.lastname).to.equal('jean');
});
it('will error with requests that include unknown directives', async () => {

@@ -250,0 +352,0 @@ const schema = `

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc