Skip to content

Latest commit

 

History

History
79 lines (64 loc) · 46.5 KB

graphql.md

File metadata and controls

79 lines (64 loc) · 46.5 KB

graphql config

Config for GraphQL servers implemented in Node.js.

🏗️ Setup

  1. If you haven't already, make sure to install @code-pushup/eslint-config and its required peer dependencies.

  2. Since this plugin requires additional peer dependencies, you have to install them as well:

    npm install -D @graphql-eslint/eslint-plugin eslint-plugin-n
  3. The GraphQL ESLint plugin needs to know where your GraphQL schema is located. For more information, refer to Extended Linting Rules with GraphQL Schema in GraphQL ESLint docs.

    • If you're using graphql-config, then your GraphQL schema will be loaded automatically from your .graphqlrc.yml (or equivalent) file. So no extra setup is required in this case.

    • Otherwise, you can use parserOptions.schema, e.g.:

      export default tseslint.config(
        // ...
        {
          files: ['**/*.graphql'],
          languageOptions: {
            parserOptions: {
              schema: './schema.graphql'
              // globs are also supported:
              // schema: './src/schema/**/*.graphql.ts'
            }
          }
        }
      );
  4. Add to your eslint.config.js file:

    import graphql from '@code-pushup/eslint-config/graphql.js';
    import tseslint from 'typescript-eslint';
    
    export default tseslint.config(...graphql);

📏 Rules (317)

294 rules are included from node config. For brevity, only the 23 additional rules are listed in this document.

🔧 Automatically fixable by the --fix CLI option.
💡 Manually fixable by editor suggestions.
🧪🚫 Disabled for test files.
🧪⚠️ Severity lessened to warning for test files.

🚨 Errors (21)

Plugin Rule Options Autofix Overrides
@graphql-eslint known-argument-names
A GraphQL field is only valid if all supplied arguments are defined by that field.
> This rule is a wrapper around a graphql-js validation function.
💡
@graphql-eslint known-directives
A GraphQL document is only valid if all @directives are known by the schema and legally positioned.
> This rule is a wrapper around a graphql-js validation function.
@graphql-eslint known-type-names
A GraphQL document is only valid if referenced types (specifically variable definitions and fragment conditions) are defined by the type schema.
> This rule is a wrapper around a graphql-js validation function.
💡
@graphql-eslint lone-schema-definition
A GraphQL document is only valid if it contains only one schema definition.
> This rule is a wrapper around a graphql-js validation function.
@graphql-eslint naming-convention
Require names to follow specified conventions.
types: PascalCase, FieldDef...
{
  "types": "PascalCase",
  "FieldDefinition": "camelCase",
  "InputValueDefinition": "camelCase",
  "Argument": "camelCase",
  "DirectiveDefinition": "camelCase",
  "EnumValueDefinition": "UPPER_CASE",
  "FieldDefinition[parent.name.value=Query]": {
    "forbiddenPrefixes": [
      "query",
      "get"
    ],
    "forbiddenSuffixes": [
      "Query"
    ]
  },
  "FieldDefinition[parent.name.value=Mutation]": {
    "forbiddenPrefixes": [
      "mutation"
    ],
    "forbiddenSuffixes": [
      "Mutation"
    ]
  },
  "FieldDefinition[parent.name.value=Subscription]": {
    "forbiddenPrefixes": [
      "subscription"
    ],
    "forbiddenSuffixes": [
      "Subscription"
    ]
  }
}
💡
@graphql-eslint no-case-insensitive-enum-values-duplicates
Disallow case-insensitive enum values duplicates.
💡
@graphql-eslint no-typename-prefix
Enforces users to avoid using the type name in a field name while defining your schema.
💡
@graphql-eslint no-unreachable-types
Requires all types to be reachable at some level by root level fields.
💡
@graphql-eslint provided-required-arguments
A field or directive is only valid if all required (non-null without a default value) field arguments have been provided.
> This rule is a wrapper around a graphql-js validation function.
@graphql-eslint relay-arguments
Set of rules to follow Relay specification for Arguments.

- A field that returns a Connection type must include forward pagination arguments (first and after), backward pagination arguments (last and before), or both

Forward pagination arguments

- first takes a non-negative integer
- after takes the Cursor type

Backward pagination arguments

- last takes a non-negative integer
- before takes the Cursor type
@graphql-eslint relay-connection-types
Set of rules to follow Relay specification for Connection types.

- Any type whose name ends in "Connection" is considered by spec to be a Connection type
- Connection type must be an Object type
- Connection type must contain a field edges that return a list type that wraps an edge type
- Connection type must contain a field pageInfo that return a non-null PageInfo Object type
@graphql-eslint relay-edge-types
Set of rules to follow Relay specification for Edge types.

- A type that is returned in list form by a connection type's edges field is considered by this spec to be an Edge type
- Edge type must be an Object type
- Edge type must contain a field node that return either Scalar, Enum, Object, Interface, Union, or a non-null wrapper around one of those types. Notably, this field cannot return a list
- Edge type must contain a field cursor that return either String, Scalar, or a non-null wrapper around one of those types
- Edge type name must end in "Edge" (optional)
- Edge type's field node must implement Node interface (optional)
- A list type should only wrap an edge type (optional)
listTypeCanWrapOnlyEdgeType...
{
  "listTypeCanWrapOnlyEdgeType": false
}
@graphql-eslint relay-page-info
Set of rules to follow Relay specification for PageInfo object.

- PageInfo must be an Object type
- PageInfo must contain fields hasPreviousPage and hasNextPage, that return non-null Boolean
- PageInfo must contain fields startCursor and endCursor, that return either String or Scalar, which can be null if there are no results
@graphql-eslint require-deprecation-reason
Require all deprecation directives to specify a reason.
@graphql-eslint require-description
Enforce descriptions in type definitions and operations.
types: true, DirectiveDefin...
{
  "types": true,
  "DirectiveDefinition": true
}
@graphql-eslint strict-id-in-types
Requires output types to have one unique identifier unless they do not have a logical one. Exceptions can be used to ignore output types that do not have unique identifiers.
@graphql-eslint unique-directive-names
A GraphQL document is only valid if all defined directives have unique names.
> This rule is a wrapper around a graphql-js validation function.
@graphql-eslint unique-directive-names-per-location
A GraphQL document is only valid if all non-repeatable directives at a given location are uniquely named.
> This rule is a wrapper around a graphql-js validation function.
@graphql-eslint unique-field-definition-names
A GraphQL complex type is only valid if all its fields are uniquely named.
> This rule is a wrapper around a graphql-js validation function.
@graphql-eslint unique-operation-types
A GraphQL document is only valid if it has only one type per operation.
> This rule is a wrapper around a graphql-js validation function.
@graphql-eslint unique-type-names
A GraphQL document is only valid if all defined types have unique names.
> This rule is a wrapper around a graphql-js validation function.

⚠️ Warnings (2)

Plugin Rule Options Autofix Overrides
@graphql-eslint description-style
Require all comments to follow the same style (either block or inline).
style: inline
{
  "style": "inline"
}
💡
@graphql-eslint no-hashtag-description
Requires to use """ or " for adding a GraphQL description instead of #.
Allows to use hashtag for comments, as long as it's not attached to an AST definition.
💡