Skip to content

Commit

Permalink
[New rule] Add strict-id-in-types rule (#333)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddeee888 committed Mar 7, 2021
1 parent f3175ff commit 4693f27
Show file tree
Hide file tree
Showing 40 changed files with 628 additions and 48 deletions.
5 changes: 5 additions & 0 deletions .changeset/happy-trainers-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-eslint/eslint-plugin': minor
---

[New rule] strict-id-in-types: use this to enforce output types to have a unique indentifier field unless being in exceptions
4 changes: 3 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Available Rules


- [`no-unreachable-types`](./rules/no-unreachable-types.md)
- [`no-deprecated`](./rules/no-deprecated.md)
- [`unique-fragment-name`](./rules/unique-fragment-name.md)
Expand All @@ -18,6 +19,7 @@
- [`avoid-duplicate-fields`](./rules/avoid-duplicate-fields.md)
- [`naming-convention`](./rules/naming-convention.md)
- [`input-name`](./rules/input-name.md)
- [`strict-id-in-types`](./rules/strict-id-in-types.md)
- [`prettier`](./rules/prettier.md)
- [`executable-definitions`](./rules/executable-definitions.md)
- [`fields-on-correct-type`](./rules/fields-on-correct-type.md)
Expand Down Expand Up @@ -55,4 +57,4 @@

- [Writing Custom Rules](./custom-rules.md)
- [How the parser works?](./parser.md)
- [`parserOptions`](./parser-options.md)
- [`parserOptions`](./parser-options.md)
2 changes: 1 addition & 1 deletion docs/rules/executable-definitions.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

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 it's source code here](https://github.com/graphql/graphql-js/blob/master/src/validation/rules/ExecutableDefinitionsRule.js).
> This rule is a wrapper around a `graphql-js` validation function. [You can find it's source code here](https://github.com/graphql/graphql-js/blob/master/src/validation/rules/ExecutableDefinitions.js).
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 @@ -7,4 +7,4 @@

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 it's source code here](https://github.com/graphql/graphql-js/blob/master/src/validation/rules/FieldsOnCorrectTypeRule.js).
> This rule is a wrapper around a `graphql-js` validation function. [You can find it's source code here](https://github.com/graphql/graphql-js/blob/master/src/validation/rules/FieldsOnCorrectType.js).
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 @@ -7,4 +7,4 @@

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 it's source code here](https://github.com/graphql/graphql-js/blob/master/src/validation/rules/FragmentsOnCompositeTypesRule.js).
> This rule is a wrapper around a `graphql-js` validation function. [You can find it's source code here](https://github.com/graphql/graphql-js/blob/master/src/validation/rules/FragmentsOnCompositeTypes.js).
22 changes: 21 additions & 1 deletion docs/rules/input-name.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,24 @@ The array object has the following properties:

#### `checkInputType` (boolean)

Default: `"true"`
Check that the input type name follows the convention <mutationName>Input

Default: `false`

#### `caseSensitiveInputType` (boolean)

Allow for case discrepancies in the input type name

Default: `true`

#### `checkQueries` (boolean)

Apply the rule to Queries

Default: `false`

#### `checkMutations` (boolean)

Apply the rule to Mutations

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

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 it's source code here](https://github.com/graphql/graphql-js/blob/master/src/validation/rules/KnownArgumentNamesRule.js).
> This rule is a wrapper around a `graphql-js` validation function. [You can find it's source code here](https://github.com/graphql/graphql-js/blob/master/src/validation/rules/KnownArgumentNames.js).
2 changes: 1 addition & 1 deletion docs/rules/known-directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

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. [You can find it's source code here](https://github.com/graphql/graphql-js/blob/master/src/validation/rules/KnownDirectivesRule.js).
> This rule is a wrapper around a `graphql-js` validation function. [You can find it's source code here](https://github.com/graphql/graphql-js/blob/master/src/validation/rules/KnownDirectives.js).
2 changes: 1 addition & 1 deletion docs/rules/known-fragment-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

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 it's source code here](https://github.com/graphql/graphql-js/blob/master/src/validation/rules/KnownFragmentNamesRule.js).
> This rule is a wrapper around a `graphql-js` validation function. [You can find it's source code here](https://github.com/graphql/graphql-js/blob/master/src/validation/rules/KnownFragmentNames.js).
2 changes: 1 addition & 1 deletion docs/rules/known-type-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

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 it's source code here](https://github.com/graphql/graphql-js/blob/master/src/validation/rules/KnownTypeNamesRule.js).
> This rule is a wrapper around a `graphql-js` validation function. [You can find it's source code here](https://github.com/graphql/graphql-js/blob/master/src/validation/rules/KnownTypeNames.js).
2 changes: 1 addition & 1 deletion docs/rules/lone-anonymous-operation.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

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 it's source code here](https://github.com/graphql/graphql-js/blob/master/src/validation/rules/LoneAnonymousOperationRule.js).
> This rule is a wrapper around a `graphql-js` validation function. [You can find it's source code here](https://github.com/graphql/graphql-js/blob/master/src/validation/rules/LoneAnonymousOperation.js).
2 changes: 1 addition & 1 deletion docs/rules/lone-schema-definition.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

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 it's source code here](https://github.com/graphql/graphql-js/blob/master/src/validation/rules/LoneSchemaDefinitionRule.js).
> This rule is a wrapper around a `graphql-js` validation function. [You can find it's source code here](https://github.com/graphql/graphql-js/blob/master/src/validation/rules/LoneSchemaDefinition.js).
2 changes: 1 addition & 1 deletion docs/rules/no-fragment-cycles.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

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 it's source code here](https://github.com/graphql/graphql-js/blob/master/src/validation/rules/NoFragmentCyclesRule.js).
> This rule is a wrapper around a `graphql-js` validation function. [You can find it's source code here](https://github.com/graphql/graphql-js/blob/master/src/validation/rules/NoFragmentCycles.js).
2 changes: 1 addition & 1 deletion docs/rules/no-undefined-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

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 it's source code here](https://github.com/graphql/graphql-js/blob/master/src/validation/rules/NoUndefinedVariablesRule.js).
> This rule is a wrapper around a `graphql-js` validation function. [You can find it's source code here](https://github.com/graphql/graphql-js/blob/master/src/validation/rules/NoUndefinedVariables.js).
26 changes: 12 additions & 14 deletions docs/rules/no-unreachable-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,37 @@
- Category: `Best Practices`
- Rule name: `@graphql-eslint/no-unreachable-types`
- Requires GraphQL Schema: `true` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
- Requires GraphQL Operations: `false` [ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)

This rule allow you to enforce that all types have to reachable by root level fields (Query.*, Mutation.*, Subscription.*).
Requires all types to be reachable at some level by root level fields

## Usage Examples

### Incorrect (field)
### Incorrect

```graphql
# eslint @graphql-eslint/no-unreachable-types: ["error"]

type Query {
me: String
type User {
id: ID!
name: String
}

type User { # This is not used, so you'll get an error
id: ID!
name: String!
type Query {
me: String
}
```


### Correct

```graphql
# eslint @graphql-eslint/no-unreachable-types: ["error"]

type Query {
me: User
type User {
id: ID!
name: String
}

type User { # This is now used, so you won't get an error
id: ID!
name: String!
type Query {
me: User
}
```
2 changes: 1 addition & 1 deletion docs/rules/no-unused-fragments.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

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 it's source code here](https://github.com/graphql/graphql-js/blob/master/src/validation/rules/NoUnusedFragmentsRule.js).
> This rule is a wrapper around a `graphql-js` validation function. [You can find it's source code here](https://github.com/graphql/graphql-js/blob/master/src/validation/rules/NoUnusedFragments.js).
2 changes: 1 addition & 1 deletion docs/rules/no-unused-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

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 it's source code here](https://github.com/graphql/graphql-js/blob/master/src/validation/rules/NoUnusedVariablesRule.js).
> This rule is a wrapper around a `graphql-js` validation function. [You can find it's source code here](https://github.com/graphql/graphql-js/blob/master/src/validation/rules/NoUnusedVariables.js).
2 changes: 1 addition & 1 deletion docs/rules/one-field-subscriptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

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 it's source code here](https://github.com/graphql/graphql-js/blob/master/src/validation/rules/SingleFieldSubscriptionsRule.js).
> This rule is a wrapper around a `graphql-js` validation function. [You can find it's source code here](https://github.com/graphql/graphql-js/blob/master/src/validation/rules/SingleFieldSubscriptions.js).
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 @@ -7,4 +7,4 @@

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 it's source code here](https://github.com/graphql/graphql-js/blob/master/src/validation/rules/OverlappingFieldsCanBeMergedRule.js).
> This rule is a wrapper around a `graphql-js` validation function. [You can find it's source code here](https://github.com/graphql/graphql-js/blob/master/src/validation/rules/OverlappingFieldsCanBeMerged.js).
2 changes: 1 addition & 1 deletion docs/rules/possible-fragment-spread.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

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 it's source code here](https://github.com/graphql/graphql-js/blob/master/src/validation/rules/PossibleFragmentSpreadsRule.js).
> This rule is a wrapper around a `graphql-js` validation function. [You can find it's source code here](https://github.com/graphql/graphql-js/blob/master/src/validation/rules/PossibleFragmentSpreads.js).
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,4 +7,4 @@

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 it's source code here](https://github.com/graphql/graphql-js/blob/master/src/validation/rules/PossibleTypeExtensionsRule.js).
> This rule is a wrapper around a `graphql-js` validation function. [You can find it's source code here](https://github.com/graphql/graphql-js/blob/master/src/validation/rules/PossibleTypeExtensions.js).
2 changes: 1 addition & 1 deletion docs/rules/provided-required-arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

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 it's source code here](https://github.com/graphql/graphql-js/blob/master/src/validation/rules/ProvidedRequiredArgumentsRule.js).
> This rule is a wrapper around a `graphql-js` validation function. [You can find it's source code here](https://github.com/graphql/graphql-js/blob/master/src/validation/rules/ProvidedRequiredArguments.js).
2 changes: 1 addition & 1 deletion docs/rules/scalar-leafs.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

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 it's source code here](https://github.com/graphql/graphql-js/blob/master/src/validation/rules/ScalarLeafsRule.js).
> This rule is a wrapper around a `graphql-js` validation function. [You can find it's source code here](https://github.com/graphql/graphql-js/blob/master/src/validation/rules/ScalarLeafs.js).
16 changes: 15 additions & 1 deletion docs/rules/selection-set-depth.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,18 @@ query deep2 {

## Config Schema

The schema defines the following properties:
### (array)

The schema defines an array with all elements of the type `object`.

The array object has the following properties:

#### `maxDepth` (number)

#### `ignore` (array)

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

Additional restrictions:

* Minimum items: `1`

0 comments on commit 4693f27

Please sign in to comment.