{"id":"197a4fba09917efe","repo":"nestjs/nest","slug":"id-197a4f","errorCode":null,"errorMessage":"${id}","messagePattern":"\\$\\{id\\}","errorType":"http","errorClass":"NotFoundException","httpStatus":404,"severity":"error","filePath":"sample/23-graphql-code-first/src/recipes/recipes.resolver.ts","lineNumber":19,"sourceCode":"import { NotFoundException } from '@nestjs/common';\nimport { Args, Mutation, Query, Resolver, Subscription } from '@nestjs/graphql';\nimport { PubSub } from 'graphql-subscriptions';\nimport { NewRecipeInput } from './dto/new-recipe.input';\nimport { RecipesArgs } from './dto/recipes.args';\nimport { Recipe } from './models/recipe.model';\nimport { RecipesService } from './recipes.service';\n\nconst pubSub = new PubSub();\n\n@Resolver(of => Recipe)\nexport class RecipesResolver {\n  constructor(private readonly recipesService: RecipesService) {}\n\n  @Query(returns => Recipe)\n  async recipe(@Args('id') id: string): Promise<Recipe> {\n    const recipe = await this.recipesService.findOneById(id);\n    if (!recipe) {\n      throw new NotFoundException(id);\n    }\n    return recipe;\n  }\n\n  @Query(returns => [Recipe])\n  recipes(@Args() recipesArgs: RecipesArgs): Promise<Recipe[]> {\n    return this.recipesService.findAll(recipesArgs);\n  }\n\n  @Mutation(returns => Recipe)\n  async addRecipe(\n    @Args('newRecipeData') newRecipeData: NewRecipeInput,\n  ): Promise<Recipe> {\n    const recipe = await this.recipesService.create(newRecipeData);\n    pubSub.publish('recipeAdded', { recipeAdded: recipe });\n    return recipe;\n  }\n","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/nestjs/nest/blob/6ec0e2783d15290732447f304d8549b591b9749e/sample/23-graphql-code-first/src/recipes/recipes.resolver.ts#L1-L37","documentation":"NestJS NotFoundException thrown at sample/23-graphql-code-first/src/recipes/recipes.resolver.ts:19 inside the `recipe(id)` @Query resolver when RecipesService.findOneById(id) returns a falsy value. Because it is constructed as `new NotFoundException(id)`, the raw id string becomes the error message — hence the message is literally `${id}`. It signals that no recipe with the requested identifier exists in the in-memory store.","triggerScenarios":"GraphQL query `query { recipe(id: \"<id-not-in-store>\") { id title } }` — findOneById returns null/undefined, so the resolver throws 404. Also fires for malformed ids the service treats as absent (e.g., wrong UUID format).","commonSituations":"Client holds a stale id after removeRecipe was called; typo/hard-coded id in a test; in-memory sample store reset on HMR/restart so previously valid ids vanish; id format mismatch (service expects a different identifier scheme than the client sends).","solutions":["Verify the id against the store before assuming the client is wrong — check RecipesService.findOneById's data source.","Return null instead of throwing if your GraphQL schema declares the field as nullable, so the client gets partial data rather than an error.","Improve the message: pass a human-readable string (`new NotFoundException(`Recipe ${id} not found`)`) instead of the bare id.","On the client, treat the 404 as data and surface a friendly 'not found' UI."],"exampleFix":"// before\nconst recipe = await this.recipesService.findOneById(id);\nif (!recipe) {\n  throw new NotFoundException(id);\n}\n\n// after\nconst recipe = await this.recipesService.findOneById(id);\nif (!recipe) {\n  throw new NotFoundException(`Recipe with id \"${id}\" not found`);\n}","handlingStrategy":"validation","validationCode":"// Before resolving, check the store directly (or a lightweight exists() method).\nconst exists = await recipesService.existsById(id);\nif (!exists) {\n  // render 'not found' UI without triggering the throwing resolver\n}","typeGuard":"function isRecipe(v: unknown): v is Recipe {\n  return typeof v === 'object' && v !== null\n    && typeof (v as any).id === 'string'\n    && typeof (v as any).title === 'string';\n}","tryCatchPattern":"// Apollo Client\ntry {\n  const { data, errors } = await client.query({ query: RECIPE, variables: { id } });\n} catch (e) {\n  const notFound = e.graphQLErrors?.some(\n    (g: any) => g.extensions?.code === 'NOT_FOUND' || /not found/i.test(g.message),\n  );\n  if (notFound) navigate('/404');\n}","preventionTips":["Use the list query to obtain valid ids before looking one up.","Make the schema return type nullable (Recipe | null) and return null instead of throwing for expected absence.","Pass a descriptive message to NotFoundException to ease client-side matching.","Seed sample data before running demos/tests that look up by id."],"tags":["graphql","nestjs","not-found","resolver","recipes"],"analyzedSha":"6ec0e2783d15290732447f304d8549b591b9749e","analyzedAt":"2026-08-03T17:42:23.673Z","schemaVersion":2}