Comparing version 5.0.0 to 5.0.1
@@ -58,3 +58,6 @@ 'use strict'; | ||
internals.graphqlHandler = async function (request, h) { | ||
const source = request.method.toUpperCase() === 'GET' ? request.query : request.payload; | ||
if (request.method.toUpperCase() === 'OPTIONS') { | ||
return h.continue; | ||
} | ||
const source = request.method.toUpperCase() === 'GET' ? request.query : (request.payload || {}); | ||
@@ -61,0 +64,0 @@ const operationName = source.operationName; |
{ | ||
"name": "graphi", | ||
"version": "5.0.0", | ||
"version": "5.0.1", | ||
"description": "hapi graphql plugin", | ||
@@ -5,0 +5,0 @@ "main": "lib", |
@@ -535,2 +535,62 @@ 'use strict'; | ||
}); | ||
it('will handle graphql POST request without a payload', async () => { | ||
const schema = ` | ||
type Person { | ||
firstname: String! | ||
lastname: String! | ||
email: String! | ||
} | ||
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: '', lastname: 'jean', email: 'what' }; | ||
}; | ||
const resolvers = { | ||
person: getPerson | ||
}; | ||
const server = Hapi.server(); | ||
await server.register({ plugin: Graphi, options: { schema, resolvers } }); | ||
const res = await server.inject({ method: 'POST', url: '/graphql' }); | ||
expect(res.statusCode).to.equal(400); | ||
}); | ||
it('will handle graphql OPTIONS request when cors is disabled', async () => { | ||
const schema = ` | ||
type Person { | ||
firstname: String! | ||
lastname: String! | ||
email: String! | ||
} | ||
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: '', lastname: 'jean', email: 'what' }; | ||
}; | ||
const resolvers = { | ||
person: getPerson | ||
}; | ||
const server = Hapi.server(); | ||
await server.register({ plugin: Graphi, options: { schema, resolvers } }); | ||
const res = await server.inject({ method: 'OPTIONS', url: '/graphql' }); | ||
expect(res.statusCode).to.equal(200); | ||
}); | ||
}); |
40045
609