Skip to content

Commit

Permalink
fix(graphql-server-core): validation for get queries
Browse files Browse the repository at this point in the history
  • Loading branch information
DxCx committed Jun 12, 2017
1 parent a84df1e commit 0ae313c
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 10 deletions.
7 changes: 1 addition & 6 deletions packages/graphql-server-core/src/runHttpQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,7 @@ export async function runHttpQuery(handlerArguments: Array<any>, request: HttpQu
try {
let query = requestParams.query;
if ( isGetRequest ) {
if (typeof query === 'string') {
// preparse the query incase of GET so we can assert the operation.
query = parse(query);
}

if ( ! isQueryOperation(query, requestParams.operationName) ) {
if ( ! isQueryOperation(parse(query), requestParams.operationName) ) {
throw new HttpQueryError(405, `GET supports only query operation`, false, {
'Allow': 'POST',
});
Expand Down
1 change: 1 addition & 0 deletions packages/graphql-server-core/src/runQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ function doRunQuery(options: QueryOptions): Promise<ExecutionResult> {
logFunction({action: LogAction.request, step: LogStep.status, key: 'operationName', data: options.operationName});

// if query is already an AST, don't parse or validate
// XXX: This refers the operations-store flow.
if (typeof options.query === 'string') {
try {
// TODO: time this with log function
Expand Down
3 changes: 1 addition & 2 deletions packages/graphql-server-express/src/apolloServerHttp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,15 +351,14 @@ describe(`GraphQL-HTTP (apolloServer) tests for ${version} express`, () => {
it('handles type validation (GET)', async () => {
const app = express();

app.use(urlString(), bodyParser.json());
app.use(urlString(), graphqlExpress({
schema: TestSchema
}));

const response = await request(app)
.get(urlString({ query: '{notExists}' }))

expect(response.status).to.equal(200);
expect(response.status).to.equal(400);
expect(JSON.parse(response.text)).to.deep.equal({
errors: [ {
message: 'Cannot query field \"notExists\" on type \"QueryRoot\".',
Expand Down
1 change: 0 additions & 1 deletion packages/graphql-server-restify/src/restifyApollo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { graphiqlRestify, graphqlRestify } from './restifyApollo';
import testSuite, { schema, CreateAppOptions } from 'graphql-server-integration-testsuite';
import { expect } from 'chai';
import { GraphQLOptions } from 'graphql-server-core';
import 'mocha';

function createApp(options: CreateAppOptions = {}) {
const server = restify.createServer({
Expand Down
5 changes: 4 additions & 1 deletion test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ require('../packages/graphql-server-express/dist/connectApollo.test');
require('../packages/graphql-server-hapi/dist/hapiApollo.test');
(NODE_MAJOR_VERSION >= 6) && require('../packages/graphql-server-micro/dist/microApollo.test');
(NODE_MAJOR_VERSION >= 7) && require('../packages/graphql-server-koa/dist/koaApollo.test');
require('../packages/graphql-server-restify/dist/restifyApollo.test');
require('../packages/graphql-server-lambda/dist/lambdaApollo.test');
require('../packages/graphql-server-express/dist/apolloServerHttp.test');

// XXX: Running restify last as it breaks http.
// for more info: https://github.com/restify/node-restify/issues/700
require('../packages/graphql-server-restify/dist/restifyApollo.test');

0 comments on commit 0ae313c

Please sign in to comment.