Performance: Queries and mutations
MEDIUM IMPACT
This concept affects the speed of data fetching and updating on the client side, impacting how fast the UI responds and renders new data.
import { Resolver, Query, Mutation, Args } from '@nestjs/graphql'; @Resolver() export class UserResolver { @Query(() => [User]) async users(@Args('limit', { nullable: true }) limit?: number, @Args('offset', { nullable: true }) offset?: number) { // Fetch users with pagination return this.userService.findPaginated(limit ?? 10, offset ?? 0); } @Mutation(() => User) async updateUser(@Args('id') id: string, @Args('input') input: UpdateUserInput) { // Validate input and batch updates if possible return this.userService.update(id, input); } }
import { Resolver, Query, Mutation, Args } from '@nestjs/graphql'; @Resolver() export class UserResolver { @Query(() => [User]) async users() { // Fetch all users without pagination or filtering return this.userService.findAll(); } @Mutation(() => User) async updateUser(@Args('id') id: string, @Args('input') input: UpdateUserInput) { // Update user and return updated user return this.userService.update(id, input); } }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Fetch all data without pagination | High (large data causes many DOM nodes) | Multiple (each data update triggers reflow) | High (large repaint area) | [X] Bad |
| Fetch data with pagination and filtering | Low (smaller data set) | Single or few (batched updates) | Low (smaller repaint area) | [OK] Good |