Skip to content

Commit

Permalink
style(lint): remove unused params
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Oct 17, 2024
1 parent 1cb46cf commit a89b34c
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 76 deletions.
2 changes: 1 addition & 1 deletion content/graphql/directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Directives can be applied on fields, field resolvers, input and object types, as

```typescript
@Directive('@deprecated(reason: "This query will be removed in the next version")')
@Query(returns => Author, { name: 'author' })
@Query(() => Author, { name: 'author' })
async getAuthor(@Args({ name: 'id', type: () => Int }) id: number) {
return this.authorsService.findOneById(id);
}
Expand Down
60 changes: 30 additions & 30 deletions content/graphql/federation.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ import { Directive, Field, ID, ObjectType } from '@nestjs/graphql';
@ObjectType()
@Directive('@key(fields: "id")')
export class User {
@Field((type) => ID)
@Field(() => ID)
id: number;

@Field()
Expand All @@ -106,11 +106,11 @@ import { Args, Query, Resolver, ResolveReference } from '@nestjs/graphql';
import { User } from './user.entity';
import { UsersService } from './users.service';

@Resolver((of) => User)
@Resolver(() => User)
export class UsersResolver {
constructor(private usersService: UsersService) {}

@Query((returns) => User)
@Query(() => User)
getUser(@Args('id') id: number): User {
return this.usersService.findById(id);
}
Expand Down Expand Up @@ -231,11 +231,11 @@ import { Post } from './post.entity';
@Directive('@extends')
@Directive('@key(fields: "id")')
export class User {
@Field((type) => ID)
@Field(() => ID)
@Directive('@external')
id: number;

@Field((type) => [Post])
@Field(() => [Post])
posts?: Post[];
}
```
Expand All @@ -248,11 +248,11 @@ import { PostsService } from './posts.service';
import { Post } from './post.entity';
import { User } from './user.entity';

