@schema-hub/zod-graphql-query-builder 0.0.13 → 0.0.14

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 (55) hide show
  1. package/package.json +16 -5
  2. package/readme.md +80 -2
  3. package/sbom.cdx.json +67 -0
  4. package/zod-graphql-query-builder/build-context.d.ts +4 -0
  5. package/zod-graphql-query-builder/build-context.d.ts.map +1 -0
  6. package/zod-graphql-query-builder/build-context.js +10 -0
  7. package/zod-graphql-query-builder/build-context.js.map +1 -0
  8. package/zod-graphql-query-builder/builder.d.ts +2 -13
  9. package/zod-graphql-query-builder/builder.d.ts.map +1 -1
  10. package/zod-graphql-query-builder/builder.js +19 -159
  11. package/zod-graphql-query-builder/builder.js.map +1 -1
  12. package/zod-graphql-query-builder/custom-scalar.d.ts +0 -2
  13. package/zod-graphql-query-builder/custom-scalar.d.ts.map +1 -1
  14. package/zod-graphql-query-builder/custom-scalar.js +1 -7
  15. package/zod-graphql-query-builder/custom-scalar.js.map +1 -1
  16. package/zod-graphql-query-builder/entry-point.d.ts +1 -4
  17. package/zod-graphql-query-builder/entry-point.d.ts.map +1 -1
  18. package/zod-graphql-query-builder/fragment-definitions.d.ts +1 -0
  19. package/zod-graphql-query-builder/fragment-definitions.d.ts.map +1 -0
  20. package/zod-graphql-query-builder/fragment-definitions.js +15 -0
  21. package/zod-graphql-query-builder/fragment-definitions.js.map +1 -0
  22. package/zod-graphql-query-builder/query-schema.d.ts +63 -27
  23. package/zod-graphql-query-builder/query-schema.d.ts.map +1 -1
  24. package/zod-graphql-query-builder/query-schema.js +8 -3
  25. package/zod-graphql-query-builder/query-schema.js.map +1 -1
  26. package/zod-graphql-query-builder/root-shape.js +7 -0
  27. package/zod-graphql-query-builder/root-shape.js.map +1 -0
  28. package/zod-graphql-query-builder/serializer.d.ts +5 -0
  29. package/zod-graphql-query-builder/serializer.d.ts.map +1 -0
  30. package/zod-graphql-query-builder/serializer.js +308 -0
  31. package/zod-graphql-query-builder/serializer.js.map +1 -0
  32. package/zod-graphql-query-builder/type-name.d.ts +8 -0
  33. package/zod-graphql-query-builder/type-name.d.ts.map +1 -0
  34. package/zod-graphql-query-builder/type-name.js +45 -0
  35. package/zod-graphql-query-builder/type-name.js.map +1 -0
  36. package/zod-graphql-query-builder/values/enum.d.ts +0 -2
  37. package/zod-graphql-query-builder/values/enum.d.ts.map +1 -1
  38. package/zod-graphql-query-builder/values/enum.js +1 -9
  39. package/zod-graphql-query-builder/values/enum.js.map +1 -1
  40. package/zod-graphql-query-builder/values/parameter-list.js +8 -2
  41. package/zod-graphql-query-builder/values/parameter-list.js.map +1 -1
  42. package/zod-graphql-query-builder/values/value.d.ts +0 -5
  43. package/zod-graphql-query-builder/values/value.d.ts.map +1 -1
  44. package/zod-graphql-query-builder/values/value.js +9 -3
  45. package/zod-graphql-query-builder/values/value.js.map +1 -1
  46. package/zod-graphql-query-builder/values/variable-placeholder.d.ts +0 -3
  47. package/zod-graphql-query-builder/values/variable-placeholder.d.ts.map +1 -1
  48. package/zod-graphql-query-builder/values/variable-placeholder.js +1 -9
  49. package/zod-graphql-query-builder/values/variable-placeholder.js.map +1 -1
  50. package/zod-graphql-query-builder/values/variable-set.js +4 -0
  51. package/zod-graphql-query-builder/values/variable-set.js.map +1 -0
  52. package/zod-graphql-query-builder/variable-definition.d.ts +0 -1
  53. package/zod-graphql-query-builder/variable-definition.d.ts.map +1 -1
  54. package/zod-graphql-query-builder/variable-definition.js +4 -1
  55. package/zod-graphql-query-builder/variable-definition.js.map +1 -1
