Performance: Schema-first approach
MEDIUM IMPACT
This approach impacts the initial server startup time by defining GraphQL schemas upfront.
import { GraphQLModule } from '@nestjs/graphql'; GraphQLModule.forRoot({ typePaths: ['./**/*.graphql'], }); // Schema is defined first in SDL file and loaded at startup
import { Resolver, Query } from '@nestjs/graphql'; @Resolver() export class UserResolver { @Query(() => String) hello() { return 'Hello World'; } } // No explicit schema file, schema generated from code at startup
| Pattern | Server Startup Time | Runtime Query Validation | Memory Usage | Verdict |
|---|---|---|---|---|
| Code-first (dynamic schema) | High (extra 100-200ms reflection) | Low (pre-built schema) | Higher (reflection metadata) | [X] Bad |
| Schema-first (predefined SDL) | Low (SDL parsing) | Low (schema preloaded) | Lower (cached schema) | [OK] Good |