noRootType
| Property | Value |
|---|---|
| Config name | noRootType |
| Default severity | — |
| Context | Schema |
| In recommended | No |
What it checks
Section titled “What it checks”Disallows specific root type definitions (Query, Mutation, Subscription) from appearing in the schema. This is useful for enforcing architectural constraints — for example, a read-only API might disallow Mutation, or a project that doesn’t use real-time features might disallow Subscription.
This rule requires the disallow option to be configured. Without it, no diagnostics are produced.
Examples
Section titled “Examples”# ❌ Bad — Mutation root type is disallowedtype Query { users: [User!]!}
type Mutation { deleteUser(id: ID!): Boolean}# ✅ Good — only allowed root types are definedtype Query { users: [User!]!}Options
Section titled “Options”| Option | Type | Default | Description |
|---|---|---|---|
disallow | string[] | [] | Which root types to disallow. Valid values: query, mutation, subscription |
Configuration
Section titled “Configuration”# Disallow mutations (read-only API)extensions: graphql-analyzer: lint: rules: noRootType: [error, { disallow: ["mutation"] }]
# Disallow subscriptionsextensions: graphql-analyzer: lint: rules: noRootType: [error, { disallow: ["subscription"] }]
# Disallow both mutations and subscriptionsextensions: graphql-analyzer: lint: rules: noRootType: severity: error options: disallow: ["mutation", "subscription"]