Skip to content

Commit

Permalink
Add info to custom resolvers and add formatError to GraphQL service (s…
Browse files Browse the repository at this point in the history
…trapi#6524)

* Add info to custom resolvers, add formatError to GraphQL service

Signed-off-by: harimkims <harimkims@gmail.com>

* remove format-error service and use config instead

Signed-off-by: harimkims <harimkims@gmail.com>
  • Loading branch information
iicdii committed Jul 2, 2020
1 parent 088b3a7 commit c045792
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 5 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,11 @@ module.exports = strapi => {
context: ctx,
};
},
formatError: err => {
const formatError = _.get(strapi.plugins.graphql, 'config.formatError', null);

return typeof formatError === 'function' ? formatError(err) : err;
},
validationRules: [depthLimit(strapi.plugins.graphql.config.depthLimit)],
tracing: _.get(strapi.plugins.graphql, 'config.tracing', false),
playground: false,
Expand Down
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 c045792

Please sign in to comment.