package/package.json CHANGED
@@ -1,11 +1,21 @@
1
1
  {
2
2
  "author": "Mathias Schreck <schreck.mathias@gmail.com>",
3
3
  "dependencies": {
4
- "graphql": "16.12.0"
4
+ "graphql": "16.14.0"
5
5
  },
6
6
  "description": "Transforms Zod schemas into GraphQL queries",
7
7
  "engines": {
8
- "node": "^22 || ^24"
8
+ "node": "^24 || ^26"
9
+ },
10
+ "exports": {
11
+ ".": {
12
+ "import": "./zod-graphql-query-builder/entry-point.js",
13
+ "types": "./zod-graphql-query-builder/entry-point.d.ts"
14
+ },
15
+ "./zod-graphql-query-builder/values/variable-placeholder.js": {
16
+ "import": "./zod-graphql-query-builder/values/variable-placeholder.js",
17
+ "types": "./zod-graphql-query-builder/values/variable-placeholder.d.ts"
18
+ }
9
19
  },
10
20
  "keywords": [
11
21
  "graphql",
@@ -16,7 +26,6 @@
16
26
  "zod-graphql"
17
27
  ],
18
28
  "license": "MIT",
19
- "main": "zod-graphql-query-builder/entry-point.js",
20
29
  "name": "@schema-hub/zod-graphql-query-builder",
21
30
  "peerDependencies": {
22
31
  "zod": "^4.0.5"
@@ -25,7 +34,9 @@
25
34
  "type": "git",
26
35
  "url": "git+ssh://git@github.com/enormora/schema-hub.git"
27
36
  },
37
+ "sideEffects": [
38
+ "./zod-graphql-query-builder/entry-point.js"
39
+ ],
28
40
  "type": "module",
29
- "types": "zod-graphql-query-builder/entry-point.d.ts",
30
- "version": "0.0.13"
41
+ "version": "0.0.14"
31
42
  }
