Performance: Code-first approach
This affects the server-side schema generation and initial API response time during GraphQL schema building.
import { GraphQLModule } from '@nestjs/graphql'; GraphQLModule.forRoot({ autoSchemaFile: 'schema.gql', });
import { GraphQLModule } from '@nestjs/graphql'; GraphQLModule.forRoot({ autoSchemaFile: false, typePaths: ['./**/*.graphql'], });
| Pattern | Server Startup Delay | Runtime Parsing | API Response Impact | Verdict |
|---|---|---|---|---|
| Schema-first (parsing .graphql files) | High (50-100ms) | Yes | Slightly slower | [X] Bad |
| Code-first (autoSchemaFile generation) | Medium (startup) | No | Faster | [OK] Good |
hello()?
import { Query, Resolver } from '@nestjs/graphql';
@Resolver()
export class HelloResolver {
@Query(() => String)
hello() {
return 'Hello, NestJS!';
}
}import { Query, Resolver } from '@nestjs/graphql';
@Resolver()
export class SampleResolver {
@Query()
sample() {
return 123;
}
}import { Field, ObjectType } from '@nestjs/graphql';
@ObjectType()
export class User {
@Field(() => String, { nullable: true })
nickname?: string;
}
What does this code do?Pass the test and this pattern moves unknown