Skip to content

fix(graphql): escape comment terminators in emitted descriptions - #4174

Merged
kamilmysliwiec merged 1 commit into
nestjs:masterfrom
thekhegay:escape-description-comment
Oct 23, 2026
Merged

kamilmysliwiec merged 1 commit into
nestjs:masterfrom
thekhegay:escape-description-comment

Conversation

@thekhegay

Copy link
Copy Markdown
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

With emitDescriptions: true (#4054) getDescriptionDocs puts description into /** */ comment as is. If description has */ in it, like cron expression or glob, comment ends right there and rest of descripton lands in generated file as code

type Query {
  """
  Runs on the cron schedule */5 * * * *.
  """
  jobs: [String!]!
}
export interface IQuery {
    /** Runs on the cron schedule */5 * * * *. */
    jobs(): string[] | Promise<string[]>;
}

Generator writes this file without any error, then tsc fails on it with TS1131: Property or signature expected and more syntax errors after it

What is the new behavior?

*/ inside description is escaped as *\/, same as graphql-codegen does in its transformComment. Example above becomes /** Runs on the cron schedule *\/5 * * * *. */ and file compiles. Descriptions without */ are emitted same as before

Added test to graphql-ast.explorer.spec.ts, it checks syntactic diagnostics of generated source file. On master it gets 10 diagnostics, with fix 0. Full @nestjs/graphql suite passes, 267 tests

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

With emitDescriptions enabled each description is copied into /** */
comment as is, so "*/" inside it (cron expression, glob like
src/**/*.ts) closes comment early and generated file does not compile.
Escape it as "*\/", same as graphql-codegen does
@kamilmysliwiec
kamilmysliwiec merged commit 0e3a5f3 into nestjs:master Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants