@nxgt/graphql-validation 0.5.0 → 0.7.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 (41) hide show
  1. package/README.md +73 -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 +4 -1
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +497 -10
  17. package/dist/index.js.map +13 -5
  18. package/dist/limits/cost-context.d.ts +26 -0
  19. package/dist/limits/cost-context.d.ts.map +1 -0
  20. package/dist/limits/describe.d.ts +9 -0
  21. package/dist/limits/describe.d.ts.map +1 -0
  22. package/dist/limits/introspection.d.ts +12 -0
  23. package/dist/limits/introspection.d.ts.map +1 -0
  24. package/dist/limits/list-size.d.ts +23 -0
  25. package/dist/limits/list-size.d.ts.map +1 -0
  26. package/dist/limits/max-depth.d.ts +28 -0
  27. package/dist/limits/max-depth.d.ts.map +1 -0
  28. package/dist/limits/max-fields.d.ts +35 -0
  29. package/dist/limits/max-fields.d.ts.map +1 -0
  30. package/dist/limits/max-list-cost.d.ts +77 -0
  31. package/dist/limits/max-list-cost.d.ts.map +1 -0
  32. package/dist/limits/pending-size.d.ts +13 -0
  33. package/dist/limits/pending-size.d.ts.map +1 -0
  34. package/dist/with-validation.d.ts.map +1 -1
  35. package/docs/README.md +1 -0
  36. package/docs/guide/constraints.md +3 -3
  37. package/docs/guide/errors.md +12 -3
  38. package/docs/guide/query-limits.md +311 -0
  39. package/docs/roadmap.md +9 -0
  40. package/docs/troubleshooting.md +73 -0
  41. package/package.json +1 -1
package/README.md CHANGED
@@ -151,8 +151,8 @@ formats, or none, it throws. Without `formats`, nothing changes. Details in
151
151
  "extensions": {
152
152
  "code": "BAD_USER_INPUT",
153
153
  "issues": [
154
- { "path": ["input", "email"], "message": "Invalid email address", "code": "invalid_format", "constraint": "format" },
155
- { "path": ["input", "age"], "message": "Too small: expected number to be >=18", "code": "too_small", "constraint": "min" }
154
+ { "path": ["input", "email"], "message": "Invalid email address", "code": "invalid_format", "constraint": "format", "value": "email" },
155
+ { "path": ["input", "age"], "message": "Too small: expected number to be >=18", "code": "too_small", "constraint": "min", "value": 18 }
156
156
  ]
157
157
  }
158
158
  }
