Skip to content

Commit

Permalink
feat: add ignoreClientDirectives option for known-directives rule (
Browse files Browse the repository at this point in the history
…#972)

* add ignoreClientDirectives

* add ignoreClientDirectives

* add ARRAY_DEFAULT_OPTIONS

* remove You can find its source code here from `graphql-js-validation`
  • Loading branch information
dimaMachina committed Feb 19, 2022
1 parent 17425dd commit b04a8d5
Show file tree
Hide file tree
Showing 44 changed files with 245 additions and 121 deletions.
5 changes: 5 additions & 0 deletions .changeset/olive-terms-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-eslint/eslint-plugin': minor
---

feat: add `ignoreClientDirectives` option for `known-directives` rule
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Name            &nbs
[fragments-on-composite-type](rules/fragments-on-composite-type.md)|Fragments use a type condition to determine if they apply, since fragments can only be spread into a composite type (object, interface, or union), the type condition must also be a composite type.|![recommended][]|🔮|
[input-name](rules/input-name.md)|Require mutation argument to be always called "input" and input type to be called Mutation name + "Input".|![all][]|🚀|💡
[known-argument-names](rules/known-argument-names.md)|A GraphQL field is only valid if all supplied arguments are defined by that field.|![recommended][]|🔮|
[known-directives](rules/known-directives.md)|A GraphQL document is only valid if all `@directives` are known by the schema and legally positioned.|![recommended][]|🔮|
[known-directives](rules/known-directives.md)|A GraphQL document is only valid if all `@directive`s are known by the schema and legally positioned.|![recommended][]|🔮|
[known-fragment-names](rules/known-fragment-names.md)|A GraphQL document is only valid if all `...Fragment` fragment spreads refer to fragments defined in the same document.|![recommended][]|🔮|
[known-type-names](rules/known-type-names.md)|A GraphQL document is only valid if referenced types (specifically variable definitions and fragment conditions) are defined by the type schema.|![recommended][]|🔮|
[lone-anonymous-operation](rules/lone-anonymous-operation.md)|A GraphQL document is only valid if when it contains an anonymous operation (the query short-hand) that it contains only that one operation definition.|![recommended][]|🔮|
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/executable-definitions.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

A GraphQL document is only valid for execution if all definitions are either operation or fragment definitions.

> This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/ExecutableDefinitionsRule.ts).
> This rule is a wrapper around a `graphql-js` validation function.
## Resources

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/fields-on-correct-type.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

A GraphQL document is only valid if all fields selected are defined by the parent type, or are an allowed meta field such as `__typename`.

> This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/FieldsOnCorrectTypeRule.ts).
> This rule is a wrapper around a `graphql-js` validation function.
## Resources

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/fragments-on-composite-type.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

Fragments use a type condition to determine if they apply, since fragments can only be spread into a composite type (object, interface, or union), the type condition must also be a composite type.

> This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/FragmentsOnCompositeTypesRule.ts).
> This rule is a wrapper around a `graphql-js` validation function.
## Resources

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/known-argument-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

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. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/KnownArgumentNamesRule.ts).
> This rule is a wrapper around a `graphql-js` validation function.
## Resources

Expand Down
31 changes: 29 additions & 2 deletions docs/rules/known-directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,36 @@
- Requires GraphQL Schema: `true` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
- Requires GraphQL Operations: `false` [ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)

A GraphQL document is only valid if all `@directives` are known by the schema and legally positioned.
A GraphQL document is only valid if all `@directive`s are known by the schema and legally positioned.

> This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/KnownDirectivesRule.ts).
> This rule is a wrapper around a `graphql-js` validation function.
## Usage Examples

### Valid

```graphql
# eslint @graphql-eslint/known-directives: ['error', { ignoreClientDirectives: ['client'] }]

{
product {
someClientField @client
}
}
```

## Config Schema

The schema defines the following properties:

### `ignoreClientDirectives` (array, required)

The object is an array with all elements of the type `string`.

