Skip to content

Commit

Permalink
enable parallel execution of batch requests prior to implementation of
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Rinehart committed Dec 12, 2016
1 parent 962930e commit 4408f55
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/graphql-server-hapi/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "graphql-server-hapi",
"version": "0.4.3",
"name": "@philo/graphql-server-hapi",
"version": "0.4.3-p1",
"description": "Production-ready Node.js GraphQL server for Hapi",
"main": "dist/index.js",
"scripts": {
Expand Down
10 changes: 5 additions & 5 deletions packages/graphql-server-hapi/src/hapiApollo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ async function getGraphQLOptions(request: Request, reply: IReply): Promise<{}> {
async function processQuery(graphqlParams, optionsObject: GraphQLOptions, isBatch: boolean, reply) {
const formatErrorFn = optionsObject.formatError || formatError;

let responses: GraphQLResult[] = [];
for (let query of graphqlParams) {
const requests = graphqlParams.map(async (query) => {
try {
// Shallow clone context for queries in batches. This allows
// users to distinguish multiple queries in the batch and to
Expand Down Expand Up @@ -154,11 +153,12 @@ async function processQuery(graphqlParams, optionsObject: GraphQLOptions, isBatc
params = optionsObject.formatParams(params);
}

responses.push(await runQuery(params));
return await runQuery(params);
} catch (e) {
responses.push({ errors: [formatErrorFn(e)] });
return { errors: [formatErrorFn(e)] };
}
}
});
const responses: GraphQLResult[] = await Promise.all(requests);
return reply(responses);
}

Expand Down

0 comments on commit 4408f55

Please sign in to comment.