@@ -161,7 +161,9 @@ formats, or none, it throws. Without `formats`, nothing changes. Details in
161
161
  ```
162
162
 
163
163
  `issues[].path` is relative to the arguments, and `issues[].constraint` names the
164
- `@constraint` argument that refused. Mapping issues to form fields is
164
+ `@constraint` argument that refused, with `issues[].value` the value it was
165
+ declared with (`18` for `min: 18`): "at least 18" without parsing `message`.
166
+ Mapping issues to form fields is
165
167
  in [Errors](docs/guide/errors.md).
166
168
 
167
169
  ### Rules a directive cannot say
@@ -234,6 +236,67 @@ if (!result.success)
234
236
  The codes, and `fieldsError`, are in
235
237
  [Answering invalid input as one error](docs/guide/invalid-input.md).
236
238
 
239
+ ### Limiting the depth and cost of a query
240
+
241
+ A schema with list cycles (`Folder.items` returns items, `Item.folder` returns
242
+ its folder) lets a client nest a query whose cost grows exponentially.
243
+ `maxDepth` and `maxListCost` are graphql-js validation rules that refuse such a
244
+ query before any resolver runs; `maxFields` bounds the breadth they leave open
245
+ (thousands of aliases of a cheap field).
246
+
247
+ ```ts
248
+ import { maxDepth, maxFields, maxListCost } from '@nxgt/graphql-validation';
249
+ import { parse, specifiedRules, validate } from 'graphql';
250
+
251
+ const rules = [
252
+ maxDepth({ depth: 8 }),
253
+ maxListCost({ budget: 10_000, defaultFirst: 50 }),
254
+ maxFields({ limit: 500 }),
255
+ ];
256
+ const errors = validate(schema, parse(query), [...specifiedRules, ...rules]);
257
+ ```
258
+
259
+ ```ts
260
+ // graphql-yoga
261
+ import { maxDepth, maxFields, maxListCost } from '@nxgt/graphql-validation';
262
+ import { createYoga } from 'graphql-yoga';
263
+
264
+ const yoga = createYoga({
265
+ schema,
266
+ plugins: [
267
+ {
268
+ onValidate: ({ addValidationRule }) => {
269
+ addValidationRule(maxDepth({ depth: 8 }));
270
+ addValidationRule(maxListCost({ budget: 10_000, defaultFirst: 50 }));
271
+ addValidationRule(maxFields({ limit: 500 }));
272
+ },
273
+ },
274
+ ],
275
+ });
276
+ ```
277
+
278
+ One `GraphQLError` per operation: `extensions: { code: 'QUERY_TOO_DEEP', depth,
279
+ limit }`, `{ code: 'QUERY_TOO_COSTLY', cost, limit }` or `{ code: 'QUERY_TOO_WIDE',
280
+ fields, limit }`. `maxFields` counts every field selection in the document, aliases and
281
+ `__typename` included, at each spread of a fragment. A list field is sized by
282
+ its `first`, `last` or `limit` argument; a variable, a negative number or no
283
+ argument uses the argument's SDL default, else `defaultFirst`. A size is an
284
+ Int, a canonical-integer string or an integral Float; the largest of several
285
+ size arguments wins. On a Relay connection the `first` on the object field
286
+ sizes the `edges` and `nodes` lists directly under it (not lists further down,
287
+ nor lists declaring their own size argument):
288
+
289
+ ```graphql
290
+ { items(first: 100) { edges { node { id } } } }
291
+ ```
292
+
293
+ Trap: any non-list field stating a size sizes the lists declaring none directly
294
+ under it, so an argument that means something else (`limit`, say) and is named in
295
+ `sizeArguments` now sizes them: leave it out of `sizeArguments`.
296
+ Introspection is counted too; add `ignoreIntrospection: true` where it is
297
+ trusted (GraphiQL in development). See
298
+ [Limiting the depth and cost of a query](docs/guide/query-limits.md).
299
+
237
300
  ## IDE support
238
301
 
239
302
  An IDE's GraphQL plugin (JetBrains GraphQL, VS Code GraphQL) reads your `.graphql`
@@ -284,7 +347,11 @@ the directive declared is this package's. Both at once throw
284
347
  | `FIELD_CODES` | those codes, keyed `tooShort`, `tooLong`, `outOfRange`, `tooFew`, `tooMany`, `invalidFormat`, `invalid` |
285
348
  | `INVALID_INPUT` | `'validation.errors.invalid-input'` |
286
349
  | `FieldIssue`, `FieldError`, `IssueParams`, `Translate`, `InvalidInputOptions`, `FieldsErrorOptions` | their types: an issue you write, a `fields` entry, its params, your translator, the options |
287
- | `ValidationIssue`, `BadUserInputExtensions` | the types of `extensions.issues` and `extensions` |
350
+ | `ValidationIssue`, `ConstraintValue`, `BadUserInputExtensions` | the types of `extensions.issues`, of an issue's `value`, and of `extensions` |
351
+ | `maxDepth({ depth, ignoreIntrospection? })` | a graphql-js validation rule refusing an operation nested deeper than `depth` fields, `extensions.code` `QUERY_TOO_DEEP`; introspection counts (the standard query is 15 levels) unless `ignoreIntrospection` |
352
+ | `maxListCost({ budget, defaultFirst, sizeArguments?, ignoreIntrospection? })` | a graphql-js validation rule refusing an operation whose list-weighted cost is over `budget`, `extensions.code` `QUERY_TOO_COSTLY`; `sizeArguments` names the arguments sizing a list (default `first`, `last`, `limit`, the largest wins); `ignoreIntrospection` skips `__schema` and `__type` |
353
+ | `maxFields({ limit, ignoreIntrospection? })` | a graphql-js validation rule refusing an operation that selects more than `limit` fields (aliases, `__typename` and every fragment spread counted, `@skip`/`@include` not evaluated), `extensions.code` `QUERY_TOO_WIDE`; introspection counts (the standard query selects 220 fields) unless `ignoreIntrospection` |
354
+ | `MaxDepthOptions`, `MaxListCostOptions`, `MaxFieldsOptions` | their options |
288
355
  | `ConstraintArgument` | the type of `issues[].constraint`: `'minLength' \| 'format' \| ...` |
289
356
  | `ArgsSchema`, `ArgsSchemaFor`, `SchemaOf` | the types `validated` accepts: the schema or shape, and that or the function building it from the context |
290
357
  | `WithValidationOptions`, `FormatSchemas`, `OwnFormats`, `StringSchema`, `FormatName` | the types of `withValidation`'s options: a record of string schemas, with no built-in format name (`FormatName`) |
@@ -295,7 +362,7 @@ refuses the schemas `withValidation` refuses. A server does not need it.
295
362
 
296
363
  | Export | Is |
297
364
  | --- | --- |
298
- | `checkConstraints(schema, onArgs?, formats?)` | runs every startup check of `withValidation` without wrapping anything; returns the `@constraint` directive, or `undefined` when the schema declares none. `formats` is the record `withValidation` takes, checked the same way |
365
+ | `checkConstraints(schema, onArgs?, formats?)` | runs every startup check of `withValidation` without wrapping anything (`onArgs(type, field, args, declared)`: `declared(path)` lists the `Constraint`s the field's SDL writes where a Zod issue's `path` points); returns the `@constraint` directive, or `undefined` when the schema declares none. `formats` is the record `withValidation` takes, checked the same way |
299
366
  | `constraintsOn(directive, node)` | the `Constraint`s written on an argument or input field (`arg.astNode`), `format` first |
300
367
  | `inputCode(type, constraints, where, named, options?, formats?)` | the schema of that argument or field as source, `z` a free identifier: built-in scalars and lists written in full, nullable types `.nullish()`; every other named type (enum, input object, custom scalar) is what `named(type)` returns. A constraint that cannot apply throws the startup message, naming `where`. `options` (`InputCodeOptions`): `list({ type, code, single })` returns each list's source, given `code` (the array with every rule) and `single` (the list's named type, non-null, without rules), e.g. to take a single value as graphql does: `single`, wrapped, piped into `code`. `format(name)` returns the source of one of your formats, since only the generator knows where your record is imported from: a reference to your schema, which the other rules narrow (`formatSchemas.siret.max(14)`); built-in formats never reach it. `formats`: the record `withValidation` takes, checked the same way, so its names are known; a field using one of them without the `format` option throws `@constraint(format: "<name>") is one of the application's formats: its source is the code generator's to write, through inputCode's format option.` |
