Merge pull request #1085 from strapi/eslint-email-graphql

Eslint email graphql
This commit is contained in:
Jim LAURIE 2018-05-03 14:06:39 +02:00 committed by GitHub
commit 30c21aef35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 29 deletions

View File

@ -17,16 +17,17 @@
"build:clean": "node ./node_modules/strapi-helper-plugin/node_modules/.bin/rimraf admin/build", "build:clean": "node ./node_modules/strapi-helper-plugin/node_modules/.bin/rimraf admin/build",
"start": "node ./node_modules/strapi-helper-plugin/node_modules/.bin/cross-env NODE_ENV=development node ./node_modules/strapi-helper-plugin/lib/server", "start": "node ./node_modules/strapi-helper-plugin/node_modules/.bin/cross-env NODE_ENV=development node ./node_modules/strapi-helper-plugin/lib/server",
"generate": "node ./node_modules/strapi-helper-plugin/node_modules/.bin/plop --plopfile ./node_modules/strapi-helper-plugin/lib/internals/generators/index.js", "generate": "node ./node_modules/strapi-helper-plugin/node_modules/.bin/plop --plopfile ./node_modules/strapi-helper-plugin/lib/internals/generators/index.js",
"lint": "node ./node_modules/strapi-helper-plugin/node_modules/.bin/eslint --ignore-path .gitignore --ignore-pattern '/admin/build/' --config ./node_modules/strapi-helper-plugin/lib/internals/eslint/.eslintrc.json admin", "lint:back": "node ./node_modules/strapi-lint/node_modules/.bin/eslint --ignore-path .gitignore --ignore-pattern '/admin/build/' --config ./node_modules/strapi-lint/lib/internals/eslint/back/.eslintrc.json controllers config services",
"prettier": "node ./node_modules/strapi-helper-plugin/node_modules/.bin/prettier --single-quote --trailing-comma es5 --write \"{admin,__{tests,mocks}__}/**/*.js\"", "prettier": "node ./node_modules/strapi-helper-plugin/node_modules/.bin/prettier --single-quote --trailing-comma es5 --write \"{admin,__{tests,mocks}__}/**/*.js\"",
"test": "npm run lint", "test": "npm run lint:back",
"prepublishOnly": "npm run build" "prepublishOnly": "npm run build"
}, },
"dependencies": { "dependencies": {
"sendmail": "^1.2.0" "sendmail": "^1.2.0"
}, },
"devDependencies": { "devDependencies": {
"strapi-helper-plugin": "3.0.0-alpha.12" "strapi-helper-plugin": "3.0.0-alpha.12",
"strapi-lint": "3.0.0-alpha.12"
}, },
"author": { "author": {
"name": "Strapi team", "name": "Strapi team",

View File

@ -12,7 +12,7 @@ const sendmail = require('sendmail')({
}); });
module.exports = { module.exports = {
send: (options, cb) => { send: (options, cb) => { // eslint-disable-line no-unused-vars
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
// Default values. // Default values.
options = _.isObject(options) ? options : {}; options = _.isObject(options) ? options : {};

View File

@ -17,9 +17,9 @@
"build:clean": "node ./node_modules/strapi-helper-plugin/node_modules/.bin/rimraf admin/build", "build:clean": "node ./node_modules/strapi-helper-plugin/node_modules/.bin/rimraf admin/build",
"start": "node ./node_modules/strapi-helper-plugin/node_modules/.bin/cross-env NODE_ENV=development node ./node_modules/strapi-helper-plugin/lib/server", "start": "node ./node_modules/strapi-helper-plugin/node_modules/.bin/cross-env NODE_ENV=development node ./node_modules/strapi-helper-plugin/lib/server",
"generate": "node ./node_modules/plop/plop.js --plopfile node_modules/strapi-helper-plugin/lib/internals/generators/index.js", "generate": "node ./node_modules/plop/plop.js --plopfile node_modules/strapi-helper-plugin/lib/internals/generators/index.js",
"lint": "node ./node_modules/strapi-helper-plugin/node_modules/.bin/eslint --ignore-path .gitignore --ignore-pattern '/admin/build/' --config ./node_modules/strapi-helper-plugin/lib/internals/eslint/.eslintrc.json admin", "lint:back": "node ./node_modules/strapi-lint/node_modules/.bin/eslint --ignore-path .gitignore --ignore-pattern '/admin/build/' --config ./node_modules/strapi-lint/lib/internals/eslint/back/.eslintrc.json controllers config services",
"prettier": "node ./node_modules/strapi-helper-plugin/node_modules/.bin/prettier --single-quote --trailing-comma es5 --write \"{admin,__{tests,mocks}__}/**/*.js\"", "prettier": "node ./node_modules/strapi-helper-plugin/node_modules/.bin/prettier --single-quote --trailing-comma es5 --write \"{admin,__{tests,mocks}__}/**/*.js\"",
"test": "npm run lint" "test": "npm run lint:back"
}, },
"dependencies": { "dependencies": {
"apollo-server-koa": "^1.3.3", "apollo-server-koa": "^1.3.3",
@ -30,6 +30,9 @@
"pluralize": "^7.0.0", "pluralize": "^7.0.0",
"strapi-utils": "3.0.0-alpha.12" "strapi-utils": "3.0.0-alpha.12"
}, },
"devDependencies": {
"strapi-lint": "3.0.0-alpha.12"
},
"author": { "author": {
"name": "A Strapi developer", "name": "A Strapi developer",
"email": "", "email": "",

View File

@ -6,7 +6,6 @@
* @description: A set of functions similar to controller's actions to avoid code duplication. * @description: A set of functions similar to controller's actions to avoid code duplication.
*/ */
const policyUtils = require('strapi-utils').policy;
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
@ -15,6 +14,7 @@ const pluralize = require('pluralize');
const graphql = require('graphql'); const graphql = require('graphql');
const { makeExecutableSchema } = require('graphql-tools'); const { makeExecutableSchema } = require('graphql-tools');
const GraphQLJSON = require('graphql-type-json'); const GraphQLJSON = require('graphql-type-json');
const policyUtils = require('strapi-utils').policy;
module.exports = { module.exports = {
@ -31,7 +31,7 @@ module.exports = {
// Try to add description for field. // Try to add description for field.
if (type === 'field') { if (type === 'field') {
return lines return lines
.map((line, index) => { .map(line => {
if (['{', '}'].includes(line)) { if (['{', '}'].includes(line)) {
return ``; return ``;
} }
@ -88,14 +88,14 @@ 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;
}) })
.join('\n'); .join('\n');
}, },
/** /**
@ -181,14 +181,14 @@ module.exports = {
model: name model: name
}; };
const queryOpts = plugin ? { source: plugin } : {}; const queryOpts = plugin ? { source: plugin } : {}; // eslint-disable-line no-unused-vars
const model = plugin ? const model = plugin ?
strapi.plugins[plugin].models[name]: strapi.plugins[plugin].models[name]:
strapi.models[name]; strapi.models[name];
// 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']; // eslint-disable-line no-unused-vars
// Extract custom resolver or type description. // Extract custom resolver or type description.
const { resolver: handler = {} } = _schema; const { resolver: handler = {} } = _schema;
@ -282,7 +282,7 @@ module.exports = {
// Return the controller. // Return the controller.
return controller(ctx, next); return controller(ctx, next);
} };
} }
// Plural. // Plural.
@ -293,7 +293,7 @@ module.exports = {
); );
return controller(ctx, next); return controller(ctx, next);
} };
})(); })();
// The controller hasn't been found. // The controller hasn't been found.
@ -362,7 +362,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);
} }
// Resolver can be a promise. // Resolver can be a promise.
@ -412,10 +412,10 @@ module.exports = {
}); });
Object.assign(acc.resolver[globalId], { Object.assign(acc.resolver[globalId], {
created_at: (obj, options, context) => { created_at: (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) => { updated_at: (obj, options, context) => { // eslint-disable-line no-unused-vars
return obj.updatedAt || obj.updated_at; return obj.updatedAt || obj.updated_at;
} }
}); });
@ -440,7 +440,7 @@ module.exports = {
attributes[`${association.alias}(sort: String, limit: Int, start: Int, where: JSON)`] = attributes[association.alias]; attributes[`${association.alias}(sort: String, limit: Int, start: Int, where: JSON)`] = attributes[association.alias];
delete attributes[association.alias]; delete attributes[association.alias];
}) });
acc.definition += `${this.getDescription(type[globalId], model)}type ${globalId} {${this.formatGQL(attributes, type[globalId], model)}}\n\n`; acc.definition += `${this.getDescription(type[globalId], model)}type ${globalId} {${this.formatGQL(attributes, type[globalId], model)}}\n\n`;
@ -499,7 +499,7 @@ module.exports = {
case 'manyMorphToMany': case 'manyMorphToMany':
case 'manyToManyMorph': case 'manyToManyMorph':
return _.merge(acc.resolver[globalId], { return _.merge(acc.resolver[globalId], {
[association.alias]: async (obj, options, context) => { [association.alias]: async (obj, options, context) => { // eslint-disable-line no-unused-vars
const [ withRelated, withoutRelated ] = await Promise.all([ const [ withRelated, withoutRelated ] = await Promise.all([
resolvers.fetch({ resolvers.fetch({
id: obj[model.primaryKey], id: obj[model.primaryKey],
@ -526,12 +526,11 @@ module.exports = {
return entry[association.alias]; return entry[association.alias];
} }
}); });
break;
default: default:
} }
_.merge(acc.resolver[globalId], { _.merge(acc.resolver[globalId], {
[association.alias]: async (obj, options, context) => { [association.alias]: async (obj, options, context) => { // eslint-disable-line no-unused-vars
// Construct parameters object to retrieve the correct related entries. // Construct parameters object to retrieve the correct related entries.
const params = { const params = {
model: association.model || association.collection, model: association.model || association.collection,
@ -565,7 +564,7 @@ module.exports = {
queryOpts.skip = convertedParams.start; queryOpts.skip = convertedParams.start;
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;
}); });
@ -578,6 +577,7 @@ module.exports = {
...where.where ...where.where
}).where; }).where;
break; break;
}
default: default:
// Where. // Where.
queryOpts.query = strapi.utils.models.convertParams(name, { queryOpts.query = strapi.utils.models.convertParams(name, {
@ -710,12 +710,12 @@ module.exports = {
polymorphicDef: `union Morph = ${types.join(' | ')}`, polymorphicDef: `union Morph = ${types.join(' | ')}`,
polymorphicResolver: { polymorphicResolver: {
Morph: { Morph: {
__resolveType(obj, context, info) { __resolveType(obj, context, info) { // eslint-disable-line no-unused-vars
return obj.kind || obj._type; return obj.kind || obj._type;
} }
} }
} }
} };
}, },
/** /**

View File

@ -119,6 +119,10 @@ shell.cd('../strapi');
watcher('', 'npm install ../strapi-generate ../strapi-generate-admin ../strapi-generate-api ../strapi-generate-new ../strapi-generate-plugin ../strapi-generate-policy ../strapi-generate-service ../strapi-utils'); watcher('', 'npm install ../strapi-generate ../strapi-generate-admin ../strapi-generate-api ../strapi-generate-new ../strapi-generate-plugin ../strapi-generate-policy ../strapi-generate-service ../strapi-utils');
watcher('📦 Linking strapi...', 'npm link'); watcher('📦 Linking strapi...', 'npm link');
shell.cd('../strapi-plugin-graphql');
watcher('', 'npm install ../strapi-lint --no-optional');
watcher('📦 Linking strapi-plugin-graphql...', 'npm link --no-optional', false);
// Upload plugins // Upload plugins
shell.cd('../strapi-upload-local'); shell.cd('../strapi-upload-local');
watcher('📦 Linking strapi-upload-local...', 'npm link --no-optional', false); watcher('📦 Linking strapi-upload-local...', 'npm link --no-optional', false);
@ -126,6 +130,7 @@ watcher('📦 Linking strapi-upload-local...', 'npm link --no-optional', false)
// Plugins with admin // Plugins with admin
shell.cd('../strapi-plugin-email'); shell.cd('../strapi-plugin-email');
shell.rm('-f', 'package-lock.json'); shell.rm('-f', 'package-lock.json');
watcher('', 'npm install ../strapi-lint --no-optional');
watcher('📦 Linking strapi-plugin-email...', 'npm link --no-optional', false); watcher('📦 Linking strapi-plugin-email...', 'npm link --no-optional', false);
shell.cd('../strapi-plugin-users-permissions'); shell.cd('../strapi-plugin-users-permissions');