package/readme.md CHANGED
@@ -101,7 +101,7 @@ const query = buildGraphqlQuery(mySchema, { variableDefinitions: { $var: 'String
101
101
  **Built query:**
102
102
 
103
103
  ```graphql
104
- query ($var: String!) { foo(anyParameterAssignedToPlainValue: "plain-string", anyParameterAssignedToEnumValue: foo, anyParameterReferencingAVariable: $var) }
104
+ query ($var: String!) { foo(anyParameterAssignedToEnumValue: foo, anyParameterAssignedToPlainValue: "plain-string", anyParameterReferencingAVariable: $var) }
105
105
  ```
106
106
 
107
107
  ### Defining Fragments
@@ -129,6 +129,84 @@ const query = buildGraphqlQuery(mySchema);
129
129
  query { foo { ... on A { __typename, valueA }, ... on B { __typename, valueB } } }
130
130
  ```
131
131
 
132
+ ### Named Fragments / Reusing Schemas
133
+
134
+ When the same object schema reference is used in more than one place in a single operation, the builder
135
+ automatically hoists its body into a named fragment to keep the produced query small. Two ways to opt in
136
+ to this behavior — both rely on the builder being able to resolve a GraphQL type name for the schema.
137
+
138
+ 1. Register a `typeName` explicitly via `graphqlFieldOptions`, or
139
+ 2. Include `__typename: z.literal('TheTypeName')` in the strict-object's shape.
140
+
141
+ If both are present and disagree the build throws. Schemas without a resolvable type name stay inlined at
142
+ every use site exactly as before, so this feature is purely additive.
143
+
144
+ **Input (explicit `typeName`):**
145
+
146
+ ```typescript
147
+ import { buildGraphqlQuery, graphqlFieldOptions } from '@schema-hub/zod-graphql-query-builder';
148
+ import { z } from 'zod';
149
+
150
+ const userSchema = graphqlFieldOptions(
151
+ z.strictObject({ id: z.string(), name: z.string() }),
152
+ { typeName: 'User' }
153
+ );
154
+ const mySchema = z.strictObject({ me: userSchema, you: userSchema });
155
+ const query = buildGraphqlQuery(mySchema);
156
+ ```
157
+
158
+ **Built query:**
159
+
160
+ ```graphql
161
+ query { me { ...User_1 }, you { ...User_1 } } fragment User_1 on User { id, name }
162
+ ```
163
+
164
+ **Input (`typeName` inferred from `__typename` literal):**
165
+
166
+ ```typescript
167
+ const userSchema = z.strictObject({
168
+ __typename: z.literal('User'),
169
+ id: z.string()
170
+ });
171
+ const mySchema = z.strictObject({ me: userSchema, you: userSchema });
172
+ const query = buildGraphqlQuery(mySchema);
173
+ ```
174
+
175
+ **Built query:**
176
+
177
+ ```graphql
178
+ query { me { ...User_1 }, you { ...User_1 } } fragment User_1 on User { __typename, id }
179
+ ```
180
+
181
+ Fragment names follow the pattern `<TypeName>_<index>`, where the index is a counter scoped to one
182
+ `buildGraphqlQuery` / `buildGraphqlMutation` call. Two distinct schemas registered with the same `typeName`
183
+ are disambiguated by the counter (`User_1`, `User_2`).
184
+
185
+ **Cyclic schemas.** Self-referential schemas — which would otherwise be inexpressible as a finite inline
186
+ selection — work as long as a type name is resolvable for them. The cyclic reference is emitted as a
187
+ self-recursive fragment:
188
+
189
+ ```typescript
190
+ type User = { id: string; friends: User[]; };
191
+ const userSchema: z.ZodMiniType<User> = graphqlFieldOptions(
192
+ z.strictObject({
193
+ id: z.string(),
194
+ friends: z.array(z.lazy(() => userSchema))
195
+ }),
196
+ { typeName: 'User' }
197
+ );
198
+ const query = buildGraphqlQuery(z.strictObject({ me: userSchema }));
199
+ ```
200
+
201
+ **Built query:**
202
+
203
+ ```graphql
204
+ query { me { ...User_1 } } fragment User_1 on User { friends { ...User_1 }, id }
205
+ ```
206
+
207
+ A cyclic schema without a resolvable type name is rejected at build time with an explicit error so the
208
+ builder never enters an infinite recursion.
209
+
132
210
  ### Working with custom scalars
133
211
 
134
212
  **Input:**
@@ -225,5 +303,5 @@ const mutation = buildGraphqlMutation(mySchema, { variableDefinitions: { $var: '
225
303
  **Built mutation:**
226
304
 
227
305
  ```graphql
228
- mutation ($var: String!) { foo(anyParameterAssignedToPlainValue: "plain-string", anyParameterAssignedToEnumValue: foo, anyParameterReferencingAVariable: $var) }
306
+ mutation ($var: String!) { foo(anyParameterAssignedToEnumValue: foo, anyParameterAssignedToPlainValue: "plain-string", anyParameterReferencingAVariable: $var) }
229
307
  ```
package/sbom.cdx.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "$schema": "http://cyclonedx.org/schema/bom-1.6.schema.json",
3
+ "bomFormat": "CycloneDX",
4
+ "specVersion": "1.6",
5
+ "version": 1,
6
+ "metadata": {
7
+ "tools": {
8
+ "components": [
9
+ {
10
+ "type": "application",
11
+ "name": "packtory",
12
+ "version": "0.0.26"
13
+ }
14
+ ]
15
+ },
16
+ "component": {
17
+ "type": "library",
18
+ "name": "@schema-hub/zod-graphql-query-builder",
19
+ "version": "0.0.14",
20
+ "bom-ref": "pkg:npm/@schema-hub/zod-graphql-query-builder@0.0.14",
21
+ "purl": "pkg:npm/@schema-hub/zod-graphql-query-builder@0.0.14"
22
+ }
23
+ },
24
+ "components": [
25
+ {
26
+ "type": "library",
27
+ "name": "graphql",
28
+ "version": "16.14.0",
29
+ "bom-ref": "pkg:npm/graphql@16.14.0",
30
+ "scope": "required",
31
+ "licenses": [
32
+ {
33
+ "expression": "MIT"
34
+ }
35
+ ],
36
+ "purl": "pkg:npm/graphql@16.14.0"
37
+ },
38
+ {
39
+ "type": "library",
40
+ "name": "zod",
41
+ "version": "^4.0.5",
42
+ "bom-ref": "pkg:npm/zod@%5E4.0.5",
43
+ "scope": "optional",
44
+ "licenses": [
45
+ {
46
+ "expression": "MIT"
47
+ }
48
+ ],
49
+ "purl": "pkg:npm/zod@%5E4.0.5"
50
+ }
51
+ ],
52
+ "dependencies": [
53
+ {
54
+ "ref": "pkg:npm/@schema-hub/zod-graphql-query-builder@0.0.14",
55
+ "dependsOn": [
56
+ "pkg:npm/graphql@16.14.0",
57
+ "pkg:npm/zod@%5E4.0.5"
58
+ ]
59
+ },
60
+ {
61
+ "ref": "pkg:npm/graphql@16.14.0"
62
+ },
63
+ {
64
+ "ref": "pkg:npm/zod@%5E4.0.5"
65
+ }
66
+ ]
67
+ }
@@ -0,0 +1,4 @@
1
+ import type { FragmentDefinition } from './fragment-definitions.js';
2
+ import type { FieldSchema, FieldShape } from './query-schema.js';
3
+ import { type FieldOptionsRegistry } from './serializer.js';
4
+ //# sourceMappingURL=build-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-context.d.ts","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/build-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B;AACnE,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,mBAAmB;AAChE,OAAO,EAA2B,KAAK,oBAAoB,EAAE,MAAM,iBAAiB"}
@@ -0,0 +1,10 @@
1
+ import { collectSchemaReferences } from './serializer.js';
2
+ export function createBuildContext(registry, rootShape) {
3
+ return {
4
+ counts: collectSchemaReferences(registry, rootShape),
5
+ nameForSchema: new Map(),
6
+ counterPerTypeName: new Map(),
7
+ definitions: new Map()
8
+ };
9
+ }
10
+ //# sourceMappingURL=build-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-context.js","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/build-context.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAA6B,MAAM,iBAAiB,CAAC;AAWrF,MAAM,UAAU,kBAAkB,CAC9B,QAA8B,EAC9B,SAAqB;IAErB,OAAO;QACH,MAAM,EAAE,uBAAuB,CAAC,QAAQ,EAAE,SAAS,CAAC;QACpD,aAAa,EAAE,IAAI,GAAG,EAAE;QACxB,kBAAkB,EAAE,IAAI,GAAG,EAAE;QAC7B,WAAW,EAAE,IAAI,GAAG,EAAE;KACzB,CAAC;AACN,CAAC"}
@@ -1,19 +1,8 @@
1
- import { type FieldSchema, type QuerySchema } from './query-schema.js';
2
- import type { GraphqlValue } from './values/value.js';
1
+ import type { FieldSchema, QuerySchema } from './query-schema.js';
2
+ import { type GraphqlFieldOptions } from './serializer.js';
3
3
  import { type VariableDefinitions } from './variable-definition.js';
4
- type GraphqlFieldOptions = {
5
- aliasFor?: string;
6
- parameters?: Record<string, GraphqlValue>;
7
- };
8
4
  export type OperationOptions = {
9
5
  operationName?: string | undefined;
10
6
  variableDefinitions?: VariableDefinitions | undefined;
11
7
  };
12
- export type QueryBuilder = {
13
- registerFieldOptions: <Schema extends FieldSchema>(schema: Schema, options: GraphqlFieldOptions) => Schema;
14
- buildQuery: (schema: QuerySchema, options?: OperationOptions) => string;
15
- buildMutation: (schema: QuerySchema, options?: OperationOptions) => string;
16
- };
17
- export declare function createQueryBuilder(): QueryBuilder;
18
- export {};
19
8
  //# sourceMappingURL=builder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/builder.ts"],"names":[],"mappings":"AASA,OAAO,EAEH,KAAK,WAAW,EAWhB,KAAK,WAAW,EAKnB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,YAAY,EAA0B,MAAM,mBAAmB,CAAC;AAE9E,OAAO,EAAgC,KAAK,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AASlG,KAAK,mBAAmB,GAAG;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC3B,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,mBAAmB,CAAC,EAAE,mBAAmB,GAAG,SAAS,CAAC;CACzD,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACvB,oBAAoB,EAAE,CAAC,MAAM,SAAS,WAAW,EAC7C,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,mBAAmB,KAC3B,MAAM,CAAC;IACZ,UAAU,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,gBAAgB,KAAK,MAAM,CAAC;IACxE,aAAa,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,gBAAgB,KAAK,MAAM,CAAC;CAC9E,CAAC;AAkDF,wBAAgB,kBAAkB,IAAI,YAAY,CA8LjD"}
1
+ {"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/builder.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,mBAAmB;AAEjE,OAAO,EAEH,KAAK,mBAAmB,EAE3B,MAAM,iBAAiB;AAGxB,OAAO,EAAgC,KAAK,mBAAmB,EAAE,MAAM,0BAA0B;AAEjG,MAAM,MAAM,gBAAgB,GAAG;IAC3B,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,mBAAmB,CAAC,EAAE,mBAAmB,GAAG,SAAS,CAAC;CACzD"}
@@ -1,8 +1,8 @@
1
- /* eslint-disable no-underscore-dangle -- we need to access _zod */
2
- import { $ZodArray, $ZodDiscriminatedUnion, $ZodReadonly, $ZodUndefined } from 'zod/v4/core';
3
- import { isCustomScalarSchema } from './custom-scalar.js';
4
- import { isFragmentsSchema, isObjectOrListSchema, isStrictObjectSchema, isUnionOrListSchema, unwrapFieldSchema, unwrapFieldSchemaChain } from './query-schema.js';
5
- import { normalizeParameterList } from './values/parameter-list.js';
1
+ import { createBuildContext } from './build-context.js';
2
+ import { formatFragmentDefinitions } from './fragment-definitions.js';
3
+ import { extractRootShape } from './root-shape.js';
4
+ import { serializeRootShape } from './serializer.js';
5
+ import { isValidGraphqlName } from './values/name.js';
6
6
  import { ensureValidVariableCorrelations } from './variable-correlations.js';
7
7
  import { serializeVariableDefinitions } from './variable-definition.js';
8
8
  function withTrailingSpace(value) {
@@ -11,171 +11,31 @@ function withTrailingSpace(value) {
11
11
  }
12
12
  return `${value} `;
13
13
  }
14
- function unwrapFromArraySchema(predicate, schema) {
15
- const elementSchema = unwrapFieldSchema(schema._zod.def.element);
16
- if (predicate(elementSchema)) {
17
- return elementSchema;
18
- }
19
- return null;
20
- }
21
- function unwrapFromTupleSchema(predicate, schema) {
22
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment -- ts-expect-error doesn’t work reliably here
23
- // @ts-ignore - Type instantiation is not infinite
24
- const { items } = schema._zod.def;
25
- const [firstElementSchema] = items;
26
- const unwrappedElementSchema = unwrapFieldSchema(firstElementSchema);
27
- if (predicate(unwrappedElementSchema)) {
28
- return unwrappedElementSchema;
29
- }
30
- return null;
31
- }
32
- function getObjectSchema(schema) {
33
- if (isStrictObjectSchema(schema)) {
34
- return schema;
35
- }
36
- if (schema instanceof $ZodArray) {
37
- return unwrapFromArraySchema(isStrictObjectSchema, schema);
38
- }
39
- return unwrapFromTupleSchema(isStrictObjectSchema, schema);
40
- }
41
- function getUnionSchema(schema) {
42
- if (schema instanceof $ZodDiscriminatedUnion) {
43
- return schema;
44
- }
45
- if (schema instanceof $ZodArray) {
46
- return unwrapFromArraySchema(isFragmentsSchema, schema);
47
- }
48
- return unwrapFromTupleSchema(isFragmentsSchema, schema);
14
+ function buildDocument(registry, documentType, schema, options) {
15
+ const { variableDefinitions = {}, operationName = '' } = options;
16
+ const shape = extractRootShape(schema);
17
+ const context = createBuildContext(registry, shape);
18
+ const { bodyEntries, referencedVariables } = serializeRootShape(registry, shape, context);
19
+ ensureValidVariableCorrelations(variableDefinitions, referencedVariables);
20
+ const operationNameAndParams = withTrailingSpace(`${operationName}${serializeVariableDefinitions(variableDefinitions)}`);
21
+ const operationOutput = `${documentType} ${operationNameAndParams}{ ${bodyEntries.join(', ')} }`;
22
+ return operationOutput + formatFragmentDefinitions(context.definitions);
49
23
  }
50
24
  export function createQueryBuilder() {
51
25
  const fieldOptionsRegistry = new WeakMap();
52
- function getFieldOptionsForSchema(schema) {
53
- const unwrappingResult = unwrapFieldSchemaChain(schema);
54
- const queue = [...unwrappingResult.wrapperElements, unwrappingResult.unwrappedSchema];
55
- for (const currentSchema of queue) {
56
- const fieldOptions = fieldOptionsRegistry.get(currentSchema);
57
- if (fieldOptions !== undefined) {
58
- return fieldOptions;
59
- }
60
- }
61
- return {};
62
- }
63
- function serializedFieldSelector(fieldName, fieldSchema) {
64
- const fieldOptions = getFieldOptionsForSchema(fieldSchema);
65
- const { aliasFor, parameters } = fieldOptions;
66
- const selectorName = aliasFor === undefined ? fieldName : `${fieldName}: ${aliasFor}`;
67
- if (parameters !== undefined) {
68
- const normalizedParameterList = normalizeParameterList(parameters);
69
- return {
70
- serializedValue: `${selectorName}${normalizedParameterList.serializedValue}`,
71
- referencedVariables: normalizedParameterList.referencedVariables
72
- };
73
- }
74
- return {
75
- serializedValue: selectorName,
76
- referencedVariables: new Set()
77
- };
78
- }
79
- function serializeObjectSchema(objectSchema) {
80
- const entries = Object.entries(objectSchema._zod.def.shape);
81
- let referencedVariables = new Set();
82
- const serializedEntries = [];
83
- for (const [fieldName, fieldSchema] of entries) {
84
- // eslint-disable-next-line @typescript-eslint/no-use-before-define -- recursion
85
- const serializedField = serializeFieldSchema(fieldName, fieldSchema);
86
- referencedVariables = new Set([...referencedVariables, ...serializedField.referencedVariables]);
87
- serializedEntries.push(serializedField.serializedValue);
88
- }
89
- return {
90
- serializedValue: ` { ${serializedEntries.join(', ')} }`,
91
- referencedVariables
92
- };
93
- }
94
- // eslint-disable-next-line max-statements -- no good idea how to refactor at the moment
95
- function serializeFragments(discriminatorMap, unionOptions) {
96
- let referencedVariables = new Set();
97
- const serializedFragments = [];
98
- const typeNameDiscriminator = discriminatorMap.__typename;
99
- const fragmentNames = Array.from(typeNameDiscriminator ?? []);
100
- for (const [index, fragmentSchema] of unionOptions.entries()) {
101
- const fragmentName = fragmentNames[index];
102
- if (fragmentName === undefined || fragmentName === null) {
103
- throw new Error(`Fragment name for index ${index} is undefined`);
104
- }
105
- const serializedFragment = serializeObjectSchema(fragmentSchema);
106
- referencedVariables = new Set([...referencedVariables, ...serializedFragment.referencedVariables]);
107
- serializedFragments.push(`... on ${fragmentName.toString()}${serializedFragment.serializedValue}`);
108
- }
109
- return {
110
- serializedValue: ` { ${serializedFragments.join(', ')} }`,
111
- referencedVariables
112
- };
113
- }
114
- function combineFieldSelectorAndFieldBody(fieldSelector, fieldBody) {
115
- return {
116
- serializedValue: `${fieldSelector.serializedValue}${fieldBody.serializedValue}`,
117
- referencedVariables: new Set([
118
- ...fieldSelector.referencedVariables,
119
- ...fieldBody.referencedVariables
120
- ])
121
- };
122
- }
123
- // eslint-disable-next-line max-statements, complexity -- no good idea how to refactor at the moment
124
- function serializeFieldSchema(fieldName, fieldSchema) {
125
- const fieldSelector = serializedFieldSelector(fieldName, fieldSchema);
126
- if (isCustomScalarSchema(fieldSchema)) {
127
- return fieldSelector;
128
- }
129
- const unwrappedSchema = unwrapFieldSchema(fieldSchema);
130
- if (unwrappedSchema instanceof $ZodUndefined) {
131
- return { serializedValue: '', referencedVariables: new Set() };
132
- }
133
- if (isObjectOrListSchema(unwrappedSchema)) {
134
- const objectSchema = getObjectSchema(unwrappedSchema);
135
- if (objectSchema !== null) {
136
- return combineFieldSelectorAndFieldBody(fieldSelector, serializeObjectSchema(objectSchema));
137
- }
138
- }
139
- if (isUnionOrListSchema(unwrappedSchema)) {
140
- const unionSchema = getUnionSchema(unwrappedSchema);
141
- if (unionSchema !== null) {
142
- return combineFieldSelectorAndFieldBody(fieldSelector, serializeFragments(unionSchema._zod.propValues, unionSchema._zod.def.options));
143
- }
144
- }
145
- return fieldSelector;
146
- }
147
- // eslint-disable-next-line max-statements -- no idea right now to make this smaller
148
- function buildDocument(documentType, schema, options) {
149
- let referencedVariables = new Set();
150
- const { variableDefinitions = {}, operationName = '' } = options;
151
- const bodyEntries = [];
152
- const shape = schema instanceof $ZodReadonly ?
153
- schema._zod.def.innerType._zod.def.shape :
154
- schema._zod.def.shape;
155
- for (const [fieldName, fieldSchema] of Object.entries(shape)) {
156
- const serializedField = serializeFieldSchema(fieldName, fieldSchema);
157
- if (serializedField.serializedValue.length > 0) {
158
- bodyEntries.push(serializedField.serializedValue);
159
- }
160
- referencedVariables = new Set([
161
- ...referencedVariables,
162
- ...serializedField.referencedVariables
163
- ]);
164
- }
165
- ensureValidVariableCorrelations(variableDefinitions, referencedVariables);
166
- const operationNameAndParams = withTrailingSpace(`${operationName}${serializeVariableDefinitions(variableDefinitions)}`);
167
- return `${documentType} ${operationNameAndParams}{ ${bodyEntries.join(', ')} }`;
168
- }
169
26
  return {
170
27
  registerFieldOptions(schema, options) {
28
+ if (options.typeName !== undefined && !isValidGraphqlName(options.typeName)) {
29
+ throw new Error(`Invalid GraphQL type name: "${options.typeName}". A type name must match /^[A-Z_a-z]\\w*$/.`);
30
+ }
171
31
  fieldOptionsRegistry.set(schema, options);
172
32
  return schema;
173
33
  },
174
34
  buildQuery(schema, options = {}) {
175
- return buildDocument('query', schema, options);
35
+ return buildDocument(fieldOptionsRegistry, 'query', schema, options);
176
36
  },
177
37
  buildMutation(schema, options = {}) {
178
- return buildDocument('mutation', schema, options);
38
+ return buildDocument(fieldOptionsRegistry, 'mutation', schema, options);
179
39
  }
180
40
  };
181
41
  }
@@ -1 +1 @@
1
- {"version":3,"file":"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CAAC;IAE1F,+BAA+B,CAAC,mBAAmB,EAAE,mBAAmB,CAAC,CAAC;IAC1E,MAAM,sBAAsB,GAAG,iBAAiB,CAC5C,GAAG,aAAa,GAAG,4BAA4B,CAAC,mBAAmB,CAAC,EAAE,CACzE,CAAC;IACF,MAAM,eAAe,GAAG,GAAG,YAAY,IAAI,sBAAsB,KAAK,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;IACjG,OAAO,eAAe,GAAG,yBAAyB,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;AAC5E,CAAC;AAED,MAAM,UAAU,kBAAkB;IAC9B,MAAM,oBAAoB,GAAyB,IAAI,OAAO,EAAE,CAAC;IAEjE,OAAO;QACH,oBAAoB,CAChB,MAAc,EACd,OAA4B;YAE5B,IAAI,OAAO,CAAC,QAAQ,KAAK,SAAS,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAC1E,MAAM,IAAI,KAAK,CACX,+BAA+B,OAAO,CAAC,QAAQ,8CAA8C,CAChG,CAAC;YACN,CAAC;YACD,oBAAoB,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YAC1C,OAAO,MAAM,CAAC;QAClB,CAAC;QAED,UAAU,CAAC,MAAM,EAAE,OAAO,GAAG,EAAE;YAC3B,OAAO,aAAa,CAAC,oBAAoB,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QACzE,CAAC;QAED,aAAa,CAAC,MAAM,EAAE,OAAO,GAAG,EAAE;YAC9B,OAAO,aAAa,CAAC,oBAAoB,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QAC5E,CAAC;KACJ,CAAC;AACN,CAAC"}
@@ -3,7 +3,5 @@ declare const customScalarSymbol: unique symbol;
3
3
  export type CustomScalarSchema<Schema extends $ZodType> = $ZodLazy<Schema> & {
4
4
  [customScalarSymbol]: true;
5
5
  };
6
- export declare function isCustomScalarSchema(schema: $ZodType): schema is CustomScalarSchema<$ZodType>;
7
- export declare function createCustomScalarSchema<Schema extends $ZodType>(schema: Schema): CustomScalarSchema<Schema>;
8
6
  export {};
9
7
  //# sourceMappingURL=custom-scalar.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"custom-scalar.d.ts","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/custom-scalar.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEtD,QAAA,MAAM,kBAAkB,EAAE,OAAO,MAAgC,CAAC;AAElE,MAAM,MAAM,kBAAkB,CAAC,MAAM,SAAS,QAAQ,IAAI,QAAQ,CAAC,MAAM,CAAC,GAAG;IACzE,CAAC,kBAAkB,CAAC,EAAE,IAAI,CAAC;CAC9B,CAAC;AAEF,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,QAAQ,GAAG,MAAM,IAAI,kBAAkB,CAAC,QAAQ,CAAC,CAE7F;AAED,wBAAgB,wBAAwB,CAAC,MAAM,SAAS,QAAQ,EAC5D,MAAM,EAAE,MAAM,GACf,kBAAkB,CAAC,MAAM,CAAC,CAQ5B"}
1
+ {"version":3,"file":"custom-scalar.d.ts","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/custom-scalar.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa;AAErD,QAAA,MAAM,kBAAkB,EAAE,OAAO,MAAgC;AAEjE,MAAM,MAAM,kBAAkB,CAAC,MAAM,SAAS,QAAQ,IAAI,QAAQ,CAAC,MAAM,CAAC,GAAG;IACzE,CAAC,kBAAkB,CAAC,EAAE,IAAI,CAAC;CAC9B"}
@@ -3,11 +3,5 @@ const customScalarSymbol = Symbol('custom-scalar');
3
3
  export function isCustomScalarSchema(schema) {
4
4
  return Object.hasOwn(schema, customScalarSymbol);
5
5
  }
6
- export function createCustomScalarSchema(schema) {
7
- const wrappedSchema = z.lazy(() => {
8
- return schema;
9
- });
10
- wrappedSchema[customScalarSymbol] = true;
11
- return wrappedSchema;
12
- }
6
+
13
7
  //# sourceMappingURL=custom-scalar.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"custom-scalar.js","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/custom-scalar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,aAAa,CAAC;AAGhC,MAAM,kBAAkB,GAAkB,MAAM,CAAC,eAAe,CAAC,CAAC;AAMlE,MAAM,UAAU,oBAAoB,CAAC,MAAgB;IACjD,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;AACrD,CAAC;AAED,MAAM,UAAU,wBAAwB,CACpC,MAAc;IAEd,MAAM,aAAa,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;QAC9B,OAAO,MAAM,CAAC;IAClB,CAAC,CAA0C,CAAC;IAE5C,aAAa,CAAC,kBAAkB,CAAC,GAAG,IAAI,CAAC;IAEzC,OAAO,aAAa,CAAC;AACzB,CAAC"}
1
+ {"version":3,"file":"custom-scalar.js","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/custom-scalar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,aAAa;AAG/B,MAAM,kBAAkB,GAAkB,MAAM,CAAC,eAAe,CAAC;AAMjE,MAAM,UAAU,oBAAoB,CAAC,MAAgB;IACjD,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;AACrD"}
@@ -1,7 +1,4 @@
1
- export declare const graphqlFieldOptions: <Schema extends import("./query-schema.js").FieldSchema>(schema: Schema, options: {
2
- aliasFor?: string;
3
- parameters?: Record<string, import("./values/value.js").GraphqlValue>;
4
- }) => Schema;
1
+ export declare const graphqlFieldOptions: <Schema extends import("./query-schema.js").FieldSchema>(schema: Schema, options: import("./type-name.js").GraphqlFieldOptions) => Schema;
5
2
  export declare const buildGraphqlQuery: (schema: import("./query-schema.js").QuerySchema, options?: import("./builder.js").OperationOptions) => string;
6
3
  export declare const buildGraphqlMutation: (schema: import("./query-schema.js").QuerySchema, options?: import("./builder.js").OperationOptions) => string;
7
4
  export { createCustomScalarSchema as customScalar } from './custom-scalar.js';
@@ -1 +1 @@
1
- {"version":3,"file":"entry-point.d.ts","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/entry-point.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,mBAAmB;;;YAA+B,CAAC;AAChE,eAAO,MAAM,iBAAiB,gHAAqB,CAAC;AACpD,eAAO,MAAM,oBAAoB,gHAAwB,CAAC;AAE1D,OAAO,EAAE,wBAAwB,IAAI,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAEvE,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC"}
1
+ {"version":3,"file":"entry-point.d.ts","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/entry-point.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,mBAAmB,2IAA+B,CAAC;AAChE,eAAO,MAAM,iBAAiB,gHAAqB,CAAC;AACpD,eAAO,MAAM,oBAAoB,gHAAwB,CAAC;AAE1D,OAAO,EAAE,wBAAwB,IAAI,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAEvE,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=fragment-definitions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fragment-definitions.d.ts","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/fragment-definitions.ts"],"names":[],"mappings":""}
@@ -0,0 +1,15 @@
1
+ export function formatFragmentDefinitions(definitions) {
2
+ if (definitions.size === 0) {
3
+ return '';
4
+ }
5
+ const sortedEntries = Array
6
+ .from(definitions.entries())
7
+ .toSorted(([nameA], [nameB]) => {
8
+ return nameA.localeCompare(nameB);
9
+ });
10
+ const formatted = sortedEntries.map(([name, definition]) => {
11
+ return `fragment ${name} on ${definition.typeName}${definition.body}`;
12
+ });
13
+ return ` ${formatted.join(' ')}`;
14
+ }
15
+ //# sourceMappingURL=fragment-definitions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fragment-definitions.js","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/fragment-definitions.ts"],"names":[],"mappings":"AAMA,MAAM,UAAU,yBAAyB,CAAC,WAA4C;IAClF,IAAI,WAAW,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,EAAE,CAAC;IACd,CAAC;IACD,MAAM,aAAa,GAAG,KAAK;SACtB,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;SAC3B,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,EAAE;QAC3B,OAAO,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IACP,MAAM,SAAS,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,UAAU,CAAC,EAAE,EAAE;QACvD,OAAO,YAAY,IAAI,OAAO,UAAU,CAAC,QAAQ,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC;IAC1E,CAAC,CAAC,CAAC;IACH,OAAO,IAAI,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;AACrC,CAAC"}