301
368
  | `FormatSchemas` | the type of that record |
@@ -343,6 +410,6 @@ Every startup error and its fix is in [Troubleshooting](docs/troubleshooting.md)
343
410
  ## Documentation
344
411
 
345
412
  - [Documentation index](docs/README.md)
346
- - Guides: [Constraints](docs/guide/constraints.md), [Errors](docs/guide/errors.md), [Answering invalid input as one error](docs/guide/invalid-input.md)
413
+ - Guides: [Constraints](docs/guide/constraints.md), [Errors](docs/guide/errors.md), [Answering invalid input as one error](docs/guide/invalid-input.md), [Limiting the depth and cost of a query](docs/guide/query-limits.md)
347
414
  - [Troubleshooting](docs/troubleshooting.md)
348
415
  - [Roadmap](docs/roadmap.md): schemas that read the context, emitting the invalid-input shape directly
@@ -14,14 +14,29 @@ export interface ValidationIssue {
14
14
  * refusal of `validated()`'s own schema.
15
15
  */
16
16
  readonly constraint?: ConstraintArgument;
17
+ /**
18
+ * What that `@constraint` argument was declared with, exactly as written
19
+ * (`100` for `maxLength: 100`, `"email"` for `format: "email"`), so a
20
+ * client can say "at most 100 characters" without parsing `message`.
21
+ * Present exactly when `constraint` is.
22
+ */
23
+ readonly value?: ConstraintValue;
17
24
  }
