Skip to content

Commit

Permalink
Add info to custom resolvers, add formatError to GraphQL service
Browse files Browse the repository at this point in the history
  • Loading branch information
iicdii committed Jun 3, 2020
1 parent 8d01c10 commit 30db2c0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
3 changes: 3 additions & 0 deletions packages/strapi-plugin-graphql/hooks/graphql/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ module.exports = strapi => {
context: ctx,
};
},
formatError: err => {
return strapi.plugins.graphql.services['format-error'].formatError(err);
},
validationRules: [depthLimit(strapi.plugins.graphql.config.depthLimit)],
tracing: _.get(strapi.plugins.graphql, 'config.tracing', false),
playground: false,
Expand Down
5 changes: 5 additions & 0 deletions packages/strapi-plugin-graphql/services/format-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const formatError = err => err;

module.exports = {
formatError,
};
8 changes: 4 additions & 4 deletions packages/strapi-plugin-graphql/services/resolvers-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ const buildMutation = (mutationName, config) => {

// custom resolvers
if (_.isFunction(resolver)) {
return async (root, options = {}, graphqlContext) => {
return async (root, options = {}, graphqlContext, info) => {
const ctx = buildMutationContext({ options, graphqlContext });

await policiesMiddleware(ctx);
graphqlContext.context = ctx;

return resolver(root, options, graphqlContext);
return resolver(root, options, graphqlContext, info);
};
}

Expand Down Expand Up @@ -91,13 +91,13 @@ const buildQuery = (queryName, config) => {

// custom resolvers
if (_.isFunction(resolver)) {
return async (root, options = {}, graphqlContext) => {
return async (root, options = {}, graphqlContext, info) => {
const { ctx, opts } = buildQueryContext({ options, graphqlContext });

await policiesMiddleware(ctx);
graphqlContext.context = ctx;

return resolver(root, opts, graphqlContext);
return resolver(root, opts, graphqlContext, info);
};
}

Expand Down

0 comments on commit 30db2c0

Please sign in to comment.