Skip to content

Commit

Permalink
fix(get-support): fixed returned status for get without query
Browse files Browse the repository at this point in the history
  • Loading branch information
DxCx committed Jan 13, 2017
1 parent 93d7966 commit 5b46db4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/graphql-server-express/src/expressApollo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions packages/graphql-server-hapi/src/hapiApollo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
10 changes: 10 additions & 0 deletions packages/graphql-server-integration-testsuite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
6 changes: 3 additions & 3 deletions packages/graphql-server-koa/src/koaApollo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5b46db4

Please sign in to comment.