25
+ /** What a `@constraint` argument is declared with: a number or a string. */
26
+ export type ConstraintValue = string | number;
18
27
  /** The `extensions` of the error an invalid input becomes. */
19
28
  export type BadUserInputExtensions = {
20
29
  readonly code: 'BAD_USER_INPUT';
21
30
  readonly issues: readonly ValidationIssue[];
22
31
  };
23
- /** Names the `@constraint` argument behind an issue, when there is one. */
24
- export type ConstraintOf = (issue: z.core.$ZodIssue) => ConstraintArgument | undefined;
32
+ /**
33
+ * Names the `@constraint` argument behind an issue, and what it was declared
34
+ * with, when there is one.
35
+ */
36
+ export type ConstraintOf = (issue: z.core.$ZodIssue) => {
37
+ argument: ConstraintArgument;
38
+ value: ConstraintValue;
39
+ } | undefined;
25
40
  /**
26
41
  * The one error an invalid input becomes: `extensions.code` is
27
42
  * `BAD_USER_INPUT`, the code Apollo and most clients already read, and
@@ -1 +1 @@
1
- {"version":3,"file":"bad-user-input.d.ts","sourceRoot":"","sources":["../src/bad-user-input.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD,yEAAyE;AACzE,MAAM,WAAW,eAA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E,CAAC;IAC5C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,qEAAqE;IACrE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,kBAAkB,CAAC;IACzC;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,eAAe,CAAC;CACjC;AAED,4EAA4E;AAC5E,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,MAAM,CAAC;AAE9C,8DAA8D;AAC9D,MAAM,MAAM,sBAAsB,GAAG;IACpC,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAChC,QAAQ,CAAC,MAAM,EAAE,SAAS,eAAe,EAAE,CAAC;CAC5C,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,CAC1B,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,SAAS,KACnB;IAAE,QAAQ,EAAE,kBAAkB,CAAC;IAAC,KAAK,EAAE,eAAe,CAAA;CAAE,GAAG,SAAS,CAAC;AAkC1E;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,QAAQ,GAAG,YAAY,CAE3E;AAED,oFAAoF;AACpF,wBAAsB,SAAS,CAC9B,MAAM,EAAE,CAAC,CAAC,OAAO,EACjB,IAAI,EAAE,OAAO,EACb,KAAK,EAAE,MAAM,EACb,YAAY,CAAC,EAAE,YAAY,GACzB,OAAO,CAAC,OAAO,CAAC,CAKlB"}
@@ -1,13 +1,15 @@
1
1
  import { type GraphQLDirective, type GraphQLField, type GraphQLObjectType, type GraphQLSchema } from 'graphql';
2
2
  import type { z } from 'zod';
3
3
  import { type FormatSchemas } from '../formats/registry.js';
4
+ import { type Constraint } from './constraints.js';
4
5
  /**
5
6
  * Runs every check `withValidation` makes at startup, so a code generator
6
7
  * refuses the same schemas: the declaration is `constraintTypeDefs`', every
7
8
  * constraint applies where it is written (in every input type), none sits on
8
9
  * a directive's argument, objects keep their interfaces' constraints, and no
9
10
  * default value breaks its own. `onArgs` receives each object field's
10
- * arguments schema, for a field with something to check.
11
+ * arguments schema, for a field with something to check, and `declared`
12
+ * the `@constraint`s the field's SDL writes where an issue's path points.
11
13
  *
12
14
  * `formats` are the application's own, which `@constraint(format: "...")`
13
15
  * may name beside the built-in ones; they are checked first (name, no
@@ -16,5 +18,5 @@ import { type FormatSchemas } from '../formats/registry.js';
16
18
  * Returns the `@constraint` directive, or `undefined` when the schema
17
19
  * declares none (and so carries no constraint).
18
20
  */
