Skip to content

feat: introduce graphql linting#2856

Merged
tatomyr merged 25 commits into
mainfrom
feat/lint-graphql
Jul 2, 2026
Merged

feat: introduce graphql linting#2856
tatomyr merged 25 commits into
mainfrom
feat/lint-graphql

Conversation

@tatomyr

@tatomyr tatomyr commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

What/Why/How?

Added experimental graphql linting.

Reference

Testing

Tests passed here: https://github.com/Redocly/redocly/pull/24589

Screenshots (optional)

Check yourself

  • This PR follows the contributing guide
  • All new/updated code is covered by tests
  • Core code changed? - Tested with other Redocly products (internal contributions only)
  • New package installed? - Tested in different environments (browser/node)
  • Documentation update has been considered

Security

  • The security impact of the change has been considered
  • Code follows company security practices and guidelines

Note

Medium Risk
Touches core lintDocument and document resolution paths but gates behavior on file extension; new dependency and a parallel rule engine increase surface area while marked experimental.

Overview
Adds experimental lint support for GraphQL SDL (.graphql / .gql) alongside OpenAPI-family formats. redocly lint detects GraphQL by file extension, keeps SDL as raw text instead of YAML parsing, and runs a dedicated pipeline built on the graphql package (parse → AST visitors).

