From 09cff64c5db1c1f58bd651f6d2f96963618d0fe2 Mon Sep 17 00:00:00 2001 From: Johann Pinson Date: Mon, 21 May 2018 15:25:26 +0200 Subject: [PATCH 1/5] fix(graphql): update Union type creation rules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit My PR is a: 🐛 Bug fix Main update on the: Plugin Fix error type `Union type Morph can only include Object types, it cannot include [Enum name]` --- packages/strapi-plugin-graphql/services/GraphQL.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/strapi-plugin-graphql/services/GraphQL.js b/packages/strapi-plugin-graphql/services/GraphQL.js index e0d4ebd5b2..12afa9d2c4 100644 --- a/packages/strapi-plugin-graphql/services/GraphQL.js +++ b/packages/strapi-plugin-graphql/services/GraphQL.js @@ -698,7 +698,7 @@ module.exports = { addPolymorphicUnionType: (customDefs, defs) => { 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); return { From 330aac40efe4b585669ed4cccded56460a608ec6 Mon Sep 17 00:00:00 2001 From: Johann Pinson Date: Mon, 21 May 2018 15:39:45 +0200 Subject: [PATCH 2/5] fix(graphql): update Union type creation rules --- .../strapi-plugin-graphql/services/GraphQL.js | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/strapi-plugin-graphql/services/GraphQL.js b/packages/strapi-plugin-graphql/services/GraphQL.js index 12afa9d2c4..f67d70b0ff 100644 --- a/packages/strapi-plugin-graphql/services/GraphQL.js +++ b/packages/strapi-plugin-graphql/services/GraphQL.js @@ -33,7 +33,7 @@ module.exports = { return lines .map(line => { if (['{', '}'].includes(line)) { - return ``; + return ''; } const split = line.split(':'); @@ -61,7 +61,7 @@ module.exports = { return lines .map((line, index) => { if (['{', '}'].includes(line)) { - return ``; + return ''; } const split = Object.keys(fields)[index - 1].split('('); @@ -90,7 +90,7 @@ module.exports = { return lines .map((line, index) => { if ([0, lines.length - 1].includes(index)) { - return ``; + return ''; } return line; @@ -105,9 +105,9 @@ module.exports = { */ getDescription: (description, model = {}) => { - const format = `"""\n`; + const format = '"""\n'; - const str = _.get(description, `_description`) || + const str = _.get(description, '_description') || _.isString(description) ? description : undefined || _.get(model, 'info.description'); @@ -115,7 +115,7 @@ module.exports = { return `${format}${str}\n${format}`; } - return ``; + return ''; }, convertToParams: (params) => { @@ -167,7 +167,7 @@ module.exports = { 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. const resolvers = strapi.plugins['content-manager'].services['contentmanager']; - const initialState = { definition: ``, query: {}, resolver: { Query : {} } }; + const initialState = { definition: '', query: {}, resolver: { Query : {} } }; if (_.isEmpty(models)) { return initialState; @@ -398,7 +398,7 @@ module.exports = { }; 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]) { acc.resolver[globalId] = {}; @@ -614,7 +614,7 @@ module.exports = { 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. - acc.definition += definition || ``; + acc.definition += definition || ''; return _.merge(acc, { query, @@ -687,7 +687,7 @@ module.exports = { JSON: GraphQLJSON }); - return `scalar JSON`; + return 'scalar JSON'; }, /** @@ -698,7 +698,7 @@ module.exports = { addPolymorphicUnionType: (customDefs, defs) => { const types = graphql.parse(customDefs + defs).definitions - .filter(def => && def.kind === 'ObjectTypeDefinition' && def.name.value !== 'Query') + .filter(def => def.kind === 'ObjectTypeDefinition' && def.name.value !== 'Query') .map(def => def.name.value); return { From 1cdb1dfc76e1ef30d2e2163d7a3a816155b79fa3 Mon Sep 17 00:00:00 2001 From: Johan Baath Date: Wed, 23 May 2018 14:25:32 +0200 Subject: [PATCH 3/5] fix clean up of duplicate permissions --- .../services/UsersPermissions.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/strapi-plugin-users-permissions/services/UsersPermissions.js b/packages/strapi-plugin-users-permissions/services/UsersPermissions.js index a32277b0fc..4e5fc46f2f 100644 --- a/packages/strapi-plugin-users-permissions/services/UsersPermissions.js +++ b/packages/strapi-plugin-users-permissions/services/UsersPermissions.js @@ -317,10 +317,12 @@ module.exports = { initialize: async function (cb) { const roles = await strapi.query('role', 'users-permissions').count(); - // It's has been already initialized. + // It has already been initialized. if (roles > 0) { - await this.removeDuplicate(); - return await this.updatePermissions(cb); + return await this.updatePermissions(async () => { + await this.removeDuplicate(); + cb(); + }); } // Create two first default roles. From e71063920f6dce479a8b58796a7ffd24ae523b72 Mon Sep 17 00:00:00 2001 From: Johann Pinson Date: Wed, 23 May 2018 14:27:23 +0200 Subject: [PATCH 4/5] Fix generate GraphQL schema if ShadowCRUD is false --- .../strapi-plugin-graphql/services/GraphQL.js | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/strapi-plugin-graphql/services/GraphQL.js b/packages/strapi-plugin-graphql/services/GraphQL.js index e0d4ebd5b2..23119c99af 100644 --- a/packages/strapi-plugin-graphql/services/GraphQL.js +++ b/packages/strapi-plugin-graphql/services/GraphQL.js @@ -621,7 +621,7 @@ module.exports = { resolver }); }, this.shadowCRUD(models)); - })() : {}; + })() : { definition: '', query: '', resolver: '' }; // Extract custom definition, query or resolver. const { definition, query, resolver = {} } = strapi.plugins.graphql.config._schema.graphql; @@ -659,7 +659,7 @@ module.exports = { const typeDefs = ` ${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)} ${polymorphicDef} `; @@ -701,15 +701,22 @@ module.exports = { .filter(def => def.name.value !== 'Query') .map(def => def.name.value); - return { - polymorphicDef: `union Morph = ${types.join(' | ')}`, - polymorphicResolver: { - Morph: { - __resolveType(obj, context, info) { // eslint-disable-line no-unused-vars - return obj.kind || obj._type; + if (types.length > 0) { + return { + polymorphicDef: `union Morph = ${types.join(' | ')}`, + polymorphicResolver: { + Morph: { + __resolveType(obj, context, info) { // eslint-disable-line no-unused-vars + return obj.kind || obj._type; + } } } - } + }; + } + + return { + polymorphicDef: '', + polymorphicResolver: {} }; }, From 534fa00c0bc6b6df0ff84218cf0b200448aa7e36 Mon Sep 17 00:00:00 2001 From: Johann Pinson Date: Thu, 24 May 2018 17:13:14 +0200 Subject: [PATCH 5/5] fix(graphql): change timestamp format snake_case to camelCase --- packages/strapi-plugin-graphql/services/GraphQL.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/strapi-plugin-graphql/services/GraphQL.js b/packages/strapi-plugin-graphql/services/GraphQL.js index e0d4ebd5b2..759a1acf65 100644 --- a/packages/strapi-plugin-graphql/services/GraphQL.js +++ b/packages/strapi-plugin-graphql/services/GraphQL.js @@ -407,15 +407,15 @@ module.exports = { // Add timestamps attributes. if (_.get(model, 'options.timestamps') === true) { Object.assign(initialState, { - created_at: 'String', - updated_at: 'String' + createdAt: 'String', + updatedAt: 'String' }); 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; }, - 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; } });