19
- export declare function checkConstraints(schema: GraphQLSchema, onArgs?: (type: GraphQLObjectType, field: GraphQLField<unknown, unknown>, args: z.ZodType) => void, formats?: FormatSchemas): GraphQLDirective | undefined;
21
+ export declare function checkConstraints(schema: GraphQLSchema, onArgs?: (type: GraphQLObjectType, field: GraphQLField<unknown, unknown>, args: z.ZodType, declared: (path: readonly PropertyKey[]) => readonly Constraint[]) => void, formats?: FormatSchemas): GraphQLDirective | undefined;
20
22
  //# sourceMappingURL=check-constraints.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"check-constraints.d.ts","sourceRoot":"","sources":["../../src/builder/check-constraints.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAGlB,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,EAAE,KAAK,aAAa,EAAc,MAAM,qBAAqB,CAAC;AAKrE;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAC/B,MAAM,EAAE,aAAa,EACrB,MAAM,CAAC,EAAE,CACR,IAAI,EAAE,iBAAiB,EACvB,KAAK,EAAE,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,EACrC,IAAI,EAAE,CAAC,CAAC,OAAO,KACX,IAAI,EACT,OAAO,CAAC,EAAE,aAAa,GACrB,gBAAgB,GAAG,SAAS,CAyB9B"}
1
+ {"version":3,"file":"check-constraints.d.ts","sourceRoot":"","sources":["../../src/builder/check-constraints.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAGlB,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,EAAE,KAAK,aAAa,EAAc,MAAM,qBAAqB,CAAC;AAErE,OAAO,EAAE,KAAK,UAAU,EAAiB,MAAM,eAAe,CAAC;AAI/D;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,CAC/B,MAAM,EAAE,aAAa,EACrB,MAAM,CAAC,EAAE,CACR,IAAI,EAAE,iBAAiB,EACvB,KAAK,EAAE,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,EACrC,IAAI,EAAE,CAAC,CAAC,OAAO,EACf,QAAQ,EAAE,CAAC,IAAI,EAAE,SAAS,WAAW,EAAE,KAAK,SAAS,UAAU,EAAE,KAC7D,IAAI,EACT,OAAO,CAAC,EAAE,aAAa,GACrB,gBAAgB,GAAG,SAAS,CA0B9B"}
@@ -0,0 +1,12 @@
1
+ import { type GraphQLField } from 'graphql';
2
+ import { type Constraint } from './constraints.js';
3
+ import type { InputSchemas } from './input-schema.js';
4
+ /**
5
+ * The `@constraint` arguments written where a Zod issue's `path` points, in
6
+ * a field's arguments: the argument or input field it ends on, or, under a
7
+ * list, the list's own rules (`minItems`, `maxItems`) at the list and its
8
+ * items' at an index, as `InputSchemas` splits them. Empty when the path
9
+ * leaves the declared types.
10
+ */
11
+ export declare function declaredAt(inputs: InputSchemas, field: GraphQLField<unknown, unknown>, path: readonly PropertyKey[]): readonly Constraint[];
12
+ //# sourceMappingURL=declared.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"declared.d.ts","sourceRoot":"","sources":["../../src/builder/declared.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,YAAY,EAMjB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,KAAK,UAAU,EAAiB,MAAM,eAAe,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEnD;;;;;;GAMG;AACH,wBAAgB,UAAU,CACzB,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,EACrC,IAAI,EAAE,SAAS,WAAW,EAAE,GAC1B,SAAS,UAAU,EAAE,CAyBvB"}
@@ -13,9 +13,6 @@ var __export = (target, all) => {
13
13
  });
14
14
  };
15
15
 
16
- // src/constraint-directive.ts
17
- import { DirectiveLocation } from "graphql";
18
-
19
16
  // src/rules/all.ts
20
17
  var exports_all = {};