Additional restrictions:

* Minimum items: `1`
* Unique items: `true`

## Resources

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/known-fragment-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

A GraphQL document is only valid if all `...Fragment` fragment spreads refer to fragments defined in the same document.

> This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/KnownFragmentNamesRule.ts).
> This rule is a wrapper around a `graphql-js` validation function.
## Usage Examples

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/known-type-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

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. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/KnownTypeNamesRule.ts).
> This rule is a wrapper around a `graphql-js` validation function.
## Resources

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/lone-anonymous-operation.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

A GraphQL document is only valid if when it contains an anonymous operation (the query short-hand) that it contains only that one operation definition.

> This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/LoneAnonymousOperationRule.ts).
> This rule is a wrapper around a `graphql-js` validation function.
## Resources

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/lone-schema-definition.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

A GraphQL document is only valid if it contains only one schema definition.

> This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/LoneSchemaDefinitionRule.ts).
> This rule is a wrapper around a `graphql-js` validation function.
## Resources

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-fragment-cycles.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

A GraphQL fragment is only valid when it does not have cycles in fragments usage.

> This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/NoFragmentCyclesRule.ts).
> This rule is a wrapper around a `graphql-js` validation function.
## Resources

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-undefined-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

A GraphQL operation is only valid if all variables encountered, both directly and via fragment spreads, are defined by that operation.

> This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/NoUndefinedVariablesRule.ts).
> This rule is a wrapper around a `graphql-js` validation function.
## Resources

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-unused-fragments.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

A GraphQL document is only valid if all fragment definitions are spread within operations, or spread within other fragments spread within operations.

> This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/NoUnusedFragmentsRule.ts).
> This rule is a wrapper around a `graphql-js` validation function.
## Resources

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-unused-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

A GraphQL operation is only valid if all variables defined by an operation are used, either directly or within a spread fragment.

> This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/NoUnusedVariablesRule.ts).
> This rule is a wrapper around a `graphql-js` validation function.
## Resources

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/one-field-subscriptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

A GraphQL subscription is valid only if it contains a single root field.

> This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/SingleFieldSubscriptionsRule.ts).
> This rule is a wrapper around a `graphql-js` validation function.
## Resources

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/overlapping-fields-can-be-merged.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

A selection set is only valid if all fields (including spreading any fragments) either correspond to distinct response names or can be merged without ambiguity.

> This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/OverlappingFieldsCanBeMergedRule.ts).
> This rule is a wrapper around a `graphql-js` validation function.
## Resources

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/possible-fragment-spread.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

A fragment spread is only valid if the type condition could ever possibly be true: if there is a non-empty intersection of the possible parent types, and possible types which pass the type condition.

> This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/PossibleFragmentSpreadsRule.ts).
> This rule is a wrapper around a `graphql-js` validation function.
## Resources

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/possible-type-extension.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

A type extension is only valid if the type is defined and has the same kind.

> This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/PossibleTypeExtensionsRule.ts).
> This rule is a wrapper around a `graphql-js` validation function.
## Resources

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/provided-required-arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

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. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/ProvidedRequiredArgumentsRule.ts).
> This rule is a wrapper around a `graphql-js` validation function.
## Resources

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/scalar-leafs.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

A GraphQL document is valid only if all leaf fields (fields without sub selections) are of scalar or enum types.

> This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/ScalarLeafsRule.ts).
> This rule is a wrapper around a `graphql-js` validation function.
## Resources

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/unique-argument-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

A GraphQL field or directive is only valid if all supplied arguments are uniquely named.

> This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/UniqueArgumentNamesRule.ts).
> This rule is a wrapper around a `graphql-js` validation function.
## Resources

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/unique-directive-names-per-location.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

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. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/UniqueDirectivesPerLocationRule.ts).
> This rule is a wrapper around a `graphql-js` validation function.
## Resources

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/unique-directive-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

A GraphQL document is only valid if all defined directives have unique names.

