mirror of
https://github.com/strapi/strapi.git
synced 2025-09-01 04:42:58 +00:00
Merge branch 'fix/graphql' of github.com:strapi/strapi into content-manager-filters
This commit is contained in:
commit
c95be9312d
@ -193,19 +193,21 @@ module.exports = {
|
|||||||
// Extract custom resolver or type description.
|
// Extract custom resolver or type description.
|
||||||
const { resolver: handler = {} } = _schema;
|
const { resolver: handler = {} } = _schema;
|
||||||
|
|
||||||
const queryName = isSingular ?
|
let queryName;
|
||||||
pluralize.singular(name):
|
|
||||||
pluralize.plural(name);
|
if (isSingular === 'force') {
|
||||||
|
queryName = name;
|
||||||
|
} else {
|
||||||
|
queryName = isSingular ?
|
||||||
|
pluralize.singular(name):
|
||||||
|
pluralize.plural(name);
|
||||||
|
}
|
||||||
|
|
||||||
// Retrieve policies.
|
// Retrieve policies.
|
||||||
const policies = isSingular ?
|
const policies = _.get(handler, `Query.${queryName}.policies`, []);
|
||||||
_.get(handler, `Query.${pluralize.singular(name)}.policies`, []):
|
|
||||||
_.get(handler, `Query.${pluralize.plural(name)}.policies`, []);
|
|
||||||
|
|
||||||
// Retrieve resolverOf.
|
// Retrieve resolverOf.
|
||||||
const resolverOf = isSingular ?
|
const resolverOf = _.get(handler, `Query.${queryName}.resolverOf`, '');
|
||||||
_.get(handler, `Query.${pluralize.singular(name)}.resolverOf`, ''):
|
|
||||||
_.get(handler, `Query.${pluralize.plural(name)}.resolverOf`, '');
|
|
||||||
|
|
||||||
const policiesFn = [];
|
const policiesFn = [];
|
||||||
|
|
||||||
@ -216,13 +218,13 @@ module.exports = {
|
|||||||
// or the shadow CRUD resolver (aka Content-Manager).
|
// or the shadow CRUD resolver (aka Content-Manager).
|
||||||
const resolver = (() => {
|
const resolver = (() => {
|
||||||
// Try to retrieve custom resolver.
|
// Try to retrieve custom resolver.
|
||||||
const resolver = isSingular ?
|
const resolver = _.get(handler, `Query.${queryName}.resolver`);
|
||||||
_.get(handler, `Query.${pluralize.singular(name)}.resolver`):
|
|
||||||
_.get(handler, `Query.${pluralize.plural(name)}.resolver`);
|
if (_.isString(resolver) || _.isPlainObject(resolver)) {
|
||||||
|
const { handler = resolver } = _.isPlainObject(resolver) ? resolver : {};
|
||||||
|
|
||||||
if (_.isString(resolver)) {
|
|
||||||
// Retrieve the controller's action to be executed.
|
// Retrieve the controller's action to be executed.
|
||||||
const [ name, action ] = resolver.split('.');
|
const [ name, action ] = handler.split('.');
|
||||||
|
|
||||||
const controller = plugin ?
|
const controller = plugin ?
|
||||||
_.get(strapi.plugins, `${plugin}.controllers.${_.toLower(name)}.${action}`):
|
_.get(strapi.plugins, `${plugin}.controllers.${_.toLower(name)}.${action}`):
|
||||||
@ -328,7 +330,7 @@ module.exports = {
|
|||||||
|
|
||||||
return async (obj, options, context) => {
|
return async (obj, options, context) => {
|
||||||
// Hack to be able to handle permissions for each query.
|
// Hack to be able to handle permissions for each query.
|
||||||
const ctx = Object.assign(context, {
|
const ctx = Object.assign(_.clone(context), {
|
||||||
request: Object.assign(_.clone(context.request), {
|
request: Object.assign(_.clone(context.request), {
|
||||||
graphql: null
|
graphql: null
|
||||||
})
|
})
|
||||||
@ -362,6 +364,7 @@ module.exports = {
|
|||||||
return values && values.toJSON ? values.toJSON() : values;
|
return values && values.toJSON ? values.toJSON() : values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return resolver.call(null, obj, options, context);
|
return resolver.call(null, obj, options, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -560,7 +563,7 @@ module.exports = {
|
|||||||
|
|
||||||
switch (association.nature) {
|
switch (association.nature) {
|
||||||
case 'manyToMany': {
|
case 'manyToMany': {
|
||||||
const arrayOfIds = obj[association.alias].map(related => {
|
const arrayOfIds = (obj[association.alias] || []).map(related => {
|
||||||
return related[ref.primaryKey] || related;
|
return related[ref.primaryKey] || related;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -642,9 +645,20 @@ module.exports = {
|
|||||||
return acc;
|
return acc;
|
||||||
}
|
}
|
||||||
|
|
||||||
acc[type][resolver] = _.isFunction(acc[type][resolver]) ?
|
if (!_.isFunction(acc[type][resolver])) {
|
||||||
acc[type][resolver]:
|
acc[type][resolver] = acc[type][resolver].resolver;
|
||||||
acc[type][resolver].resolver;
|
}
|
||||||
|
|
||||||
|
if (_.isString(acc[type][resolver]) || _.isPlainObject(acc[type][resolver])) {
|
||||||
|
const { plugin = '' } = _.isPlainObject(acc[type][resolver]) ? acc[type][resolver] : {};
|
||||||
|
|
||||||
|
acc[type][resolver] = this.composeResolver(
|
||||||
|
strapi.plugins.graphql.config._schema.graphql,
|
||||||
|
plugin,
|
||||||
|
resolver,
|
||||||
|
'force' // Avoid singular/pluralize and force query name.
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
}, acc);
|
}, acc);
|
||||||
|
@ -39,9 +39,11 @@ module.exports = async (ctx, next) => {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
if (!permission) {
|
if (!permission) {
|
||||||
ctx.forbidden();
|
if (ctx.request.graphql === null) {
|
||||||
|
return ctx.request.graphql = strapi.errors.forbidden();
|
||||||
|
}
|
||||||
|
|
||||||
return ctx.request.graphql = ctx.body;
|
ctx.forbidden();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute the policies.
|
// Execute the policies.
|
||||||
|
@ -19,6 +19,7 @@ module.exports = strapi => {
|
|||||||
this.delegator = delegate(strapi.app.context, 'response');
|
this.delegator = delegate(strapi.app.context, 'response');
|
||||||
this.createResponses();
|
this.createResponses();
|
||||||
|
|
||||||
|
strapi.errors = Boom;
|
||||||
strapi.app.use(async (ctx, next) => {
|
strapi.app.use(async (ctx, next) => {
|
||||||
try {
|
try {
|
||||||
// App logic.
|
// App logic.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user