Skip to content

Commit a85320c

Browse files
authored
chore: add pagination and root field linter rules (#112)
1 parent 0b37be0 commit a85320c

File tree

4 files changed

+1078
-231
lines changed

4 files changed

+1078
-231
lines changed

docs/graphql-linting.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,30 @@ The custom GraphQL linter includes the following built-in rules:
8383
| `no-duplicate-fields` | error | Prevent duplicate field definitions |
8484
| `require-description` | warn | Require descriptions for types/fields |
8585
| `require-deprecation-reason` | warn | Require reason for deprecated fields |
86+
| `field-naming-convention` | warn | Enforce camelCase field naming |
87+
| `root-fields-nullable` | warn | Suggest nullable root field types |
88+
89+
### Pagination Rules
90+
91+
| Rule | Severity | Description |
92+
| ------------------------------ | -------- | ---------------------------------------------- |
93+
| `connection-structure` | error | Ensure Connection types have edges/pageInfo |
94+
| `edge-structure` | error | Ensure Edge types have node/cursor fields |
95+
| `connection-arguments` | warn | Suggest pagination arguments for connections |
96+
| `pagination-argument-types` | error | Enforce correct types for pagination arguments |
8697

8798
### Rule Details
8899

89100
- **no-anonymous-operations**: Ensures all GraphQL operations (queries, mutations, subscriptions) have names
90101
- **no-duplicate-fields**: Prevents duplicate field definitions within the same type
91102
- **require-description**: Suggests adding descriptions to types and fields for better documentation
92103
- **require-deprecation-reason**: Ensures deprecated fields include a reason for deprecation
104+
- **field-naming-convention**: Enforces camelCase naming for field names (ignores special fields like `__typename`)
105+
- **root-fields-nullable**: Suggests making root type fields nullable for better error handling
106+
- **connection-structure**: Ensures Connection types follow the Relay pagination pattern with `edges` and `pageInfo` fields
107+
- **edge-structure**: Ensures Edge types have the required `node` and `cursor` fields
108+
- **connection-arguments**: Suggests adding `first` and `after` arguments to fields returning Connection types
109+
- **pagination-argument-types**: Enforces correct types for pagination arguments (`first: Int!`, `after: String`)
93110

94111
## Usage
95112

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@
229229
"watch:esbuild": "node esbuild.js --watch",
230230
"watch:tsc": "tsc --noEmit --watch --project tsconfig.json",
231231
"package": "npm run check-types && npm run lint && node esbuild.js --production",
232-
"compile-tests": "tsc -p . --outDir out",
232+
"compile-tests": "tsc -p . --outDir out && mkdir -p out/test/fixtures && cp -r src/test/fixtures/* out/test/fixtures/",
233233
"watch-tests": "tsc -p . -w --outDir out",
234234
"pretest": "npm run compile-tests && npm run compile && npm run lint",
235235
"check-types": "tsc --noEmit",

0 commit comments

Comments
 (0)