> This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/UniqueDirectiveNamesRule.ts).
> This rule is a wrapper around a `graphql-js` validation function.
## Resources

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/unique-enum-value-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

A GraphQL enum type is only valid if all its values are uniquely named.

> This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/UniqueEnumValueNamesRule.ts).
> This rule is a wrapper around a `graphql-js` validation function.
## Resources

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/unique-field-definition-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

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. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/UniqueFieldDefinitionNamesRule.ts).
> This rule is a wrapper around a `graphql-js` validation function.
## Resources

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/unique-input-field-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

A GraphQL input object value is only valid if all supplied fields are uniquely named.

> This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/UniqueInputFieldNamesRule.ts).
> This rule is a wrapper around a `graphql-js` validation function.
## Resources

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/unique-operation-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

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. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/UniqueOperationTypesRule.ts).
> This rule is a wrapper around a `graphql-js` validation function.
## Resources

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/unique-type-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

A GraphQL document is only valid if all defined types have unique names.

> This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/UniqueTypeNamesRule.ts).
> This rule is a wrapper around a `graphql-js` validation function.
## Resources

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/unique-variable-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

A GraphQL operation is only valid if all its variables are uniquely named.

> This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/UniqueVariableNamesRule.ts).
> This rule is a wrapper around a `graphql-js` validation function.
## Resources

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/value-literals-of-correct-type.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

A GraphQL document is only valid if all value literals are of the type expected at their position.

> This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/ValuesOfCorrectTypeRule.ts).
> This rule is a wrapper around a `graphql-js` validation function.
## Resources

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/variables-are-input-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

A GraphQL operation is only valid if all the variables it defines are of input types (scalar, enum, or input object).

> This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/VariablesAreInputTypesRule.ts).
> This rule is a wrapper around a `graphql-js` validation function.
## Resources

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/variables-in-allowed-position.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

Variables passed to field arguments conform to type.

> This rule is a wrapper around a `graphql-js` validation function. [You can find its source code here](https://github.com/graphql/graphql-js/blob/main/src/validation/rules/VariablesInAllowedPositionRule.ts).
> This rule is a wrapper around a `graphql-js` validation function.
## Resources

Expand Down
21 changes: 6 additions & 15 deletions packages/plugin/src/rules/alphabetize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import lowerCase from 'lodash.lowercase';
import { GraphQLESLintRule } from '../types';
import { GraphQLESTreeNode } from '../estree-parser';
import { GraphQLESLintRuleListener } from '../testkit';
import { ARRAY_DEFAULT_OPTIONS } from '../utils';

const RULE_ID = 'alphabetize';

Expand Down Expand Up @@ -168,45 +169,35 @@ const rule: GraphQLESLintRule<[AlphabetizeConfig]> = {
minProperties: 1,
properties: {
fields: {
type: 'array',
uniqueItems: true,
minItems: 1,
...ARRAY_DEFAULT_OPTIONS,
items: {
enum: fieldsEnum,
},
description: 'Fields of `type`, `interface`, and `input`.',
},
values: {
type: 'array',
uniqueItems: true,
minItems: 1,
...ARRAY_DEFAULT_OPTIONS,
items: {
enum: valuesEnum,
},
description: 'Values of `enum`.',
},
selections: {
type: 'array',
uniqueItems: true,
minItems: 1,
...ARRAY_DEFAULT_OPTIONS,
items: {
enum: selectionsEnum,
},
description: 'Selections of `fragment` and operations `query`, `mutation` and `subscription`.',
},
variables: {
type: 'array',
uniqueItems: true,
minItems: 1,
...ARRAY_DEFAULT_OPTIONS,
items: {
enum: variablesEnum,
},
description: 'Variables of operations `query`, `mutation` and `subscription`.',
},
arguments: {
type: 'array',
uniqueItems: true,
minItems: 1,
...ARRAY_DEFAULT_OPTIONS,
items: {
enum: argumentsEnum,
},
Expand Down

0 comments on commit b04a8d5

Please sign in to comment.