@nxgt/graphql-validation 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/README.md +54 -6
  2. package/dist/bad-user-input.d.ts +17 -2
  3. package/dist/bad-user-input.d.ts.map +1 -1
  4. package/dist/builder/check-constraints.d.ts +4 -2
  5. package/dist/builder/check-constraints.d.ts.map +1 -1
  6. package/dist/builder/declared.d.ts +12 -0
  7. package/dist/builder/declared.d.ts.map +1 -0
  8. package/dist/chunks/{index-xcaf9kes.js → index-atwkcfg3.js} +5 -5
  9. package/dist/chunks/{index-xcaf9kes.js.map → index-atwkcfg3.js.map} +2 -2
  10. package/dist/chunks/{index-twevz7yc.js → index-w9pw7fsk.js} +68 -34
  11. package/dist/chunks/{index-twevz7yc.js.map → index-w9pw7fsk.js.map} +6 -5
  12. package/dist/cli.js +1 -1
  13. package/dist/codegen.js +2 -2
  14. package/dist/index.d.ts +3 -1
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +380 -10
  17. package/dist/index.js.map +10 -5
  18. package/dist/limits/describe.d.ts +9 -0
  19. package/dist/limits/describe.d.ts.map +1 -0
  20. package/dist/limits/introspection.d.ts +12 -0
  21. package/dist/limits/introspection.d.ts.map +1 -0
  22. package/dist/limits/list-size.d.ts +15 -0
  23. package/dist/limits/list-size.d.ts.map +1 -0
  24. package/dist/limits/max-depth.d.ts +28 -0
  25. package/dist/limits/max-depth.d.ts.map +1 -0
  26. package/dist/limits/max-list-cost.d.ts +62 -0
  27. package/dist/limits/max-list-cost.d.ts.map +1 -0
  28. package/dist/with-validation.d.ts.map +1 -1
  29. package/docs/README.md +1 -0
  30. package/docs/guide/constraints.md +3 -3
  31. package/docs/guide/errors.md +12 -3
  32. package/docs/guide/query-limits.md +206 -0
  33. package/docs/roadmap.md +4 -0
  34. package/docs/troubleshooting.md +53 -0
  35. package/package.json +1 -1
@@ -8,6 +8,7 @@ is the one a client sees.
8
8
  - [Startup](#startup)
9
9
  - [Silent traps](#silent-traps)
10
10
  - [Runtime](#runtime)
11
+ - [Query limits](#query-limits)
11
12
  - [The bin](#the-bin)
12
13
 
13
14
  ## Install
@@ -405,6 +406,58 @@ every issue. The resolver did not run.
405
406
  | `Too small: expected number to be >=18` | `min: 18` |
406
407
  | `Invalid string: must match pattern /.../` | `pattern` |
407
408
 
409
+ ## Query limits
410
+
411
+ ### `Operation "Name" is 9 levels deep, more than the 8 allowed`
412
+
413
+ **When:** an operation is validated with `maxDepth({ depth: 8 })`.
414
+ **Why:** `extensions` is `{ code: 'QUERY_TOO_DEEP', depth: 9, limit: 8 }`. A
415
+ top-level field is depth 1; named fragments are followed, inline fragments add
416
+ nothing, `__typename` does not count. `__schema` and `__type` do: the standard
417
+ introspection query is 15 levels deep (pass `ignoreIntrospection: true` where
418
+ it is trusted). An anonymous operation
419
+ reads `Operation is 9 levels deep, ...`.
420
+ **Fix:** flatten the query, or raise `depth`. See
421
+ [Limiting the depth and cost of a query](guide/query-limits.md).
422
+
423
+ ### `Operation "Name" costs 5002, more than the 1000 allowed`
424
+
425
+ **When:** an operation is validated with `maxListCost({ budget: 1000, ... })`.
426
+ **Why:** `extensions` is `{ code: 'QUERY_TOO_COSTLY', cost: 5002, limit: 1000 }`.
427
+ Each field costs 1, times the sizes of the lists enclosing it. A list without a
428
+ usable `first` (a variable, a negative number, nothing) counts for its SDL
429
+ default, else `defaultFirst`, so a query that is cheap with the variable's real
430
+ value can still be refused.
431
+ **Fix:** ask for fewer items with a literal `first`, or raise `budget`. A query
432
+ on an interface or a union is overestimated (every branch is summed).
433
+
434
+ ### `maxDepth: depth must be an integer from 1 to 9007199254740990.`
435
+
436
+ **When:** `maxDepth` is called with `0`, a negative or a fractional `depth`.
437
+ **Fix:** pass an integer in range.
438
+
439
+ ### `maxListCost: budget must be an integer from 0 to 9007199254740990.`
440
+
441
+ **When:** `maxListCost` is called with a negative, fractional or too large
442
+ `budget`. A cost never exceeds `Number.MAX_SAFE_INTEGER` (9007199254740991), so a
443
+ budget at or over it would refuse nothing.
444
+ **Fix:** pass an integer in range.
445
+
446
+ ### `maxListCost: defaultFirst must be an integer from 0 to 9007199254740990.`
447
+
448
+ **When:** `defaultFirst` is negative, fractional or too large.
449
+ **Fix:** pass the size to assume for a list with no usable size argument.
450
+
451
+ ### A query refused although its `first` is small, or an introspection query refused
452
+
453
+ **When:** `QUERY_TOO_COSTLY` or `QUERY_TOO_DEEP` for GraphiQL's schema fetch or
454
+ a codegen's introspection query.
455
+ **Why:** `__schema` is counted: the standard introspection query is 15 levels
456
+ deep and costs on the order of 200,000 on a one-field schema.
457
+ **Fix:** `ignoreIntrospection: true` on the rule where introspection is
458
+ disabled or the client is trusted. A `first: $n` variable counts for the SDL
459
+ default, not for the value sent.
460
+
408
461
  ## The bin
409
462
 
410
463
  ### `typedefs failed: <message>`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxgt/graphql-validation",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Validate GraphQL arguments and input fields with @constraint directives, checked by Zod schemas, for graphql 16 and 17",
5
5
  "license": "MIT",
6
6
  "type": "module",