mirror of
https://github.com/strapi/strapi.git
synced 2025-08-11 02:07:51 +00:00
Merge branch 'master' into fix-typo
This commit is contained in:
commit
cd42dcded2
@ -33,7 +33,7 @@ module.exports = {
|
|||||||
return lines
|
return lines
|
||||||
.map(line => {
|
.map(line => {
|
||||||
if (['{', '}'].includes(line)) {
|
if (['{', '}'].includes(line)) {
|
||||||
return ``;
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
const split = line.split(':');
|
const split = line.split(':');
|
||||||
@ -61,7 +61,7 @@ module.exports = {
|
|||||||
return lines
|
return lines
|
||||||
.map((line, index) => {
|
.map((line, index) => {
|
||||||
if (['{', '}'].includes(line)) {
|
if (['{', '}'].includes(line)) {
|
||||||
return ``;
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
const split = Object.keys(fields)[index - 1].split('(');
|
const split = Object.keys(fields)[index - 1].split('(');
|
||||||
@ -90,7 +90,7 @@ module.exports = {
|
|||||||
return lines
|
return lines
|
||||||
.map((line, index) => {
|
.map((line, index) => {
|
||||||
if ([0, lines.length - 1].includes(index)) {
|
if ([0, lines.length - 1].includes(index)) {
|
||||||
return ``;
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
return line;
|
return line;
|
||||||
@ -105,9 +105,9 @@ module.exports = {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
getDescription: (description, model = {}) => {
|
getDescription: (description, model = {}) => {
|
||||||
const format = `"""\n`;
|
const format = '"""\n';
|
||||||
|
|
||||||
const str = _.get(description, `_description`) ||
|
const str = _.get(description, '_description') ||
|
||||||
_.isString(description) ? description : undefined ||
|
_.isString(description) ? description : undefined ||
|
||||||
_.get(model, 'info.description');
|
_.get(model, 'info.description');
|
||||||
|
|
||||||
@ -115,7 +115,7 @@ module.exports = {
|
|||||||
return `${format}${str}\n${format}`;
|
return `${format}${str}\n${format}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ``;
|
return '';
|
||||||
},
|
},
|
||||||
|
|
||||||
convertToParams: (params) => {
|
convertToParams: (params) => {
|
||||||
@ -167,7 +167,7 @@ module.exports = {
|
|||||||
return globalId;
|
return globalId;
|
||||||
}
|
}
|
||||||
|
|
||||||
return definition.model ? `Morph` : `[Morph]`;
|
return definition.model ? 'Morph' : '[Morph]';
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -380,7 +380,7 @@ module.exports = {
|
|||||||
// Retrieve generic service from the Content Manager plugin.
|
// Retrieve generic service from the Content Manager plugin.
|
||||||
const resolvers = strapi.plugins['content-manager'].services['contentmanager'];
|
const resolvers = strapi.plugins['content-manager'].services['contentmanager'];
|
||||||
|
|
||||||
const initialState = { definition: ``, query: {}, resolver: { Query : {} } };
|
const initialState = { definition: '', query: {}, resolver: { Query : {} } };
|
||||||
|
|
||||||
if (_.isEmpty(models)) {
|
if (_.isEmpty(models)) {
|
||||||
return initialState;
|
return initialState;
|
||||||
@ -398,7 +398,7 @@ module.exports = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const globalId = model.globalId;
|
const globalId = model.globalId;
|
||||||
const _schema = _.cloneDeep(_.get(strapi.plugins, `graphql.config._schema.graphql`, {}));
|
const _schema = _.cloneDeep(_.get(strapi.plugins, 'graphql.config._schema.graphql', {}));
|
||||||
|
|
||||||
if (!acc.resolver[globalId]) {
|
if (!acc.resolver[globalId]) {
|
||||||
acc.resolver[globalId] = {};
|
acc.resolver[globalId] = {};
|
||||||
@ -407,15 +407,15 @@ module.exports = {
|
|||||||
// Add timestamps attributes.
|
// Add timestamps attributes.
|
||||||
if (_.get(model, 'options.timestamps') === true) {
|
if (_.get(model, 'options.timestamps') === true) {
|
||||||
Object.assign(initialState, {
|
Object.assign(initialState, {
|
||||||
created_at: 'String',
|
createdAt: 'String',
|
||||||
updated_at: 'String'
|
updatedAt: 'String'
|
||||||
});
|
});
|
||||||
|
|
||||||
Object.assign(acc.resolver[globalId], {
|
Object.assign(acc.resolver[globalId], {
|
||||||
created_at: (obj, options, context) => { // eslint-disable-line no-unused-vars
|
createdAt: (obj, options, context) => { // eslint-disable-line no-unused-vars
|
||||||
return obj.createdAt || obj.created_at;
|
return obj.createdAt || obj.created_at;
|
||||||
},
|
},
|
||||||
updated_at: (obj, options, context) => { // eslint-disable-line no-unused-vars
|
updatedAt: (obj, options, context) => { // eslint-disable-line no-unused-vars
|
||||||
return obj.updatedAt || obj.updated_at;
|
return obj.updatedAt || obj.updated_at;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -614,14 +614,14 @@ module.exports = {
|
|||||||
const { definition, query, resolver } = this.shadowCRUD(Object.keys(strapi.plugins[plugin].models), plugin);
|
const { definition, query, resolver } = this.shadowCRUD(Object.keys(strapi.plugins[plugin].models), plugin);
|
||||||
|
|
||||||
// We cannot put this in the merge because it's a string.
|
// We cannot put this in the merge because it's a string.
|
||||||
acc.definition += definition || ``;
|
acc.definition += definition || '';
|
||||||
|
|
||||||
return _.merge(acc, {
|
return _.merge(acc, {
|
||||||
query,
|
query,
|
||||||
resolver
|
resolver
|
||||||
});
|
});
|
||||||
}, this.shadowCRUD(models));
|
}, this.shadowCRUD(models));
|
||||||
})() : {};
|
})() : { definition: '', query: '', resolver: '' };
|
||||||
|
|
||||||
// Extract custom definition, query or resolver.
|
// Extract custom definition, query or resolver.
|
||||||
const { definition, query, resolver = {} } = strapi.plugins.graphql.config._schema.graphql;
|
const { definition, query, resolver = {} } = strapi.plugins.graphql.config._schema.graphql;
|
||||||
@ -659,7 +659,7 @@ module.exports = {
|
|||||||
const typeDefs = `
|
const typeDefs = `
|
||||||
${definition}
|
${definition}
|
||||||
${shadowCRUD.definition}
|
${shadowCRUD.definition}
|
||||||
type Query {${this.formatGQL(shadowCRUD.query, resolver.Query, null, 'query')}${query}}
|
type Query {${shadowCRUD.query && this.formatGQL(shadowCRUD.query, resolver.Query, null, 'query')}${query}}
|
||||||
${this.addCustomScalar(resolvers)}
|
${this.addCustomScalar(resolvers)}
|
||||||
${polymorphicDef}
|
${polymorphicDef}
|
||||||
`;
|
`;
|
||||||
@ -687,7 +687,7 @@ module.exports = {
|
|||||||
JSON: GraphQLJSON
|
JSON: GraphQLJSON
|
||||||
});
|
});
|
||||||
|
|
||||||
return `scalar JSON`;
|
return 'scalar JSON';
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -698,18 +698,25 @@ module.exports = {
|
|||||||
|
|
||||||
addPolymorphicUnionType: (customDefs, defs) => {
|
addPolymorphicUnionType: (customDefs, defs) => {
|
||||||
const types = graphql.parse(customDefs + defs).definitions
|
const types = graphql.parse(customDefs + defs).definitions
|
||||||
.filter(def => def.name.value !== 'Query')
|
.filter(def => def.kind === 'ObjectTypeDefinition' && def.name.value !== 'Query')
|
||||||
.map(def => def.name.value);
|
.map(def => def.name.value);
|
||||||
|
|
||||||
return {
|
if (types.length > 0) {
|
||||||
polymorphicDef: `union Morph = ${types.join(' | ')}`,
|
return {
|
||||||
polymorphicResolver: {
|
polymorphicDef: `union Morph = ${types.join(' | ')}`,
|
||||||
Morph: {
|
polymorphicResolver: {
|
||||||
__resolveType(obj, context, info) { // eslint-disable-line no-unused-vars
|
Morph: {
|
||||||
return obj.kind || obj._type;
|
__resolveType(obj, context, info) { // eslint-disable-line no-unused-vars
|
||||||
|
return obj.kind || obj._type;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
polymorphicDef: '',
|
||||||
|
polymorphicResolver: {}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -317,10 +317,12 @@ module.exports = {
|
|||||||
initialize: async function (cb) {
|
initialize: async function (cb) {
|
||||||
const roles = await strapi.query('role', 'users-permissions').count();
|
const roles = await strapi.query('role', 'users-permissions').count();
|
||||||
|
|
||||||
// It's has been already initialized.
|
// It has already been initialized.
|
||||||
if (roles > 0) {
|
if (roles > 0) {
|
||||||
await this.removeDuplicate();
|
return await this.updatePermissions(async () => {
|
||||||
return await this.updatePermissions(cb);
|
await this.removeDuplicate();
|
||||||
|
cb();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create two first default roles.
|
// Create two first default roles.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user