An ESLint plugin to validate GraphQL schema definitions against a set of rules.
You'll first need to install ESLint:
npm i eslint --save-dev
Next, install eslint-plugin-graphql-schema
:
npm install eslint-plugin-graphql-schema --save-dev
To use you must include the graphql
or gql
extensions
eslint --ext .graphql
Add graphql-schema
to the plugins section of your .eslintrc
configuration file. You can omit the eslint-plugin-
prefix:
{
"plugins": [
"graphql-schema"
]
}
Configure the rules you want to use under the rules section. We do recommend that you only use file
patterns that include *Schema*
and/or *schema*
as this is the pattern found in Shared Configurations.
{
"overrides":[
{
"files": ["*schema*.graphql", "*Schema*.graphql", "*schema*.gql", "*Schema*.gql"],
"parser": "eslint-plugin-graphql-schema/parser",
"rules": {
"graphql-schema/arguments-have-descriptions": ["off", {"commentDescriptions": false}],
"graphql-schema/type-fields-have-descriptions": ["warn", {"commentDescriptions": false}],
"graphql-schema/types-have-descriptions": ["off", {"commentDescriptions": false}],
"graphql-schema/type-fields-have-trailing-commas": ["error", "never"],
"graphql-schema/object-types-have-prefixes": ["error", {"prefixes": ["Org"]}]
}
}
]
}
- graphql-schema/arguments-have-descriptions: Validates that all field arguments have a description.
- graphql-schema/defined-types-are-used: Validates that all defined types are in use at least once in the schema.
- graphql-schema/deprecations-have-a-reason: Validates that all deprecations have a reason.
- graphql-schema/descriptions-are-capitalized: Validates that all field arguments have a description.
- graphql-schema/enum-values-all-caps: Validates that all enum values are capitalized.
- graphql-schema/enum-values-have-descriptions: Validates that all enum values have a description.
- graphql-schema/enum-values-sorted-alphabetically: Validates that all enum values sorted alphabetically.
- graphql-schema/input-object-fields-have-trailing-commas: Validates that input object fields have trailing commas.
- graphql-schema/input-object-fields-sorted-alphabetically: Validates that all input object fields sorted alphabetically.
- graphql-schema/input-object-values-are-camel-cased: Validates that input object value names are camel cased.
- graphql-schema/input-object-values-have-descriptions: Validates that input object values have a description.
- graphql-schema/object-types-have-prefixes: Validates that object types have given prefixes.
- graphql-schema/type-fields-are-camel-cased: Validates that object type field and interface type field names are camel cased.
- graphql-schema/type-fields-have-descriptions: Validates that object type fields and interface type fields have a description.
- graphql-schema/type-fields-have-trailing-commas: Validates that object type fields and interface type fields have trailing commas.
- graphql-schema/type-fields-sorted-alphabetically: Validates that all type object fields sorted alphabetically.
- graphql-schema/types-are-capitalized: Validates that interface types and object types have capitalized names.
- graphql-schema/types-have-descriptions: Validates that interface types, object types, union types, scalar types, enum types and input types have descriptions.
This is a good mix of warnings and errors.
{
"extends": [
"plugin:graphql-schema/recommended"
]
}
This is all about explaining yourself and giving everything a description. Don't worry! It's only a stern warning.
{
"extends": [
"plugin:graphql-schema/mom"
]
}
All rules get enabled and stand ready to error. Be the hero your team deserves!
{
"extends": [
"plugin:graphql-schema/hero"
]
}
- See Contributing
- graphql-schema-linter: A lot of rules are from this repo and converted for use in eslint. If you do not wish to add another eslint-plugin then try this.
- @apollographql/eslint-plugin-graphql: Great eslint-plugin if you already have schema. Highly recommended.
eslint-plugin-graphql-schema is licensed under the MIT License.