Complete the code to define a GraphQL query in NestJS.
import { Query, Resolver } from '@nestjs/graphql'; @Resolver() export class SampleResolver { @[1]() getHello(): string { return 'Hello World!'; } }
The @Query() decorator defines a GraphQL query method in NestJS.
Complete the code to define a GraphQL mutation in NestJS.
import { Mutation, Resolver } from '@nestjs/graphql'; @Resolver() export class SampleResolver { @[1]() createItem(): string { return 'Item created'; } }
The @Mutation() decorator defines a GraphQL mutation method in NestJS.
Fix the error in the resolver method decorator to correctly define a query.
import { Query, Resolver } from '@nestjs/graphql'; @Resolver() export class SampleResolver { @[1]() fetchData(): string { return 'Data fetched'; } }
To define a query, the method must use the @Query() decorator.
Fill both blanks to define a mutation method with an argument in NestJS GraphQL.
import { Mutation, Resolver, Args } from '@nestjs/graphql'; @Resolver() export class SampleResolver { @[1]() addUser(@[2]('name') name: string): string { return `User ${name} added`; } }
The @Mutation() decorator defines the mutation, and @Args() extracts the argument.
Fill all three blanks to define a query method with an argument and return type in NestJS GraphQL.
import { Query, Resolver, Args } from '@nestjs/graphql'; @Resolver() export class SampleResolver { @[1]() getUser(@[2]('id') id: string): [3] { return `User with ID ${id}`; } }
The method is a query, so use @Query(). Arguments come from @Args(), and the return type is string.
