feat: introduce graphql linting#2856
Conversation
🦋 Changeset detectedLatest commit: 73e2aff The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
Performance Benchmark (Lower is Faster)
|
| '@redocly/cli': minor | ||
| --- | ||
|
|
||
| Added initial support for linting GraphQL SDL schema files (`.graphql` / `.gql`). |
There was a problem hiding this comment.
Let's mark it as experimental for now
| "operation-summary": "error", | ||
| }, | ||
| "graphql": { | ||
| "no-empty-servers": "error", |
There was a problem hiding this comment.
Those are unused rules propagated from the root rules config section.
| import type { Config } from './config/index.js'; | ||
| import { initRules } from './config/rules.js'; | ||
| import { isGraphqlRef } from './graphql/extensions.js'; | ||
| import { runGraphqlRules, type InitializedGraphqlRule } from './graphql/run.js'; |
There was a problem hiding this comment.
let's use dynamic import here so it won't load for everyone and slow them down
There was a problem hiding this comment.
I haven't noticed any perf degradation so far. Would you still like to have it imported dynamcally?
7f3750d to
7bd109c
Compare
94e4609 to
b2ce0d4
Compare
Co-authored-by: Jacek Łękawa <164185257+JLekawa@users.noreply.github.com>
8723a0d to
73e2aff
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 73e2aff. Configure here.
|
|
||
| function singleProperty(property: Assertion['subject']['property']): string | undefined { | ||
| return Array.isArray(property) ? property[0] : property; | ||
| } |
There was a problem hiding this comment.
Array property silently drops all but first element
Medium Severity
The singleProperty helper returns only the first element when property is an array, silently discarding the rest. Configurable rules support property as a string[], where assertions are meant to evaluate against each listed property. In the GraphQL adapter, a rule like property: [name, description] only ever checks name, and the description assertion is quietly skipped. This causes incomplete lint coverage without any warning to the user.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 73e2aff. Configure here.
| return [syntaxErrorToProblem(e, source)]; | ||
| } | ||
| throw e; | ||
| } |
There was a problem hiding this comment.
Syntax error path bypasses addProblemToIgnore processing
Low Severity
When a GraphQL parse error occurs, lintGraphqlDocument returns directly with the syntaxErrorToProblem result, bypassing the config.addProblemToIgnore call that all other problems go through on line 37. This is inconsistent with the normal flow and breaks the contract that all returned problems are processed through the ignore pipeline.
Reviewed by Cursor Bugbot for commit 73e2aff. Configure here.


What/Why/How?
Added experimental graphql linting.
Reference
Testing
Screenshots (optional)
Check yourself
Security
Note
Medium Risk
Introduces a new core lint path and
graphqldependency, but GraphQL files are gated by extension and do not alter existing OpenAPI/AsyncAPI lint behavior.Overview
Adds experimental lint support for GraphQL SDL (
.graphql/.gql) inredocly lint, documented in a new guide and linked from thelintcommand docs..graphql/.gqlfiles are detected by extension, kept as raw SDL during resolve (not YAML-parsed), and linted through a dedicated path that usesgraphqlto parse and walk the AST. OpenAPI-style walking and bundle$refhandling are skipped for these files.Configuration gains a
graphqlspec version andgraphqlRules(merged with sharedrulesexceptno-unresolved-refs). Built-in GraphQL rules includestruct(syntax + schema validity),no-unused-types, andtype-description, with severities wired into existing presets. Plugins may exposerules.graphql.Configurable
rule/*assertions now accept GraphQL AST kinds assubject.type(viaGraphqlAssertions), includingwherefiltering. Config lint suggests valid GraphQL kinds on typos and shortens invalidsubject.typeerrors with a documentation link.CLI ruleset-empty checks include GraphQL (and OpenRPC) rules. Minor struct enum validation messages link to docs when the allowed-value list is large.
Reviewed by Cursor Bugbot for commit 73e2aff. Bugbot is set up for automated code reviews on this repo. Configure here.