Merge branch 'master' into fix-typo

This commit is contained in:
Jim LAURIE 2018-05-25 18:09:03 +02:00 committed by GitHub
commit cd42dcded2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 28 deletions

View File

@ -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,9 +698,10 @@ 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);
if (types.length > 0) {
return { return {
polymorphicDef: `union Morph = ${types.join(' | ')}`, polymorphicDef: `union Morph = ${types.join(' | ')}`,
polymorphicResolver: { polymorphicResolver: {
@ -711,6 +712,12 @@ module.exports = {
} }
} }
}; };
}
return {
polymorphicDef: '',
polymorphicResolver: {}
};
}, },
/** /**

View File

@ -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) {
return await this.updatePermissions(async () => {
await this.removeDuplicate(); await this.removeDuplicate();
return await this.updatePermissions(cb); cb();
});
} }
// Create two first default roles. // Create two first default roles.