@Resolver((of) => User)
@Resolver(() => User)
export class UsersResolver {
constructor(private readonly postsService: PostsService) {}

@ResolveField((of) => [Post])
@ResolveField(() => [Post])
public posts(@Parent() user: User): Post[] {
return this.postsService.forAuthor(user.id);
}
Expand All @@ -268,16 +268,16 @@ import { User } from './user.entity';
@ObjectType()
@Directive('@key(fields: "id")')
export class Post {
@Field((type) => ID)
@Field(() => ID)
id: number;

@Field()
title: string;

@Field((type) => Int)
@Field(() => Int)
authorId: number;

@Field((type) => User)
@Field(() => User)
user?: User;
}
```
Expand All @@ -290,21 +290,21 @@ import { PostsService } from './posts.service';
import { Post } from './post.entity';
import { User } from './user.entity';

@Resolver((of) => Post)
@Resolver(() => Post)
export class PostsResolver {
constructor(private readonly postsService: PostsService) {}

@Query((returns) => Post)
@Query(() => Post)
findPost(@Args('id') id: number): Post {
return this.postsService.findOne(id);
}

@Query((returns) => [Post])
@Query(() => [Post])
getPosts(): Post[] {
return this.postsService.all();
}

@ResolveField((of) => User)
@ResolveField(() => User)
user(@Parent() post: Post): any {
return { __typename: 'User', id: post.authorId };
}
Expand Down Expand Up @@ -462,7 +462,7 @@ import { Directive, Field, ID, ObjectType } from '@nestjs/graphql';
@ObjectType()
@Directive('@key(fields: "id")')
export class User {
@Field((type) => ID)
@Field(() => ID)
id: number;

@Field()
Expand All @@ -477,11 +477,11 @@ import { Args, Query, Resolver, ResolveReference } from '@nestjs/graphql';
import { User } from './user.entity';
import { UsersService } from './users.service';

@Resolver((of) => User)
@Resolver(() => User)
export class UsersResolver {
constructor(private usersService: UsersService) {}

@Query((returns) => User)
@Query(() => User)
getUser(@Args('id') id: number): User {
return this.usersService.findById(id);
}
Expand Down Expand Up @@ -602,11 +602,11 @@ import { Post } from './post.entity';
@Directive('@extends')
@Directive('@key(fields: "id")')
export class User {
@Field((type) => ID)
@Field(() => ID)
@Directive('@external')
id: number;

@Field((type) => [Post])
@Field(() => [Post])
posts?: Post[];
}
```
Expand All @@ -619,11 +619,11 @@ import { PostsService } from './posts.service';
import { Post } from './post.entity';
import { User } from './user.entity';

@Resolver((of) => User)
@Resolver(() => User)
export class UsersResolver {
constructor(private readonly postsService: PostsService) {}

@ResolveField((of) => [Post])
@ResolveField(() => [Post])
public posts(@Parent() user: User): Post[] {
return this.postsService.forAuthor(user.id);
}
Expand All @@ -639,16 +639,16 @@ import { User } from './user.entity';
@ObjectType()
@Directive('@key(fields: "id")')
export class Post {
@Field((type) => ID)
@Field(() => ID)
id: number;

@Field()
title: string;

@Field((type) => Int)
@Field(() => Int)
authorId: number;

@Field((type) => User)
@Field(() => User)
user?: User;
}
```
Expand All @@ -661,21 +661,21 @@ import { PostsService } from './posts.service';
import { Post } from './post.entity';
import { User } from './user.entity';

@Resolver((of) => Post)
@Resolver(() => Post)
export class PostsResolver {
constructor(private readonly postsService: PostsService) {}

@Query((returns) => Post)
@Query(() => Post)
findPost(@Args('id') id: number): Post {
return this.postsService.findOne(id);
}

@Query((returns) => [Post])
@Query(() => [Post])
getPosts(): Post[] {
return this.postsService.all();
}

@ResolveField((of) => User)
@ResolveField(() => User)
user(@Parent() post: Post): any {
return { __typename: 'User', id: post.authorId };
}
Expand Down Expand Up @@ -830,10 +830,10 @@ import { Post } from './post.entity';
@ObjectType()
@Directive('@key(fields: "id")')
export class User {
@Field((type) => ID)
@Field(() => ID)
id: number;

@Field((type) => [Post])
@Field(() => [Post])
posts?: Post[];
}
```
Expand Down
6 changes: 3 additions & 3 deletions content/graphql/interfaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Field, ID, InterfaceType } from '@nestjs/graphql';

@InterfaceType()
export abstract class Character {
@Field((type) => ID)
@Field(() => ID)
id: string;

@Field()
Expand Down Expand Up @@ -58,7 +58,7 @@ To provide a customized `resolveType()` function, pass the `resolveType` propert
},
})
export abstract class Book {
@Field((type) => ID)
@Field(() => ID)
id: string;

@Field()
Expand All @@ -73,7 +73,7 @@ So far, using interfaces, you could only share field definitions with your objec
```typescript
import { Resolver, ResolveField, Parent, Info } from '@nestjs/graphql';

@Resolver(type => Character) // Reminder: Character is an interface
@Resolver((type) => Character) // Reminder: Character is an interface
export class CharacterInterfaceResolver {
@ResolveField(() => [Character])
friends(
Expand Down
4 changes: 2 additions & 2 deletions content/graphql/mutations.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The official [Apollo](https://www.apollographql.com/docs/graphql-tools/generate-
Let's add another method to the `AuthorResolver` used in the previous section (see [resolvers](/graphql/resolvers)).

```typescript
@Mutation(returns => Post)
@Mutation(() => Post)
async upvotePost(@Args({ name: 'postId', type: () => Int }) postId: number) {
return this.postsService.upvoteById({ id: postId });
}
Expand Down Expand Up @@ -44,7 +44,7 @@ export class UpvotePostInput {
We can then use this type in the resolver class:

```typescript
@Mutation(returns => Post)
@Mutation(() => Post)
async upvotePost(
@Args('upvotePostData') upvotePostData: UpvotePostInput,
) {}
Expand Down
34 changes: 17 additions & 17 deletions content/graphql/resolvers-map.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ At this point, we've defined the objects (type definitions) that can exist in ou

```typescript
@@filename(authors/authors.resolver)
@Resolver(of => Author)
@Resolver(() => Author)
export class AuthorsResolver {
constructor(
private authorsService: AuthorsService,
private postsService: PostsService,
) {}

@Query(returns => Author)
@Query(() => Author)
async author(@Args('id', { type: () => Int }) id: number) {
return this.authorsService.findOneById(id);
}
Expand Down Expand Up @@ -176,7 +176,7 @@ We can define multiple `@Query()` resolver functions (both within this class, an
In the above examples, the `@Query()` decorator generates a GraphQL schema query type name based on the method name. For example, consider the following construction from the example above:

```typescript
@Query(returns => Author)
@Query(() => Author)
async author(@Args('id', { type: () => Int }) id: number) {
return this.authorsService.findOneById(id);
}
Expand All @@ -196,19 +196,19 @@ Conventionally, we prefer to decouple these names; for example, we prefer to use

```typescript
@@filename(authors/authors.resolver)
@Resolver(of => Author)
@Resolver(() => Author)
export class AuthorsResolver {
constructor(
private authorsService: AuthorsService,
private postsService: PostsService,
) {}

@Query(returns => Author, { name: 'author' })
@Query(() => Author, { name: 'author' })
async getAuthor(@Args('id', { type: () => Int }) id: number) {
return this.authorsService.findOneById(id);
}

@ResolveField('posts', returns => [Post])
@ResolveField('posts', () => [Post])
async getPosts(@Parent() author: Author) {
const { id } = author;
return this.postsService.findAll({ authorId: id });
Expand Down Expand Up @@ -246,7 +246,7 @@ Usually your `@Args()` decorator will be simple, and not require an object argum
In the `getAuthor()` case, the `number` type is used, which presents a challenge. The `number` TypeScript type doesn't give us enough information about the expected GraphQL representation (e.g., `Int` vs. `Float`). Thus we have to **explicitly** pass the type reference. We do that by passing a second argument to the `Args()` decorator, containing argument options, as shown below:

```typescript
@Query(returns => Author, { name: 'author' })
@Query(() => Author, { name: 'author' })
async getAuthor(@Args('id', { type: () => Int }) id: number) {
return this.authorsService.findOneById(id);
}
Expand Down Expand Up @@ -316,10 +316,10 @@ Base `@ArgsType()` class:
```typescript
@ArgsType()
class PaginationArgs {
@Field((type) => Int)
@Field(() => Int)
offset: number = 0;

@Field((type) => Int)
@Field(() => Int)
limit: number = 10;
}
```
Expand All @@ -343,7 +343,7 @@ The same approach can be taken with `@ObjectType()` objects. Define generic prop
```typescript
@ObjectType()
class Character {
@Field((type) => Int)
@Field(() => Int)
id: number;

@Field()
Expand All @@ -367,7 +367,7 @@ You can use inheritance with a resolver as well. You can ensure type safety by c
function BaseResolver<T extends Type<unknown>>(classRef: T): any {
@Resolver({ isAbstract: true })
abstract class BaseResolverHost {
@Query((type) => [classRef], { name: `findAll${classRef.name}` })
@Query(() => [classRef], { name: `findAll${classRef.name}` })
async findAll(): Promise<T[]> {
return [];
}
Expand All @@ -385,7 +385,7 @@ Note the following:
Here's how you could generate a concrete sub-class of the `BaseResolver`:

```typescript
@Resolver((of) => Recipe)
@Resolver(() => Recipe)
export class RecipesResolver extends BaseResolver(Recipe) {
constructor(private recipesService: RecipesService) {
super();
Expand Down Expand Up @@ -424,22 +424,22 @@ export interface IPaginatedType<T> {
export function Paginated<T>(classRef: Type<T>): Type<IPaginatedType<T>> {
@ObjectType(`${classRef.name}Edge`)
abstract class EdgeType {
@Field((type) => String)
@Field(() => String)
cursor: string;

@Field((type) => classRef)
@Field(() => classRef)
node: T;
}

@ObjectType({ isAbstract: true })
abstract class PaginatedType implements IPaginatedType<T> {
@Field((type) => [EdgeType], { nullable: true })
@Field(() => [EdgeType], { nullable: true })
edges: EdgeType[];

@Field((type) => [classRef], { nullable: true })
@Field(() => [classRef], { nullable: true })
nodes: T[];

@Field((type) => Int)
@Field(() => Int)
totalCount: number;

@Field()
Expand Down
Loading

0 comments on commit a89b34c

Please sign in to comment.