Skip to content

Commit

Permalink
chore(get-support): rename buffer to requestPayload
Browse files Browse the repository at this point in the history
  • Loading branch information
DxCx committed Dec 16, 2016
1 parent 6de43f0 commit 4e0420b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
12 changes: 6 additions & 6 deletions packages/graphql-server-express/src/expressApollo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function graphqlExpress(options: GraphQLOptions | ExpressGraphQLOptionsFu
}

const formatErrorFn = optionsObject.formatError || graphql.formatError;
let buffer;
let requestPayload;

switch ( req.method ) {
case 'POST':
Expand All @@ -53,7 +53,7 @@ export function graphqlExpress(options: GraphQLOptions | ExpressGraphQLOptionsFu
return;
}

buffer = req.body;
requestPayload = req.body;
break;
case 'GET':
if ( !req.query ) {
Expand All @@ -63,7 +63,7 @@ export function graphqlExpress(options: GraphQLOptions | ExpressGraphQLOptionsFu
return;
}

buffer = req.query;
requestPayload = req.query;
break;

default:
Expand All @@ -77,13 +77,13 @@ export function graphqlExpress(options: GraphQLOptions | ExpressGraphQLOptionsFu
let isBatch = true;
// TODO: do something different here if the body is an array.
// Throw an error if body isn't either array or object.
if (!Array.isArray(buffer)) {
if (!Array.isArray(requestPayload)) {
isBatch = false;
buffer = [buffer];
requestPayload = [requestPayload];
}

let responses: Array<graphql.GraphQLResult> = [];
for (let requestParams of buffer) {
for (let requestParams of requestPayload) {
try {
const query = requestParams.query;
const operationName = requestParams.operationName;
Expand Down
22 changes: 11 additions & 11 deletions packages/graphql-server-hapi/src/hapiApollo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface HapiPluginOptions {

const graphqlHapi: IRegister = function(server: Server, options: HapiPluginOptions, next) {
server.method('assignIsBatch', assignIsBatch);
server.method('assignBuffer', assignBuffer);
server.method('assignRequest', assignRequest);
server.method('getGraphQLParams', getGraphQLParams);
server.method('getGraphQLOptions', getGraphQLOptions);
server.method('processQuery', processQuery);
Expand All @@ -32,15 +32,15 @@ const graphqlHapi: IRegister = function(server: Server, options: HapiPluginOptio
},
pre: [
{
assign: 'buffer',
method: 'assignBuffer(method, payload, query)',
assign: 'requestPayload',
method: 'assignRequest(method, payload, query)',
},
{
assign: 'isBatch',
method: 'assignIsBatch(method, pre.buffer)',
method: 'assignIsBatch(method, pre.requestPayload)',
}, {
assign: 'graphqlParams',
method: 'getGraphQLParams(pre.buffer, pre.isBatch)',
method: 'getGraphQLParams(pre.requestPayload, pre.isBatch)',
}, {
assign: 'graphqlOptions',
method: 'getGraphQLOptions',
Expand Down Expand Up @@ -77,7 +77,7 @@ graphqlHapi.attributes = {
version: '0.0.1',
};

function assignBuffer(method, payload, query, reply) {
function assignRequest(method, payload, query, reply) {
switch ( method ) {
case 'get':
if (!query) {
Expand All @@ -94,27 +94,27 @@ function assignBuffer(method, payload, query, reply) {
}
}

function assignIsBatch(method, buffer, reply) {
function assignIsBatch(method, requestPayload, reply) {
// TODO: do something different here if the body is an array.
// Throw an error if body isn't either array or object.

switch ( method ) {
case 'get':
return reply(false);
case 'post':
return reply(Array.isArray(buffer));
return reply(Array.isArray(requestPayload));
default:
throw new Error(`Invalid case reached, method is ${method}`);
}
}

function getGraphQLParams(buffer, isBatch, reply) {
function getGraphQLParams(requestPayload, isBatch, reply) {
if (!isBatch) {
buffer = [buffer];
requestPayload = [requestPayload];
}

const params = [];
for (let query of buffer) {
for (let query of requestPayload) {
let variables = query.variables;
if (variables && typeof variables === 'string') {
try {
Expand Down
12 changes: 6 additions & 6 deletions packages/graphql-server-koa/src/koaApollo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function graphqlKoa(options: GraphQLOptions | KoaGraphQLOptionsFunction):
}

const formatErrorFn = optionsObject.formatError || graphql.formatError;
let buffer;
let requestPayload;

switch ( ctx.request.method ) {
case 'GET':
Expand All @@ -43,29 +43,29 @@ export function graphqlKoa(options: GraphQLOptions | KoaGraphQLOptionsFunction):
return ctx.body = 'GET query missing';
}

buffer = ctx.request.query;
requestPayload = ctx.request.query;
break;
case 'POST':
if (!ctx.request.body) {
ctx.status = 500;
return ctx.body = 'POST body missing. Did you forget "app.use(koaBody())"?';
}

buffer = ctx.request.body;
requestPayload = ctx.request.body;
break;
default:
ctx.status = 405;
return ctx.body = 'Apollo Server supports only GET/POST requests.';
}

let isBatch = true;
if (!Array.isArray(buffer)) {
if (!Array.isArray(requestPayload)) {
isBatch = false;
buffer = [buffer];
requestPayload = [requestPayload];
}

let responses: Array<graphql.GraphQLResult> = [];
for (let requestParams of buffer) {
for (let requestParams of requestPayload) {
try {
const query = requestParams.query;
const operationName = requestParams.operationName;
Expand Down

0 comments on commit 4e0420b

Please sign in to comment.