eslint-plugin-prisma-nestjs-graphql
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -9,3 +9,11 @@ "use strict"; | ||
const entities = JSON.parse((0, fs_1.readFileSync)(`prisma/generated/json-schema.json`, 'utf-8')); | ||
const scalars = ['string', 'float', 'integer', 'object', 'enum', 'boolean', 'number']; | ||
const scalars = [ | ||
'string', | ||
'float', | ||
'integer', | ||
'object', | ||
'enum', | ||
'boolean', | ||
'number', | ||
]; | ||
const prismaEntities = Object.entries(entities.definitions).map(e => ({ | ||
@@ -41,2 +49,5 @@ name: e[0], | ||
})); | ||
const args = (name, type) => { | ||
return `@Args({ name: '${name}', nullable: true }) ${name}: ${type}OrderByInput,`; | ||
}; | ||
module.exports = { | ||
@@ -92,5 +103,11 @@ rules: { | ||
fix: function (fixer) { | ||
const importFix = fixer.insertTextBefore(decorator, `import {${openResolvers | ||
.map(r => r.type.replace('[', '').replace(']', '')) | ||
.join(', ')}} from '@prisma/client/nestjs-graphql' | ||
const imports = openResolvers.map(r => r.type.replace('[', '').replace(']', '')); | ||
const multiImports = openResolvers | ||
.filter(i => -1 !== i.type.search('[')) | ||
.map(r => r.type.replace('[', '').replace(']', '')); | ||
const importFix = fixer.insertTextBefore(decorator, `import { | ||
${imports.join(', ')}, | ||
${multiImports.map(i => i + 'WhereInput').join(', ')}, | ||
${multiImports.map(i => i + 'OrderByInput').join(', ')}, | ||
} from '@prisma/client/nestjs-graphql' | ||
`); | ||
@@ -103,5 +120,11 @@ const txt = `\n\n\n // FIELDRESOLVERS \n` + | ||
@ResolveField(() => ${r.type}, { | ||
name: '${r.name}', ${isToManyRelation ? '' : '\n nullable: true,'} | ||
name: '${r.name}', | ||
${isToManyRelation ? '' : '\n nullable: true,'} | ||
}) | ||
${r.name}(@Parent() ${(0, camelcase_1.default)(decoratorName)}: ${decoratorName}) { | ||
${r.name}(@Parent() ${(0, camelcase_1.default)(decoratorName)}: ${decoratorName}, ${isToManyRelation | ||
? args('where', r.type) + | ||
', \n' + | ||
args('orderBy', r.type) | ||
: ''} | ||
) { | ||
return this.${(0, camelcase_1.default)(decoratorName)}Service | ||
@@ -111,3 +134,3 @@ .findOne({ | ||
}) | ||
.${r.name}(); | ||
.${r.name}({ where }); | ||
} | ||
@@ -114,0 +137,0 @@ `; |
{ | ||
"name": "eslint-plugin-prisma-nestjs-graphql", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "eslint plugin for prisma & nestjs & graphql setups to not forget resolvers etc.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -14,2 +14,3 @@ # eslint-plugin-prisma-nestjs-graphql | ||
- Install it: npm i -D eslint-plugin-prisma-nestjs-graphql | ||
- It needs you to also use https://www.npmjs.com/package/prisma-json-schema-generator as generator for your prisma setup. | ||
@@ -28,4 +29,2 @@ - The p will look for a file called `prisma/generated/json-schema.json` which should be generated by the prisma-json-schema-generator | ||
- Your resolver files should reside in a folder | ||
## Known issues | ||
@@ -32,0 +31,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36022
145
39