Built-in GraphQL rules include struct (syntax + validateSchema), no-unused-types, and type-description, wired through graphqlRules in presets (recommended, all, etc.) and the default plugin. Configurable rule/* assertions work against GraphQL AST kinds (ObjectTypeDefinition, FieldDefinition, …) via a new GraphQL assertions visitor, with redocly.yaml subject enums extended accordingly.

Config/plugins gain a graphql rules bucket; common ref-resolution rules like no-unresolved-refs are omitted from the GraphQL ruleset. Bundling explicitly skips GraphQL. Docs add a GraphQL lint guide and update lint / configurable-rules pages; enum validation errors for huge subject lists now link to documentation instead of dumping all values.

Reviewed by Cursor Bugbot for commit e4237dc. Bugbot is set up for automated code reviews on this repo. Configure here.

@changeset-bot

changeset-bot Bot commented Jun 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e4237dc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@redocly/openapi-core Minor
@redocly/cli Minor
@redocly/respect-core Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@tatomyr tatomyr self-assigned this Jun 5, 2026
@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 81.78% (🎯 81%) 7651 / 9355
🔵 Statements 81.13% (🎯 80%) 7963 / 9814
🔵 Functions 84.95% (🎯 84%) 1536 / 1808
🔵 Branches 73.32% (🎯 73%) 5158 / 7034
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/cli/src/utils/miscellaneous.ts 61.67% 58.2% 78.04% 60.97% 75, 140, 197-247, 273-274, 284-285, 300, 304, 307, 313, 317-320, 328-361, 372, 397, 406, 414-452, 567, 576
packages/core/src/detect-spec.ts 91.66% 93.24% 100% 91.66% 20-23, 29
packages/core/src/lint.ts 91.89% 85.71% 100% 91.66% 107-118, 141
packages/core/src/oas-types.ts 100% 100% 100% 100%
packages/core/src/resolve.ts 95.34% 94.69% 100% 95.2% 94, 141, 285, 460-468
packages/core/src/bundle/bundle-visitor.ts 72.72% 68.42% 100% 72.72% 37, 41-49, 60-64, 71, 80, 88, 93-118, 188-200, 217-218, 236-237, 251-252, 285
packages/core/src/config/all.ts 100% 100% 100% 100%
packages/core/src/config/builtIn.ts 100% 100% 100% 100%
packages/core/src/config/config-resolvers.ts 76.21% 60.98% 94.11% 77.01% 73, 101-104, 154, 193, 201, 257, 268, 277, 290, 300, 303-307, 312-321, 345-347, 357, 360, 363, 366, 369, 372, 385-387, 391, 397, 400, 403-406, 409-412, 415-418, 432-434, 441, 444, 447, 450, 453, 456, 481-483, 488-494
packages/core/src/config/config.ts 61.92% 62.5% 70.45% 62.28% 185-215, 241, 245, 249-255, 258, 262-271, 303, 321-341, 395-403, 436-466
packages/core/src/config/minimal.ts 100% 100% 100% 100%
packages/core/src/config/recommended-strict.ts 100% 100% 100% 100%
packages/core/src/config/recommended.ts 100% 100% 100% 100%
packages/core/src/config/rules.ts 100% 100% 100% 100%
packages/core/src/config/spec.ts 100% 100% 100% 100%
packages/core/src/config/utils.ts 97.59% 81.81% 100% 98.78% 35, 87-89
packages/core/src/graphql/assertions.ts 95.77% 90.9% 100% 98.33% 49, 52, 73-75
packages/core/src/graphql/detect-graphql.ts 100% 100% 100% 100%
packages/core/src/graphql/lint-graphql.ts 95.65% 60% 100% 95.45% 44
packages/core/src/graphql/node-kinds.ts 100% 100% 100% 100%
packages/core/src/graphql/visitor.ts 91.66% 81.48% 100% 100% 51, 108
packages/core/src/rules/utils.ts 92% 88.7% 100% 91.3% 65, 99, 109-113, 129, 140-144, 237
packages/core/src/rules/common/struct.ts 97.22% 91.78% 100% 97.01% 79-83, 190-194
packages/core/src/rules/common/assertions/utils.ts 84% 65.51% 69.23% 88.29% 50, 54, 58, 83-85, 89-91, 142, 163-165, 172, 184-192, 252, 272-273, 289
packages/core/src/rules/graphql/index.ts 100% 100% 100% 100%
packages/core/src/rules/graphql/no-unused-types.ts 100% 73.07% 100% 100%
packages/core/src/rules/graphql/struct.ts 66.66% 33.33% 75% 66.66% 18, 27, 32-42
packages/core/src/rules/graphql/type-description.ts 100% 100% 100% 100%
packages/core/src/types/redocly-yaml.ts 92.92% 84.9% 100% 92.7% 415, 447, 453, 497-504, 506, 665-670, 673-678
Generated in workflow #10558 for commit e4237dc by the Vitest Coverage Report Action

@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Performance Benchmark (Lower is Faster)

CLI Version Bundle Lint Check Config
cli-latest ▓ 1.01x ± 0.01 ▓ 1.00x (Fastest) ▓ 1.00x (Fastest)
cli-next ▓ 1.00x (Fastest) ▓ 1.01x ± 0.01 ▓ 1.02x ± 0.01

Comment thread packages/core/src/rules/graphql/type-pascal-case.ts Outdated
Comment thread .changeset/graphql-sdl-linting.md Outdated
"operation-summary": "error",
},
"graphql": {
"no-empty-servers": "error",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are unused rules propagated from the root rules config section.

Comment thread packages/core/src/config/config.ts Outdated
Comment thread packages/core/src/lint-graphql.ts Outdated
@tatomyr tatomyr requested a review from RomanHotsiy June 12, 2026 08:07
@tatomyr tatomyr force-pushed the feat/lint-graphql branch from 7f3750d to 7bd109c Compare June 12, 2026 08:15
@tatomyr tatomyr marked this pull request as ready for review June 12, 2026 08:15
@tatomyr tatomyr requested review from a team as code owners June 12, 2026 08:16
Comment thread packages/core/src/rules/graphql/no-unused-types.ts
Comment thread packages/core/src/graphql/visitor.ts
Comment thread packages/core/src/config/config.ts
Comment thread docs/@v2/guides/lint-graphql.md Outdated
Comment thread docs/@v2/guides/lint-graphql.md Outdated
Comment thread docs/@v2/guides/lint-graphql.md Outdated
Comment thread docs/@v2/guides/lint-graphql.md Outdated
Comment thread docs/@v2/guides/lint-graphql.md Outdated
Comment thread docs/@v2/guides/lint-graphql.md Outdated
Comment thread docs/@v2/guides/lint-graphql.md Outdated
Comment thread docs/@v2/guides/lint-graphql.md Outdated
Comment thread docs/@v2/guides/lint-graphql.md Outdated
Comment thread docs/@v2/guides/lint-graphql.md Outdated
@tatomyr tatomyr force-pushed the feat/lint-graphql branch 2 times, most recently from 8723a0d to 73e2aff Compare June 16, 2026 08:18
Comment thread packages/core/src/graphql/assertions.ts
Comment thread packages/core/src/graphql/lint-graphql.ts
@tatomyr tatomyr force-pushed the feat/lint-graphql branch from 73e2aff to 6bdd8fe Compare June 16, 2026 14:35
Comment thread docs/@v2/guides/lint-graphql.md Outdated
Comment thread packages/core/src/graphql/visitor.ts
Comment thread packages/cli/package.json Outdated
Comment thread packages/core/src/config/config.ts
@tatomyr tatomyr force-pushed the feat/lint-graphql branch from 2b29c2e to c580a1b Compare June 17, 2026 06:10
Comment thread packages/core/src/graphql/lint-graphql.ts
Comment thread packages/core/src/lint.ts

// GraphQL SDL is not a JSON/YAML tree, so it runs through a separate engine.
if (isGraphqlRef(document.source.absoluteRef)) {
return lintGraphqlDocument({ document, config });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, that we can add dynamic imports for the GraphQL in the lint command, because now we have esbuild and chunks, so the dynamic import should go to the separate chunk. It should decrease the influence of the GraphQL on the performance.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Comment thread packages/core/src/types/redocly-yaml.ts Outdated
@tatomyr tatomyr force-pushed the feat/lint-graphql branch from b69ae8e to 9c8e4ce Compare June 22, 2026 07:05
@tatomyr tatomyr marked this pull request as draft June 22, 2026 07:08

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 9c8e4ce. Configure here.

Comment thread packages/core/src/graphql/lint-graphql.ts
@tatomyr tatomyr force-pushed the feat/lint-graphql branch from 64dd060 to c94d2b8 Compare June 25, 2026 16:10
@tatomyr tatomyr requested a review from AlbinaBlazhko17 July 2, 2026 16:58
@tatomyr tatomyr force-pushed the feat/lint-graphql branch from 964cf73 to e4237dc Compare July 2, 2026 17:05
@tatomyr tatomyr merged commit 1710d61 into main Jul 2, 2026
46 of 47 checks passed
@tatomyr tatomyr deleted the feat/lint-graphql branch July 2, 2026 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

snapshot Create experimental release PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants