From 4e0420bcb27956aaf99805f24bc28774a4449c23 Mon Sep 17 00:00:00 2001 From: Hagai Cohen Date: Mon, 14 Nov 2016 23:46:09 +0200 Subject: [PATCH] chore(get-support): rename buffer to requestPayload --- .../src/expressApollo.ts | 12 +++++----- .../graphql-server-hapi/src/hapiApollo.ts | 22 +++++++++---------- packages/graphql-server-koa/src/koaApollo.ts | 12 +++++----- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/packages/graphql-server-express/src/expressApollo.ts b/packages/graphql-server-express/src/expressApollo.ts index 2672761a50f..d9cf528f172 100644 --- a/packages/graphql-server-express/src/expressApollo.ts +++ b/packages/graphql-server-express/src/expressApollo.ts @@ -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': @@ -53,7 +53,7 @@ export function graphqlExpress(options: GraphQLOptions | ExpressGraphQLOptionsFu return; } - buffer = req.body; + requestPayload = req.body; break; case 'GET': if ( !req.query ) { @@ -63,7 +63,7 @@ export function graphqlExpress(options: GraphQLOptions | ExpressGraphQLOptionsFu return; } - buffer = req.query; + requestPayload = req.query; break; default: @@ -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 = []; - for (let requestParams of buffer) { + for (let requestParams of requestPayload) { try { const query = requestParams.query; const operationName = requestParams.operationName; diff --git a/packages/graphql-server-hapi/src/hapiApollo.ts b/packages/graphql-server-hapi/src/hapiApollo.ts index 022f2e71fe0..ca3ec3fe64a 100644 --- a/packages/graphql-server-hapi/src/hapiApollo.ts +++ b/packages/graphql-server-hapi/src/hapiApollo.ts @@ -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); @@ -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', @@ -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) { @@ -94,7 +94,7 @@ 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. @@ -102,19 +102,19 @@ function assignIsBatch(method, buffer, reply) { 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 { diff --git a/packages/graphql-server-koa/src/koaApollo.ts b/packages/graphql-server-koa/src/koaApollo.ts index 65cde8bfba5..0729b2f7f32 100644 --- a/packages/graphql-server-koa/src/koaApollo.ts +++ b/packages/graphql-server-koa/src/koaApollo.ts @@ -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': @@ -43,7 +43,7 @@ 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) { @@ -51,7 +51,7 @@ export function graphqlKoa(options: GraphQLOptions | KoaGraphQLOptionsFunction): 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; @@ -59,13 +59,13 @@ export function graphqlKoa(options: GraphQLOptions | KoaGraphQLOptionsFunction): } let isBatch = true; - if (!Array.isArray(buffer)) { + if (!Array.isArray(requestPayload)) { isBatch = false; - buffer = [buffer]; + requestPayload = [requestPayload]; } let responses: Array = []; - for (let requestParams of buffer) { + for (let requestParams of requestPayload) { try { const query = requestParams.query; const operationName = requestParams.operationName;