✅ The "extends": "plugin:@graphql-eslint/schema-recommended"
property in a configuration file enables this rule.
- Category:
Schema
- Rule name:
@graphql-eslint/strict-id-in-types
- Requires GraphQL Schema:
true
ℹ️ - Requires GraphQL Operations:
false
ℹ️
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.
# eslint @graphql-eslint/strict-id-in-types: ['error', { acceptedIdNames: ['id', '_id'], acceptedIdTypes: ['ID'], exceptions: { suffixes: ['Payload'] } }]
# Incorrect field name
type InvalidFieldName {
key: ID!
}
# Incorrect field type
type InvalidFieldType {
id: String!
}
# Incorrect exception suffix
type InvalidSuffixResult {
data: String!
}
# Too many unique identifiers. Must only contain one.
type InvalidFieldName {
id: ID!
_id: ID!
}
# eslint @graphql-eslint/strict-id-in-types: ['error', { acceptedIdNames: ['id', '_id'], acceptedIdTypes: ['ID'], exceptions: { types: ['Error'], suffixes: ['Payload'] } }]
type User {
id: ID!
}
type Post {
_id: ID!
}
type CreateUserPayload {
data: String!
}
type Error {
message: String!
}
The schema defines the following properties:
The object is an array with all elements of the type string
.
Default:
[
"id"
]
Additional restrictions:
- Unique items:
true
The object is an array with all elements of the type string
.
Default:
[
"ID"
]
Additional restrictions:
- Unique items:
true
Properties of the exceptions
object:
This is used to exclude types with names that match one of the specified values.
The object is an array with all elements of the type string
.
Additional restrictions:
- Minimum items:
1
- Unique items:
true
This is used to exclude types with names with suffixes that match one of the specified values.
The object is an array with all elements of the type string
.
Additional restrictions:
- Minimum items:
1
- Unique items:
true