Skip to content

Commit

Permalink
parallelize batch requests before apollographql#176
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Dec 15, 2016
1 parent 964e9e2 commit 55f4a08
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
8 changes: 4 additions & 4 deletions packages/graphql-server-express/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "graphql-server-express",
"version": "0.4.3",
"name": "@remind/graphql-server-express",
"version": "0.4.3-p1",
"description": "Production-ready Node.js GraphQL server for Express and Connect",
"main": "dist/index.js",
"scripts": {
Expand All @@ -9,7 +9,7 @@
},
"repository": {
"type": "git",
"url": "https://github.com/apollostack/graphql-server/tree/master/packages/graphql-server-express"
"url": "https://github.com/remind101/graphql-server/tree/master/packages/graphql-server-express"
},
"keywords": [
"GraphQL",
Expand All @@ -22,7 +22,7 @@
"author": "Jonas Helfer <jonas@helfer.email>",
"license": "MIT",
"bugs": {
"url": "https://github.com/apollostack/graphql-server/issues"
"url": "https://github.com/remind101/graphql-server/issues"
},
"homepage": "https://github.com/apollostack/graphql-server#readme",
"dependencies": {
Expand Down
11 changes: 6 additions & 5 deletions packages/graphql-server-express/src/expressApollo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ export function graphqlExpress(options: GraphQLOptions | ExpressGraphQLOptionsFu
b = [b];
}

let responses: Array<graphql.GraphQLResult> = [];
for (let requestParams of b) {
const requests = b.map(async (requestParams) => {
try {
const query = requestParams.query;
const operationName = requestParams.operationName;
Expand Down Expand Up @@ -111,11 +110,13 @@ export function graphqlExpress(options: GraphQLOptions | ExpressGraphQLOptionsFu
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: graphql.GraphQLResult[] = await Promise.all(requests);

res.setHeader('Content-Type', 'application/json');
if (isBatch) {
Expand Down

0 comments on commit 55f4a08

Please sign in to comment.