From a89b34ccf5824c8dc2e1011a699e748073aa1c9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20My=C5=9Bliwiec?= Date: Thu, 17 Oct 2024 12:43:14 +0200 Subject: [PATCH] style(lint): remove unused params --- content/graphql/directives.md | 2 +- content/graphql/federation.md | 60 ++++++++++++++--------------- content/graphql/interfaces.md | 6 +-- content/graphql/mutations.md | 4 +- content/graphql/resolvers-map.md | 34 ++++++++-------- content/graphql/scalars.md | 14 +++---- content/graphql/subscriptions.md | 28 +++++++------- content/graphql/unions-and-enums.md | 2 +- content/recipes/passport.md | 2 +- 9 files changed, 76 insertions(+), 76 deletions(-) diff --git a/content/graphql/directives.md b/content/graphql/directives.md index 0433e5065e..331c1eb7d5 100644 --- a/content/graphql/directives.md +++ b/content/graphql/directives.md @@ -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); } diff --git a/content/graphql/federation.md b/content/graphql/federation.md index bf80e631be..bf02202c4e 100644 --- a/content/graphql/federation.md +++ b/content/graphql/federation.md @@ -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() @@ -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); } @@ -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[]; } ``` @@ -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); } @@ -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; } ``` @@ -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 }; } @@ -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() @@ -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); } @@ -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[]; } ``` @@ -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); } @@ -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; } ``` @@ -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 }; } @@ -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[]; } ``` diff --git a/content/graphql/interfaces.md b/content/graphql/interfaces.md index c0a8107062..46298a50e0 100644 --- a/content/graphql/interfaces.md +++ b/content/graphql/interfaces.md @@ -11,7 +11,7 @@ import { Field, ID, InterfaceType } from '@nestjs/graphql'; @InterfaceType() export abstract class Character { - @Field((type) => ID) + @Field(() => ID) id: string; @Field() @@ -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() @@ -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( diff --git a/content/graphql/mutations.md b/content/graphql/mutations.md index 3a79b2bcba..b3e0af11b3 100644 --- a/content/graphql/mutations.md +++ b/content/graphql/mutations.md @@ -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 }); } @@ -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, ) {} diff --git a/content/graphql/resolvers-map.md b/content/graphql/resolvers-map.md index e2ec5f4c67..7c79579cb1 100644 --- a/content/graphql/resolvers-map.md +++ b/content/graphql/resolvers-map.md @@ -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); } @@ -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); } @@ -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 }); @@ -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); } @@ -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; } ``` @@ -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() @@ -367,7 +367,7 @@ You can use inheritance with a resolver as well. You can ensure type safety by c function BaseResolver>(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 { return []; } @@ -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(); @@ -424,22 +424,22 @@ export interface IPaginatedType { export function Paginated(classRef: Type): Type> { @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 { - @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() diff --git a/content/graphql/scalars.md b/content/graphql/scalars.md index 267fdd020b..d3f22c25b6 100644 --- a/content/graphql/scalars.md +++ b/content/graphql/scalars.md @@ -42,7 +42,7 @@ To create a custom implementation for the `Date` scalar, simply create a new cla import { Scalar, CustomScalar } from '@nestjs/graphql'; import { Kind, ValueNode } from 'graphql'; -@Scalar('Date', (type) => Date) +@Scalar('Date', () => Date) export class DateScalar implements CustomScalar { description = 'Date custom scalar type'; @@ -107,7 +107,7 @@ export class AppModule {} Now we can use the `JSON` type in our classes. ```typescript -@Field((type) => GraphQLJSON) +@Field(() => GraphQLJSON) info: JSON; ``` @@ -121,8 +121,8 @@ To define a custom scalar, create a new `GraphQLScalarType` instance. We'll crea const regex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i; function validate(uuid: unknown): string | never { - if (typeof uuid !== "string" || !regex.test(uuid)) { - throw new Error("invalid uuid"); + if (typeof uuid !== 'string' || !regex.test(uuid)) { + throw new Error('invalid uuid'); } return uuid; } @@ -132,8 +132,8 @@ export const CustomUuidScalar = new GraphQLScalarType({ description: 'A simple UUID parser', serialize: (value) => validate(value), parseValue: (value) => validate(value), - parseLiteral: (ast) => validate(ast.value) -}) + parseLiteral: (ast) => validate(ast.value), +}); ``` We pass a custom resolver to the `forRoot()` method: @@ -152,7 +152,7 @@ export class AppModule {} Now we can use the `UUID` type in our classes. ```typescript -@Field((type) => CustomUuidScalar) +@Field(() => CustomUuidScalar) uuid: string; ``` diff --git a/content/graphql/subscriptions.md b/content/graphql/subscriptions.md index 25513b4781..6fe8cbc296 100644 --- a/content/graphql/subscriptions.md +++ b/content/graphql/subscriptions.md @@ -39,10 +39,10 @@ The following subscription handler takes care of **subscribing** to an event by ```typescript const pubSub = new PubSub(); -@Resolver((of) => Author) +@Resolver(() => Author) export class AuthorResolver { // ... - @Subscription((returns) => Comment) + @Subscription(() => Comment) commentAdded() { return pubSub.asyncIterator('commentAdded'); } @@ -64,7 +64,7 @@ type Subscription { Note that subscriptions, by definition, return an object with a single top level property whose key is the name of the subscription. This name is either inherited from the name of the subscription handler method (i.e., `commentAdded` above), or is provided explicitly by passing an option with the key `name` as the second argument to the `@Subscription()` decorator, as shown below. ```typescript -@Subscription(returns => Comment, { +@Subscription(() => Comment, { name: 'commentAdded', }) subscribeToCommentAdded() { @@ -80,7 +80,7 @@ Now, to publish the event, we use the `PubSub#publish` method. This is often use ```typescript @@filename(posts/posts.resolver) -@Mutation(returns => Comment) +@Mutation(() => Comment) async addComment( @Args('postId', { type: () => Int }) postId: number, @Args('comment', { type: () => Comment }) comment: CommentInput, @@ -106,7 +106,7 @@ This tells us that the subscription must return an object with a top-level prope To filter out specific events, set the `filter` property to a filter function. This function acts similar to the function passed to an array `filter`. It takes two arguments: `payload` containing the event payload (as sent by the event publisher), and `variables` taking any arguments passed in during the subscription request. It returns a boolean determining whether this event should be published to client listeners. ```typescript -@Subscription(returns => Comment, { +@Subscription(() => Comment, { filter: (payload, variables) => payload.commentAdded.title === variables.title, }) @@ -120,7 +120,7 @@ commentAdded(@Args('title') title: string) { To mutate the published event payload, set the `resolve` property to a function. The function receives the event payload (as sent by the event publisher) and returns the appropriate value. ```typescript -@Subscription(returns => Comment, { +@Subscription(() => Comment, { resolve: value => value, }) commentAdded() { @@ -133,7 +133,7 @@ commentAdded() { If you need to access injected providers (e.g., use an external service to validate the data), use the following construction. ```typescript -@Subscription(returns => Comment, { +@Subscription(() => Comment, { resolve(this: AuthorResolver, value) { // "this" refers to an instance of "AuthorResolver" return value; @@ -147,7 +147,7 @@ commentAdded() { The same construction works with filters: ```typescript -@Subscription(returns => Comment, { +@Subscription(() => Comment, { filter(this: AuthorResolver, payload, variables) { // "this" refers to an instance of "AuthorResolver" return payload.commentAdded.title === variables.title; @@ -372,10 +372,10 @@ To create a subscription using the code first approach, we use the `@Subscriptio The following subscription handler takes care of **subscribing** to an event by calling `PubSub#asyncIterator`. This method takes a single argument, the `triggerName`, which corresponds to an event topic name. ```typescript -@Resolver((of) => Author) +@Resolver(() => Author) export class AuthorResolver { // ... - @Subscription((returns) => Comment) + @Subscription(() => Comment) commentAdded(@Context('pubsub') pubSub: PubSub) { return pubSub.subscribe('commentAdded'); } @@ -397,7 +397,7 @@ type Subscription { Note that subscriptions, by definition, return an object with a single top level property whose key is the name of the subscription. This name is either inherited from the name of the subscription handler method (i.e., `commentAdded` above), or is provided explicitly by passing an option with the key `name` as the second argument to the `@Subscription()` decorator, as shown below. ```typescript -@Subscription(returns => Comment, { +@Subscription(() => Comment, { name: 'commentAdded', }) subscribeToCommentAdded(@Context('pubsub') pubSub: PubSub) { @@ -413,7 +413,7 @@ Now, to publish the event, we use the `PubSub#publish` method. This is often use ```typescript @@filename(posts/posts.resolver) -@Mutation(returns => Comment) +@Mutation(() => Comment) async addComment( @Args('postId', { type: () => Int }) postId: number, @Args('comment', { type: () => Comment }) comment: CommentInput, @@ -445,7 +445,7 @@ This tells us that the subscription must return an object with a top-level prope To filter out specific events, set the `filter` property to a filter function. This function acts similar to the function passed to an array `filter`. It takes two arguments: `payload` containing the event payload (as sent by the event publisher), and `variables` taking any arguments passed in during the subscription request. It returns a boolean determining whether this event should be published to client listeners. ```typescript -@Subscription(returns => Comment, { +@Subscription(() => Comment, { filter: (payload, variables) => payload.commentAdded.title === variables.title, }) @@ -457,7 +457,7 @@ commentAdded(@Args('title') title: string, @Context('pubsub') pubSub: PubSub) { If you need to access injected providers (e.g., use an external service to validate the data), use the following construction. ```typescript -@Subscription(returns => Comment, { +@Subscription(() => Comment, { filter(this: AuthorResolver, payload, variables) { // "this" refers to an instance of "AuthorResolver" return payload.commentAdded.title === variables.title; diff --git a/content/graphql/unions-and-enums.md b/content/graphql/unions-and-enums.md index 71e5c3db9a..3c8761641b 100644 --- a/content/graphql/unions-and-enums.md +++ b/content/graphql/unions-and-enums.md @@ -42,7 +42,7 @@ export const ResultUnion = createUnionType({ Now, we can reference the `ResultUnion` in our query: ```typescript -@Query(returns => [ResultUnion]) +@Query(() => [ResultUnion]) search(): Array { return [new Author(), new Book()]; } diff --git a/content/recipes/passport.md b/content/recipes/passport.md index 9a8804fa17..4e6ab3d51b 100644 --- a/content/recipes/passport.md +++ b/content/recipes/passport.md @@ -972,7 +972,7 @@ export const CurrentUser = createParamDecorator( To use above decorator in your resolver, be sure to include it as a parameter of your query or mutation: ```typescript -@Query(returns => User) +@Query(() => User) @UseGuards(GqlAuthGuard) whoAmI(@CurrentUser() user: User) { return this.usersService.findById(user.id);