diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 000000000..c2385eead --- /dev/null +++ b/.prettierignore @@ -0,0 +1,15 @@ +# node modules +node_modules + +# builded sources +build +dist + +# coverage reports +coverage + +# IntelliJ stuffs +.idea/ + +# parcel cache +.cache diff --git a/.prettierrc b/.prettierrc index cd4cbdbbd..3cbe4676f 100644 --- a/.prettierrc +++ b/.prettierrc @@ -5,5 +5,6 @@ "bracketSpacing": true, "semi": true, "singleQuote": false, + "arrowParens": "avoid", "useTabs": false } diff --git a/docs/dependency-injection.md b/docs/dependency-injection.md index bff4e6d19..2ded05ba6 100644 --- a/docs/dependency-injection.md +++ b/docs/dependency-injection.md @@ -71,10 +71,7 @@ export class RecipeService { > Be aware than when you use [InversifyJS](https://github.com/inversify/InversifyJS), you have to bind the resolver class with the [self-binding of concrete types](https://github.com/inversify/InversifyJS/blob/master/wiki/classes_as_id.md#self-binding-of-concrete-types), e.g.: > > ```typescript -> container -> .bind(SampleResolver) -> .to(SampleResolver) -> .inSingletonScope(); +> container.bind(SampleResolver).to(SampleResolver).inSingletonScope(); > ``` ## Scoped containers diff --git a/docs/validation.md b/docs/validation.md index 63704e26c..9ac2500ad 100644 --- a/docs/validation.md +++ b/docs/validation.md @@ -46,9 +46,9 @@ And that's it! 😉 TypeGraphQL will automatically validate our inputs and arguments based on the definitions: ```typescript -@Resolver((of) => Recipe) +@Resolver(of => Recipe) export class RecipeResolver { - @Mutation((returns) => Recipe) + @Mutation(returns => Recipe) async addRecipe(@Arg("input") recipeInput: RecipeInput): Promise { // you can be 100% sure that the input is correct console.assert(recipeInput.title.length <= 30); @@ -73,7 +73,7 @@ And we can still enable it per resolver's argument if we need to: ```typescript class RecipeResolver { - @Mutation((returns) => Recipe) + @Mutation(returns => Recipe) async addRecipe(@Arg("input", { validate: true }) recipeInput: RecipeInput) { // ... } @@ -84,7 +84,7 @@ The `ValidatorOptions` object used for setting features like [validation groups] ```typescript class RecipeResolver { - @Mutation((returns) => Recipe) + @Mutation(returns => Recipe) async addRecipe( @Arg("input", { validate: { groups: ["admin"] } }) recipeInput: RecipeInput, diff --git a/examples/typegoose/helpers.ts b/examples/typegoose/helpers.ts index d08618a9a..f63cf98a0 100644 --- a/examples/typegoose/helpers.ts +++ b/examples/typegoose/helpers.ts @@ -24,7 +24,10 @@ export async function seedDatabase() { { title: "Recipe 2", author: defaultUser._id, - ratings: [{ value: 2, user: defaultUser }, { value: 4, user: defaultUser }], + ratings: [ + { value: 2, user: defaultUser }, + { value: 4, user: defaultUser }, + ], }, ] as Recipe[]); diff --git a/package.json b/package.json index b366502fd..67f00e35e 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,10 @@ "test": "jest --verbose --coverage", "test:ci": "jest --verbose --coverage --ci --forceExit --detectOpenHandles --runInBand", "test:watch": "jest --watch", - "check": "tsc --noEmit", + "format": "prettier --write \"{src,tests,examples}/**/*.{ts,js}\" \"docs/**/*.md\"", + "check:format": "prettier --check \"{src,tests,examples}/**/*.{ts,js}\" \"docs/**/*.md\"", + "check:type": "tsc --noEmit", + "check": "npm run check:format && npm run check:type", "lint": "tslint --project tsconfig.json", "verify": "npm run check && npm run lint", "package": "gulp package", diff --git a/src/resolvers/helpers.ts b/src/resolvers/helpers.ts index 55ea351ac..067ef264a 100644 --- a/src/resolvers/helpers.ts +++ b/src/resolvers/helpers.ts @@ -19,7 +19,7 @@ export function getParams( ): Promise | any[] { const paramValues = params .sort((a, b) => a.index - b.index) - .map((paramInfo) => { + .map(paramInfo => { switch (paramInfo.kind) { case "args": return validateArg( diff --git a/src/resolvers/validate-arg.ts b/src/resolvers/validate-arg.ts index d9c47a68c..bc31c4c1f 100644 --- a/src/resolvers/validate-arg.ts +++ b/src/resolvers/validate-arg.ts @@ -24,7 +24,7 @@ export async function validateArg( const { validateOrReject } = await import("class-validator"); try { if (Array.isArray(arg)) { - await Promise.all(arg.map((argItem) => validateOrReject(argItem, validatorOptions))); + await Promise.all(arg.map(argItem => validateOrReject(argItem, validatorOptions))); } else { await validateOrReject(arg, validatorOptions); } diff --git a/src/utils/types.ts b/src/utils/types.ts index 22b879226..e0a37ef79 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -5,7 +5,7 @@ export type Without = { [KeyType in Exclude]?: never; }; -export type MergeExclusive = (FirstType | SecondType) extends object +export type MergeExclusive = FirstType | SecondType extends object ? (Without & SecondType) | (Without & FirstType) : FirstType | SecondType; diff --git a/tests/functional/resolvers.ts b/tests/functional/resolvers.ts index aaeee0c33..de3a169ae 100644 --- a/tests/functional/resolvers.ts +++ b/tests/functional/resolvers.ts @@ -133,7 +133,8 @@ describe("Resolvers", () => { @Arg("numberArg") numberArg: number, @Arg("inputArg") inputArg: SampleInput, @Arg("inputChildArg") inputChildArg: SampleInputChild, - @Arg("explicitNullableArg", type => String, { nullable: true }) explicitNullableArg: any, + @Arg("explicitNullableArg", type => String, { nullable: true }) + explicitNullableArg: any, @Arg("stringArrayArg", type => String) stringArrayArg: string[], @Arg("explicitArrayArg", type => [String]) explicitArrayArg: any, @Arg("defaultStringArg", { defaultValue: "defaultStringArgDefaultValue" }) @@ -1093,7 +1094,7 @@ describe("Resolvers", () => { function DescriptorDecorator(): MethodDecorator { return (obj, methodName, descriptor: any) => { const originalMethod: Function = descriptor.value; - descriptor.value = function() { + descriptor.value = function () { descriptorEvaluated = true; return originalMethod.apply(this, arguments); }; diff --git a/tests/helpers/directives/AppendDirective.ts b/tests/helpers/directives/AppendDirective.ts index 8f017794d..fe07ba6f7 100644 --- a/tests/helpers/directives/AppendDirective.ts +++ b/tests/helpers/directives/AppendDirective.ts @@ -21,7 +21,7 @@ export class AppendDirective extends SchemaDirectiveVisitor { astNode: undefined, }); - field.resolve = async function(source, { append, ...otherArgs }, context, info) { + field.resolve = async function (source, { append, ...otherArgs }, context, info) { const result = await resolve!.call(this, source, otherArgs, context, info); return `${result}${append}`;