mirror of
https://github.com/vale981/apollo-server
synced 2025-03-06 10:11:40 -05:00
fix(get-support): fixed returned status for get without query
This commit is contained in:
parent
93d7966df8
commit
5b46db4aa0
4 changed files with 17 additions and 7 deletions
|
@ -56,8 +56,8 @@ export function graphqlExpress(options: GraphQLOptions | ExpressGraphQLOptionsFu
|
|||
requestPayload = req.body;
|
||||
break;
|
||||
case 'GET':
|
||||
if ( !req.query ) {
|
||||
res.statusCode = 500;
|
||||
if ( !req.query || (Object.keys(req.query).length === 0) ) {
|
||||
res.statusCode = 400;
|
||||
res.write('GET query missing.');
|
||||
res.end();
|
||||
return;
|
||||
|
|
|
@ -80,8 +80,8 @@ graphqlHapi.attributes = {
|
|||
function assignRequest(method, payload, query, reply) {
|
||||
switch ( method ) {
|
||||
case 'get':
|
||||
if (!query) {
|
||||
return reply(createErr(500, 'GET query missing.'));
|
||||
if (!query || (Object.keys(query).length === 0)) {
|
||||
return reply(createErr(400, 'GET query missing.'));
|
||||
}
|
||||
return reply(query);
|
||||
case 'post':
|
||||
|
|
|
@ -182,6 +182,16 @@ export default (createApp: CreateAppFunc, destroyApp?: DestroyAppFunc) => {
|
|||
});
|
||||
});
|
||||
|
||||
it('throws an error if GET query is missing', () => {
|
||||
app = createApp();
|
||||
const req = request(app)
|
||||
.get(`/graphql`);
|
||||
return req.then((res) => {
|
||||
expect(res.status).to.equal(400);
|
||||
return expect(res.error.text).to.contain('GET query missing.');
|
||||
});
|
||||
});
|
||||
|
||||
it('can handle a basic GET request', () => {
|
||||
app = createApp();
|
||||
const expected = {
|
||||
|
|
|
@ -38,9 +38,9 @@ export function graphqlKoa(options: GraphQLOptions | KoaGraphQLOptionsFunction):
|
|||
|
||||
switch ( ctx.request.method ) {
|
||||
case 'GET':
|
||||
if (!ctx.request.query) {
|
||||
ctx.status = 500;
|
||||
return ctx.body = 'GET query missing';
|
||||
if (!ctx.request.query || (Object.keys(ctx.request.query).length === 0)) {
|
||||
ctx.status = 400;
|
||||
return ctx.body = 'GET query missing.';
|
||||
}
|
||||
|
||||
requestPayload = ctx.request.query;
|
||||
|
|
Loading…
Add table
Reference in a new issue