Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/graphql-sdl-linting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@redocly/openapi-core': minor
'@redocly/cli': minor
---

Added initial support for linting GraphQL SDL schema files (`.graphql` / `.gql`).
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions packages/cli/src/__tests__/fixtures/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const configFixture: Config = {
arazzo1: {},
overlay1: {},
openrpc1: {},
graphql: {},
},
preprocessors: {
oas2: {},
Expand All @@ -38,6 +39,7 @@ export const configFixture: Config = {
arazzo1: {},
overlay1: {},
openrpc1: {},
graphql: {},
},
plugins: [],
doNotResolveExamples: false,
Expand All @@ -51,6 +53,7 @@ export const configFixture: Config = {
arazzo1: {},
overlay1: {},
openrpc1: {},
graphql: {},
},
resolveIgnore: vi.fn(),
addProblemToIgnore: vi.fn(),
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ describe('checkIfRulesetExist', () => {
arazzo1: {},
overlay1: {},
openrpc1: {},
graphql: {},
};
expect(() => checkIfRulesetExist(rules)).toThrowError(
'⚠️ No rules were configured. Learn how to configure rules: https://redocly.com/docs/cli/rules/'
Expand All @@ -631,6 +632,7 @@ describe('checkIfRulesetExist', () => {
arazzo1: {},
overlay1: {},
openrpc1: {},
graphql: {},
};
checkIfRulesetExist(rules);
});
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/utils/miscellaneous.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,8 @@ export function checkIfRulesetExist(rules: typeof Config.prototype.rules) {
...rules.async3,
...rules.arazzo1,
...rules.overlay1,
...rules.openrpc1,
...rules.graphql,
};

if (isEmptyObject(ruleset)) {
Expand Down
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"ajv": "npm:@redocly/ajv@8.18.1",
"ajv-formats": "^3.0.1",
"colorette": "^1.2.0",
"graphql": "^16.9.0",
"js-levenshtein": "^1.1.6",
"js-yaml": "^4.1.0",
"picomatch": "^4.0.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ exports[`createConfigTypes > matches snapshot for the default config schema 1`]
"properties": {},
},
"graphql": "rootRedoclyConfigSchema.apis_additionalProperties.graphql",
"graphqlRules": "Rules",
"metadata": {
"type": "object",
},
Expand Down Expand Up @@ -301,6 +302,7 @@ exports[`createConfigTypes > matches snapshot for the default config schema 1`]
"name": "Extends",
"properties": {},
},
"graphqlRules": "Rules",
"oas2Decorators": "Decorators",
"oas2Preprocessors": "Preprocessors",
"oas2Rules": "Rules",
Expand Down Expand Up @@ -384,6 +386,7 @@ exports[`createConfigTypes > matches snapshot for the default config schema 1`]
"feedback": "rootRedoclyConfigSchema.feedback",
"footer": "rootRedoclyConfigSchema.footer",
"graphql": "rootRedoclyConfigSchema.graphql",
"graphqlRules": "Rules",
"i18n": "rootRedoclyConfigSchema.i18n",
"ignore": {
"items": {
Expand Down Expand Up @@ -942,6 +945,7 @@ exports[`createConfigTypes > matches snapshot for the default config schema 1`]
"name": "Extends",
"properties": {},
},
"graphqlRules": "Rules",
"name": {
"type": "string",
},
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/bundle/bundle-visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ export function mapTypeToComponent(typeName: string, version: SpecMajorVersion)
default:
return null;
}
case 'graphql':
// GraphQL SDL is never bundled/$ref-resolved.
return null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ exports[`resolveConfig > should ignore minimal from the root and read local file
"tags-alphabetical": "off",
},
"decorators": {},
"graphqlRules": {
"type-description": "warn",
"type-pascal-case": "warn",
},
"oas2Decorators": {},
"oas2Preprocessors": {},
"oas2Rules": {
Expand Down Expand Up @@ -448,6 +452,10 @@ exports[`resolveConfig > should resolve extends with local file config which con
"tags-alphabetical": "off",
},
"decorators": {},
"graphqlRules": {
"type-description": "warn",
"type-pascal-case": "warn",
},
"oas2Decorators": {},
"oas2Preprocessors": {},
"oas2Rules": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Config {
"arazzo1": {},
"async2": {},
"async3": {},
"graphql": {},
"oas2": {},
"oas3_0": {},
"oas3_1": {},
Expand All @@ -36,6 +37,7 @@ Config {
"arazzo1": {},
"async2": {},
"async3": {},
"graphql": {},
"oas2": {},
"oas3_0": {},
"oas3_1": {},
Expand Down Expand Up @@ -64,6 +66,10 @@ Config {
"no-empty-servers": "error",
"operation-summary": "error",
},
"graphql": {
"no-empty-servers": "error",
"operation-summary": "error",
},
"oas2": {
"no-empty-servers": "error",
"operation-summary": "error",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Config {
"arazzo1": {},
"async2": {},
"async3": {},
"graphql": {},
"oas2": {},
"oas3_0": {},
"oas3_1": {},
Expand All @@ -25,6 +26,7 @@ Config {
"arazzo1": {},
"async2": {},
"async3": {},
"graphql": {},
"oas2": {},
"oas3_0": {},
"oas3_1": {},
Expand All @@ -51,6 +53,7 @@ Config {
"async3Preprocessors": {},
"async3Rules": {},
"decorators": {},
"graphqlRules": {},
"oas2Decorators": {},
"oas2Preprocessors": {},
"oas2Rules": {},
Expand Down Expand Up @@ -158,6 +161,22 @@ Config {
"no-empty-servers": "error",
"operation-summary": "error",
},
"graphql": {
"assertions": [
{
"assertionId": "rule/test",
"assertions": {
"defined": true,
},
"subject": {
"property": "x-test",
"type": "Operation",
},
},
],
"no-empty-servers": "error",
"operation-summary": "error",
},
"oas2": {
"assertions": [
{
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/config/__tests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe('Config.forAlias', () => {
"arazzo1": {},
"async2": {},
"async3": {},
"graphql": {},
"oas2": {},
"oas3_0": {},
"oas3_1": {},
Expand Down Expand Up @@ -75,6 +76,7 @@ describe('Config.forAlias', () => {
"arazzo1": {},
"async2": {},
"async3": {},
"graphql": {},
"oas2": {},
"oas3_0": {},
"oas3_1": {},
Expand All @@ -99,6 +101,7 @@ describe('Config.forAlias', () => {
"async3Preprocessors": {},
"async3Rules": {},
"decorators": {},
"graphqlRules": {},
"oas2Decorators": {},
"oas2Preprocessors": {},
"oas2Rules": {},
Expand Down Expand Up @@ -144,6 +147,10 @@ describe('Config.forAlias', () => {
"no-empty-servers": "error",
"operation-summary": "warn",
},
"graphql": {
"no-empty-servers": "error",
"operation-summary": "warn",
},
"oas2": {
"no-empty-servers": "error",
"operation-summary": "warn",
Expand Down
24 changes: 24 additions & 0 deletions packages/core/src/config/__tests__/load.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ describe('loadConfig', () => {
"tags-alphabetical": "off",
},
"decorators": {},
"graphqlRules": {
"type-description": "off",
"type-pascal-case": "off",
},
"name": "Baseline",
"oas2Decorators": {},
"oas2Preprocessors": {},
Expand Down Expand Up @@ -508,6 +512,10 @@ describe('loadConfig', () => {
"tags-alphabetical": "off",
},
"decorators": {},
"graphqlRules": {
"type-description": "warn",
"type-pascal-case": "warn",
},
"name": "Silver",
"oas2Decorators": {},
"oas2Preprocessors": {},
Expand Down Expand Up @@ -837,6 +845,10 @@ describe('loadConfig', () => {
"tags-alphabetical": "off",
},
"decorators": {},
"graphqlRules": {
"type-description": "off",
"type-pascal-case": "off",
},
"name": "Gold",
"oas2Decorators": {},
"oas2Preprocessors": {},
Expand Down Expand Up @@ -1250,6 +1262,10 @@ describe('loadConfig', () => {
"tags-alphabetical": "off",
},
"decorators": {},
"graphqlRules": {
"type-description": "off",
"type-pascal-case": "off",
},
"name": "Baseline",
"oas2Decorators": {},
"oas2Preprocessors": {},
Expand Down Expand Up @@ -1574,6 +1590,10 @@ describe('loadConfig', () => {
"tags-alphabetical": "off",
},
"decorators": {},
"graphqlRules": {
"type-description": "warn",
"type-pascal-case": "warn",
},
"name": "Silver",
"oas2Decorators": {},
"oas2Preprocessors": {},
Expand Down Expand Up @@ -1903,6 +1923,10 @@ describe('loadConfig', () => {
"tags-alphabetical": "off",
},
"decorators": {},
"graphqlRules": {
"type-description": "off",
"type-pascal-case": "off",
},
"name": "Gold",
"oas2Decorators": {},
"oas2Preprocessors": {},
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/config/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ const all: RawGovernanceConfig<'built-in'> = {
'spec-no-duplicated-method-params': 'error',
'spec-no-required-params-after-optional': 'error',
},
graphqlRules: {
'type-description': 'error',
'type-pascal-case': 'error',
},
};

export default all;
2 changes: 2 additions & 0 deletions packages/core/src/config/builtIn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
rules as async3Rules,
preprocessors as async3Preprocessors,
} from '../rules/async3/index.js';
import { rules as graphqlRules } from '../rules/graphql/index.js';
import { rules as oas2Rules, preprocessors as oas2Preprocessors } from '../rules/oas2/index.js';
import { rules as oas3Rules, preprocessors as oas3Preprocessors } from '../rules/oas3/index.js';
import {
Expand Down Expand Up @@ -52,6 +53,7 @@ export const defaultPlugin: Plugin<'built-in'> = {
arazzo1: arazzo1Rules,
overlay1: overlay1Rules,
openrpc1: openrpc1Rules,
graphql: graphqlRules,
},
preprocessors: {
oas3: oas3Preprocessors,
Expand Down
8 changes: 6 additions & 2 deletions packages/core/src/config/config-resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,11 @@ export async function resolvePlugins(
!pluginInstance.rules.async3 &&
!pluginInstance.rules.arazzo1 &&
!pluginInstance.rules.overlay1 &&
!pluginInstance.rules.openrpc1
!pluginInstance.rules.openrpc1 &&
!pluginInstance.rules.graphql
) {
throw new Error(
`Plugin rules must have \`oas3\`, \`oas2\`, \`async2\`, \`async3\`, \`arazzo\`, \`overlay1\`, or \`openrpc1\` rules "${p}.`
`Plugin rules must have \`oas3\`, \`oas2\`, \`async2\`, \`async3\`, \`arazzo\`, \`overlay1\`, \`openrpc1\`, or \`graphql\` rules "${p}.`
);
}
plugin.rules = {};
Expand All @@ -367,6 +368,9 @@ export async function resolvePlugins(
if (pluginInstance.rules.openrpc1) {
plugin.rules.openrpc1 = prefixRules(pluginInstance.rules.openrpc1, id);
}
if (pluginInstance.rules.graphql) {
plugin.rules.graphql = prefixRules(pluginInstance.rules.graphql, id);
}
}
if (pluginInstance.preprocessors) {
if (
Expand Down
Loading
Loading