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

Add info to custom resolvers and add formatError to GraphQL service #6524

Merged
merged 3 commits into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 => {
iicdii marked this conversation as resolved.
Show resolved Hide resolved
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