21
18
  __export(exports_all, {
@@ -36,6 +33,9 @@ __export(exports_all, {
36
33
  startsWithRule: () => startsWithRule
37
34
  });
38
35
 
36
+ // src/constraint-directive.ts
37
+ import { DirectiveLocation } from "graphql";
38
+
39
39
  // src/rules/rule.ts
40
40
  var RULE_PARAM = "nxgtConstraint";
41
41
  function defineRule(rule) {
@@ -242,5 +242,5 @@ function assertOwnConstraint(directive) {
242
242
 
243
243
  export { __export, RULE_PARAM, rules, applyRule, applyRuleCode, constraintOf, constraintTypeDefs2, assertOwnConstraint };
244
244
 
245
- //# debugId=AD9C9BDBBBE92EA564756E2164756E21
246
- //# sourceMappingURL=index-xcaf9kes.js.map
245
+ //# debugId=02497C6067AC4D4564756E2164756E21
246
+ //# sourceMappingURL=index-atwkcfg3.js.map
@@ -21,7 +21,7 @@
21
21
  "import { defineRule, literal } from './rule';\n\nexport const startsWithRule = defineRule({\n\targument: 'startsWith',\n\ttype: 'String',\n\ttarget: 'string',\n\ttoZod: (schema, value) => schema.startsWith(value),\n\ttoCode: (schema, value) => `${schema}.startsWith(${literal(value)})`,\n\towns: (issue) => issue.format === 'starts_with',\n});\n",
22
22
  "import type { z } from 'zod';\nimport * as all from './all';\nimport { type IssueFields, RULE_PARAM, type RuleContext } from './rule';\n\n/**\n * One of the rules, as its own type: a builder narrows it on `target`, so a\n * number schema never reaches a string rule.\n */\nexport type RegisteredRule = (typeof all)[keyof typeof all];\n\n/** An argument `@constraint` takes. */\nexport type ConstraintArgument = RegisteredRule['argument'];\n\n/**\n * Every rule, keyed by its `@constraint` argument. Derived from what\n * `./all` exports, so a new rule is one file and one line there, and the\n * directive's SDL follows.\n */\nexport const rules = Object.fromEntries(\n\tObject.values(all).map((rule) => [rule.argument, rule]),\n) as {\n\treadonly [A in ConstraintArgument]: Extract<RegisteredRule, { argument: A }>;\n};\n\n/**\n * Applies a rule to a schema its caller has already matched to the rule's\n * target: the one place the rule's typed `toZod` meets a schema built from\n * GraphQL types, which the compiler cannot relate.\n */\nexport function applyRule(\n\trule: RegisteredRule,\n\tschema: z.ZodType,\n\tvalue: string | number,\n\tcontext: RuleContext,\n): z.ZodType {\n\tconst toZod = rule.toZod as unknown as (\n\t\tschema: z.ZodType,\n\t\tvalue: string | number,\n\t\tcontext: RuleContext,\n\t) => z.ZodType;\n\treturn toZod(schema, value, context);\n}\n\n/** `applyRule` for source: the rule's typed `toCode` on a schema's source. */\nexport function applyRuleCode(\n\trule: RegisteredRule,\n\tsource: string,\n\tvalue: string | number,\n\tcontext: RuleContext,\n): string {\n\tconst toCode = rule.toCode as (\n\t\tschema: string,\n\t\tvalue: string | number,\n\t\tcontext: RuleContext,\n\t) => string;\n\treturn toCode(source, value, context);\n}\n\n/**\n * The `@constraint` argument whose rule refused with this issue, if any: the\n * one the issue is marked with (an application format's), else the one rule\n * that owns its shape.\n */\nexport function constraintOf(\n\tissue: z.core.$ZodIssue,\n): ConstraintArgument | undefined {\n\tconst fields = issue as unknown as IssueFields;\n\tconst marked = fields.params?.[RULE_PARAM];\n\tif (typeof marked === 'string' && Object.hasOwn(rules, marked))\n\t\treturn marked as ConstraintArgument;\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Aa,cAAc,UAAU;AAAA,IAC5C,GAAG,UAAU,KAAK,QAAQ,CAAC,QAAQ;AAAA,MAClC,MAAM,OAAQ,MACb,IAAI;AAAA,MAEL,IAAI,CAAC;AAAA,QAAM,OAAO,CAAC,YAAY,IAAI,2BAA2B;AAAA,MAC9D,MAAM,OAAO,OAAO,IAAI,IAAI;AAAA,MAC5B,OAAO,SAAS,KAAK,OAClB,CAAC,IACD,CAAC,YAAY,IAAI,SAAS,aAAa,KAAK,MAAM;AAAA,KACrD;AAAA,EACF;AAAA,EACA,IAAI,SAAS,SAAS,GAAG;AAAA,IACxB,MAAM,IAAI,MACT,+DAA+D,SAAS,KAAK,IAAI,wCAClF;AAAA,EACD;AAAA;",
25
+ "debugId": "02497C6067AC4D4564756E2164756E21",
26
26
  "names": []
27
27
  }
@@ -4,27 +4,7 @@ import {
4
4
  rules,
5
5
  applyRule,
6
6
  assertOwnConstraint
7
- } from "./index-xcaf9kes.js";
8
-
9
- // src/builder/constraints.ts
10
- import {
11
- getDirectiveValues
12
- } from "graphql";
13
- function constraintsOn2(directive, node) {
14
- if (!directive || !node)
15
- return [];
16
- const values = getDirectiveValues(directive, { directives: node.directives ?? [] }) ?? {};
17
- return Object.entries(values).filter(([, value]) => value !== undefined && value !== null).map(([argument, value]) => ({
18
- rule: rules[argument],
19
- value
20
- })).sort((a, b) => Number(Boolean(b.rule.base)) - Number(Boolean(a.rule.base)));
21
- }
22
-
23
- // src/builder/check-constraints.ts
24
- import {
25
- isInterfaceType,
26
- isObjectType
27
- } from "graphql";
7
+ } from "./index-atwkcfg3.js";
28
8
 
29
9
  // src/formats/all.ts
30
10
  var exports_all = {};
@@ -39,6 +19,12 @@ __export(exports_all, {
39
19
  uuidFormat: () => uuidFormat
40
20
  });
41
21
 
22
+ // src/builder/check-constraints.ts
23
+ import {
24
+ isInterfaceType,
25
+ isObjectType
26
+ } from "graphql";
27
+
42
28
  // src/formats/byte.ts
43
29
  import { z } from "zod";
44
30
 
@@ -276,6 +262,22 @@ function registryOf(own) {
276
262
 
277
263
  // src/builder/args-schema.ts
278
264
  import { z as z10 } from "zod";
265
+
266
+ // src/builder/constraints.ts
267
+ import {
268
+ getDirectiveValues
269
+ } from "graphql";
270
+ function constraintsOn2(directive, node) {
271
+ if (!directive || !node)
272
+ return [];
273
+ const values = getDirectiveValues(directive, { directives: node.directives ?? [] }) ?? {};
274
+ return Object.entries(values).filter(([, value]) => value !== undefined && value !== null).map(([argument, value]) => ({
275
+ rule: rules[argument],
276
+ value
277
+ })).sort((a, b) => Number(Boolean(b.rule.base)) - Number(Boolean(a.rule.base)));
278
+ }
279
+
280
+ // src/builder/args-schema.ts
279
281
  function argsSchemaOf(inputs, parent, field) {
280
282
  if (!field.args.some((arg) => inputs.needsCheck(arg)))
281
283
  return;
@@ -307,12 +309,44 @@ function assertInterfaceConstraintsKept(inputs, type) {
307
309
  }
308
310
  }
309
311
 
310
- // src/builder/input-schema.ts
312
+ // src/builder/declared.ts
311
313
  import {
312
314
  getNamedType,
313
315
  isInputObjectType,
314
316
  isListType,
315
- isNonNullType,
317
+ isNonNullType
318
+ } from "graphql";
319
+ function declaredAt(inputs, field, path) {
320
+ const [name, ...rest] = path;
321
+ const arg = field.args.find((candidate) => candidate.name === name);
322
+ if (!arg)
323
+ return [];
324
+ let type = arg.type;
325
+ let constraints = constraintsOn2(inputs.directive, arg.astNode);
326
+ for (const key of rest) {
327
+ const unwrapped = isNonNullType(type) ? type.ofType : type;
328
+ if (isListType(unwrapped) && typeof key === "number") {
329
+ constraints = constraints.filter(({ rule }) => rule.target !== "list");
330
+ type = unwrapped.ofType;
331
+ continue;
332
+ }
333
+ const named = getNamedType(unwrapped);
334
+ const next = !isListType(unwrapped) && isInputObjectType(named) ? named.getFields()[String(key)] : undefined;
335
+ if (!next)
336
+ return [];
337
+ type = next.type;
338
+ constraints = constraintsOn2(inputs.directive, next.astNode);
339
+ }
340
+ const onList = isListType(isNonNullType(type) ? type.ofType : type);
341
+ return constraints.filter(({ rule }) => rule.target === "list" === onList);
342
+ }
343
+
344
+ // src/builder/input-schema.ts
345
+ import {
346
+ getNamedType as getNamedType2,
347
+ isInputObjectType as isInputObjectType2,
348
+ isListType as isListType2,
349
+ isNonNullType as isNonNullType2,
316
350
  valueFromAST
317
351
  } from "graphql";
318
352
  import { z as z12 } from "zod";
@@ -392,7 +426,7 @@ class InputSchemas {
392
426
  constructor(schema, formats = registryOf()) {
393
427
  this.#context = { formats };
394
428
  this.directive = schema.getDirective("constraint") ?? undefined;
395
- const objects = Object.values(schema.getTypeMap()).filter(isInputObjectType);
429
+ const objects = Object.values(schema.getTypeMap()).filter(isInputObjectType2);
396
430
  for (let changed = true;changed; ) {
397
431
  changed = false;
398
432
  for (const type of objects) {
@@ -407,12 +441,12 @@ class InputSchemas {
407
441
  }
408
442
  }
409
443
  isConstrained(type) {
410
- const named = getNamedType(type);
411
- return isInputObjectType(named) && this.#constrained.has(named.name);
444
+ const named = getNamedType2(type);
445
+ return isInputObjectType2(named) && this.#constrained.has(named.name);
412
446
  }
413
447
  buildAll(schema) {
414
448
  for (const type of Object.values(schema.getTypeMap())) {
415
- if (isInputObjectType(type))
449
+ if (isInputObjectType2(type))
416
450
  this.#object(type);
417
451
  }
418
452
  }
@@ -446,14 +480,14 @@ class InputSchemas {
446
480
  }
447
481
  }
448
482
  #typed(type, constraints, where) {
449
- if (isNonNullType(type))
483
+ if (isNonNullType2(type))
450
484
  return this.#required(type.ofType, constraints, where);
451
485
  return this.#required(type, constraints, where).nullish();
452
486
  }
453
487
  #required(type, constraints, where) {
454
- if (isNonNullType(type))
488
+ if (isNonNullType2(type))
455
489
  return this.#required(type.ofType, constraints, where);
456
- if (isListType(type)) {
490
+ if (isListType2(type)) {
457
491
  const own = constraints.filter(({ rule }) => rule.target === "list");
458
492
  const items = constraints.filter(({ rule }) => rule.target !== "list");
459
493
  let list = z12.array(this.#typed(type.ofType, items, where));
@@ -461,7 +495,7 @@ class InputSchemas {
461
495
  list = applyRule(rule, list, value, this.#context);
462
496
  return list;
463
497
  }
464
- if (isInputObjectType(type)) {
498
+ if (isInputObjectType2(type)) {
465
499
  assertObjectTargets(type.name, constraints, where);
466
500
  return this.#object(type);
467
501
  }
@@ -505,7 +539,7 @@ function checkConstraints2(schema, onArgs, formats) {
505
539
  for (const field of Object.values(type.getFields())) {
506
540
  const args = argsSchemaOf(inputs, type.name, field);
507
541
  if (args)
508
- onArgs?.(type, field, args);
542
+ onArgs?.(type, field, args, (path) => declaredAt(inputs, field, path));
509
543
  }
510
544
  }
511
545
  inputs.checkDefaults();
@@ -523,5 +557,5 @@ function assertNoDirectiveArgumentConstrained(inputs, schema) {
523
557
 
524
558
  export { registryOf, constraintsOn2, assertLeafTargets, assertObjectTargets, baseCode, checkConstraints2 };
525
559
 
526
- //# debugId=F2C2C0D2BA61CB1B64756E2164756E21
527
- //# sourceMappingURL=index-twevz7yc.js.map
560
+ //# debugId=418E0FAAA9B9E68E64756E2164756E21
561
+ //# sourceMappingURL=index-w9pw7fsk.js.map