Skip to content

Commit

Permalink
chore(prettier): reformat the code and add format scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalLytek committed Mar 29, 2020
1 parent fe61e9b commit a211550
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 16 deletions.
15 changes: 15 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# node modules
node_modules

# builded sources
build
dist

# coverage reports
coverage

# IntelliJ stuffs
.idea/

# parcel cache
.cache
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"bracketSpacing": true,
"semi": true,
"singleQuote": false,
"arrowParens": "avoid",
"useTabs": false
}
5 changes: 1 addition & 4 deletions docs/dependency-injection.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>(SampleResolver)
> .to(SampleResolver)
> .inSingletonScope();
> container.bind<SampleResolver>(SampleResolver).to(SampleResolver).inSingletonScope();
> ```
## Scoped containers
Expand Down
8 changes: 4 additions & 4 deletions docs/validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<Recipe> {
// you can be 100% sure that the input is correct
console.assert(recipeInput.title.length <= 30);
Expand All @@ -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) {
// ...
}
Expand All @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion examples/typegoose/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]);

Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/resolvers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function getParams(
): Promise<any[]> | any[] {
const paramValues = params
.sort((a, b) => a.index - b.index)
.map((paramInfo) => {
.map(paramInfo => {
switch (paramInfo.kind) {
case "args":
return validateArg(
Expand Down
2 changes: 1 addition & 1 deletion src/resolvers/validate-arg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function validateArg<T extends Object>(
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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export type Without<FirstType, SecondType> = {
[KeyType in Exclude<keyof FirstType, keyof SecondType>]?: never;
};

export type MergeExclusive<FirstType, SecondType> = (FirstType | SecondType) extends object
export type MergeExclusive<FirstType, SecondType> = FirstType | SecondType extends object
? (Without<FirstType, SecondType> & SecondType) | (Without<SecondType, FirstType> & FirstType)
: FirstType | SecondType;

Expand Down
5 changes: 3 additions & 2 deletions tests/functional/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" })
Expand Down Expand Up @@ -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);
};
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/directives/AppendDirective.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand Down

0 comments on commit a211550

Please sign in to comment.