Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:pass other apollo server options. #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2.3.1 / 2018-12-28
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

history不需要改

==================

* feat:pass other apollo server options. (#20)

2.3.0 / 2018-10-21
==================
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,24 @@ exports.graphql = {
onPreGraphQL: function* (ctx) {},
// 开发工具 graphiQL 路由前的拦截器,建议用于做权限操作(如只提供开发者使用)
onPreGraphiQL: function* (ctx) {},
// apollo server的透传参数
apolloServerOptions: {
rootValue,
formatError,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

缺少单测,最好把formatError这个测试一下,测试下是否可以在应用外面接收到格式化后的error

formatResponse,
mocks,
schemaDirectives,
introspection,
playground,
debug,
validationRules,
tracing,
cacheControl,
subscriptions,
engine,
persistedQueries,
cors,
}
};

// 添加中间件拦截请求
Expand Down
27 changes: 19 additions & 8 deletions app/middleware/graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,33 @@ module.exports = (_, app) => {

return async (ctx, next) => {
/* istanbul ignore else */
const {
onPreGraphiQL,
onPreGraphQL,
apolloServerOptions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个文档补一下,补在外面readme

} = options;

if (ctx.path === graphQLRouter) {
if (ctx.request.accepts([ 'json', 'html' ]) === 'html' && graphiql) {
if (options.onPreGraphiQL) {
await options.onPreGraphiQL(ctx);
if (onPreGraphiQL) {
await onPreGraphiQL(ctx);
}
return graphiqlKoa({
endpointURL: graphQLRouter,
})(ctx);
}
if (options.onPreGraphQL) {
await options.onPreGraphQL(ctx);
if (onPreGraphQL) {
await onPreGraphQL(ctx);
}
return graphqlKoa({
schema: app.schema,
context: ctx,
})(ctx);
const serverOptions = Object.assign(
{},
apolloServerOptions,
{
schema: app.schema,
context: ctx,
}
);
return graphqlKoa(serverOptions)(ctx);
}
await next();
};
Expand Down