From 7e5fce9f819fd462fb810693ca2a2d624b504805 Mon Sep 17 00:00:00 2001 From: Makcy <644215038@qq.com> Date: Tue, 26 Jun 2018 17:19:11 +0800 Subject: [PATCH 1/4] [ADD]graphqliRouter option to config --- app/middleware/graphql.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/middleware/graphql.js b/app/middleware/graphql.js index a2f2f07..6d9af3d 100644 --- a/app/middleware/graphql.js +++ b/app/middleware/graphql.js @@ -5,6 +5,7 @@ const { graphqlKoa, graphiqlKoa } = require('apollo-server-koa'); module.exports = (_, app) => { const options = app.config.graphql; const graphQLRouter = options.router; + const graphiqlRouter = options.graphiqlRouter ? options.graphiqlRouter : graphQLRouter; let graphiql = true; if (options.graphiql === false) { @@ -19,7 +20,7 @@ module.exports = (_, app) => { await options.onPreGraphiQL(ctx); } return graphiqlKoa({ - endpointURL: graphQLRouter, + endpointURL: graphiqlRouter, })(ctx); } if (options.onPreGraphQL) { From 5189642210007632287ce525e6ccce0f018d7a8e Mon Sep 17 00:00:00 2001 From: Makcy <644215038@qq.com> Date: Wed, 27 Jun 2018 18:46:07 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=BD=93=E6=9C=AA=E8=AE=BE=E7=BD=AEgraphiq?= =?UTF-8?q?lRouter=E7=9A=84=E6=97=B6=E5=80=99=EF=BC=8C=E5=9C=A8config.grap?= =?UTF-8?q?hql=E4=B8=AD=E9=80=8F=E5=87=BA=E8=AF=A5=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/middleware/graphql.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/middleware/graphql.js b/app/middleware/graphql.js index 6d9af3d..76d11f7 100644 --- a/app/middleware/graphql.js +++ b/app/middleware/graphql.js @@ -5,7 +5,7 @@ const { graphqlKoa, graphiqlKoa } = require('apollo-server-koa'); module.exports = (_, app) => { const options = app.config.graphql; const graphQLRouter = options.router; - const graphiqlRouter = options.graphiqlRouter ? options.graphiqlRouter : graphQLRouter; + options.graphiqlRouter = options.graphiqlRouter ? options.graphiqlRouter : graphQLRouter; let graphiql = true; if (options.graphiql === false) { @@ -20,7 +20,7 @@ module.exports = (_, app) => { await options.onPreGraphiQL(ctx); } return graphiqlKoa({ - endpointURL: graphiqlRouter, + endpointURL: options.graphiqlRouter, })(ctx); } if (options.onPreGraphQL) { From 40a5b62c47ecf9082644f68b4c09afe98a36c055 Mon Sep 17 00:00:00 2001 From: shadyzoz Date: Wed, 12 Sep 2018 16:15:42 +0800 Subject: [PATCH 3/4] feat: add graphql-voyager and add formatError config --- app/middleware/graphql.js | 12 ++++++++++++ package.json | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/middleware/graphql.js b/app/middleware/graphql.js index 76d11f7..9c219a5 100644 --- a/app/middleware/graphql.js +++ b/app/middleware/graphql.js @@ -1,17 +1,24 @@ 'use strict'; const { graphqlKoa, graphiqlKoa } = require('apollo-server-koa'); +const { koa: voyagerMiddleware } = require('graphql-voyager/middleware'); module.exports = (_, app) => { const options = app.config.graphql; const graphQLRouter = options.router; options.graphiqlRouter = options.graphiqlRouter ? options.graphiqlRouter : graphQLRouter; + const voyagerRouter = options.voyagerRouter; let graphiql = true; if (options.graphiql === false) { graphiql = false; } + let voyager = true; + if (options.voyager === false) { + voyager = false; + } + return async (ctx, next) => { /* istanbul ignore else */ if (ctx.path === graphQLRouter) { @@ -29,6 +36,11 @@ module.exports = (_, app) => { return graphqlKoa({ schema: app.schema, context: ctx, + formatError: options.formatError, + })(ctx); + } else if (voyager && ctx.path === voyagerRouter) { + return voyagerMiddleware({ + endpointURL: options.graphiqlRouter, })(ctx); } await next(); diff --git a/package.json b/package.json index d2a54c6..351e45d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "egg-graphql", - "version": "2.1.0", + "version": "2.2.0", "description": "egg graphql plugin", "eggPlugin": { "name": "graphql" @@ -17,6 +17,7 @@ "graphql": "^0.11.7", "graphql-tag": "^2.5.0", "graphql-tools": "^2.19.0", + "graphql-voyager": "^1.0.0-rc.25", "lodash": "4.17.4" }, "devDependencies": { From 993f6679b44a323bfe89d006bc9929fba7a2387d Mon Sep 17 00:00:00 2001 From: shadyzoz Date: Mon, 17 Sep 2018 10:08:36 +0800 Subject: [PATCH 4/4] fix: package name --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 10dd01c..8e5adb7 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@server/egg-graphql", + "name": "egg-graphql", "version": "2.0.4", "description": "egg graphql plugin", "eggPlugin": {