@schema-hub/zod-graphql-query-builder 0.0.1
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.
- package/LICENSE +21 -0
- package/package.json +31 -0
- package/readme.md +130 -0
- package/zod-graphql-query-builder/builder.d.ts +19 -0
- package/zod-graphql-query-builder/builder.d.ts.map +1 -0
- package/zod-graphql-query-builder/builder.js +148 -0
- package/zod-graphql-query-builder/builder.js.map +1 -0
- package/zod-graphql-query-builder/entry-point.d.ts +8 -0
- package/zod-graphql-query-builder/entry-point.d.ts.map +1 -0
- package/zod-graphql-query-builder/entry-point.js +7 -0
- package/zod-graphql-query-builder/entry-point.js.map +1 -0
- package/zod-graphql-query-builder/query-schema.d.ts +29 -0
- package/zod-graphql-query-builder/query-schema.d.ts.map +1 -0
- package/zod-graphql-query-builder/query-schema.js +33 -0
- package/zod-graphql-query-builder/query-schema.js.map +1 -0
- package/zod-graphql-query-builder/values/enum.d.ts +7 -0
- package/zod-graphql-query-builder/values/enum.d.ts.map +1 -0
- package/zod-graphql-query-builder/values/enum.js +16 -0
- package/zod-graphql-query-builder/values/enum.js.map +1 -0
- package/zod-graphql-query-builder/values/name.js +5 -0
- package/zod-graphql-query-builder/values/name.js.map +1 -0
- package/zod-graphql-query-builder/values/parameter-list.js +19 -0
- package/zod-graphql-query-builder/values/parameter-list.js.map +1 -0
- package/zod-graphql-query-builder/values/record.js +7 -0
- package/zod-graphql-query-builder/values/record.js.map +1 -0
- package/zod-graphql-query-builder/values/value.d.ts +14 -0
- package/zod-graphql-query-builder/values/value.d.ts.map +1 -0
- package/zod-graphql-query-builder/values/value.js +71 -0
- package/zod-graphql-query-builder/values/value.js.map +1 -0
- package/zod-graphql-query-builder/values/variable-placeholder.d.ts +8 -0
- package/zod-graphql-query-builder/values/variable-placeholder.d.ts.map +1 -0
- package/zod-graphql-query-builder/values/variable-placeholder.js +19 -0
- package/zod-graphql-query-builder/values/variable-placeholder.js.map +1 -0
- package/zod-graphql-query-builder/variable-correlations.js +14 -0
- package/zod-graphql-query-builder/variable-correlations.js.map +1 -0
- package/zod-graphql-query-builder/variable-definition.d.ts +3 -0
- package/zod-graphql-query-builder/variable-definition.d.ts.map +1 -0
- package/zod-graphql-query-builder/variable-definition.js +25 -0
- package/zod-graphql-query-builder/variable-definition.js.map +1 -0
- package/zod-graphql-query-builder/variable-type.js +11 -0
- package/zod-graphql-query-builder/variable-type.js.map +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) [2024]
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"author": "Mathias Schreck <schreck.mathias@gmail.com>",
|
|
3
|
+
"dependencies": {
|
|
4
|
+
"graphql": "16.8.1"
|
|
5
|
+
},
|
|
6
|
+
"description": "Transforms Zod schemas into GraphQL queries",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": "^20"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"graphql",
|
|
12
|
+
"graphql-builder",
|
|
13
|
+
"graphql-query",
|
|
14
|
+
"query-builder",
|
|
15
|
+
"zod",
|
|
16
|
+
"zod-graphql"
|
|
17
|
+
],
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"main": "zod-graphql-query-builder/entry-point.js",
|
|
20
|
+
"name": "@schema-hub/zod-graphql-query-builder",
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"zod": "3.22.4"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+ssh://git@github.com/enormora/schema-hub.git"
|
|
27
|
+
},
|
|
28
|
+
"type": "module",
|
|
29
|
+
"types": "zod-graphql-query-builder/entry-point.d.ts",
|
|
30
|
+
"version": "0.0.1"
|
|
31
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# zod-graphql-query-builder
|
|
2
|
+
|
|
3
|
+
This library transforms a [`zod`](https://github.com/colinhacks/zod) schema into a GraphQL query.
|
|
4
|
+
|
|
5
|
+
## Example
|
|
6
|
+
|
|
7
|
+
**Input:**
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import { buildGraphqlQuery } from '@schema-hub/zod-graphql-query-builder';
|
|
11
|
+
import { z } from 'zod';
|
|
12
|
+
|
|
13
|
+
const mySchema = z.object({ foo: z.string() }).strict();
|
|
14
|
+
const query = buildGraphqlQuery(mySchema);
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
**Built query:**
|
|
18
|
+
|
|
19
|
+
```graphql
|
|
20
|
+
query { foo }
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Why?
|
|
24
|
+
|
|
25
|
+
- GraphQL has its own type system, requiring effort to map it to other type systems like TypeScript.
|
|
26
|
+
- Common alternatives, like code generation, suffer from issues such as potential out-of-sync generated code and lack of runtime validation.
|
|
27
|
+
- Utilizing `zod` schemas enables easy use of schemas for runtime validation.
|
|
28
|
+
- Even if we own the GraphQL server, we cannot always trust the types due to potential modifications by browser extensions or proxies. Hence, strict runtime verification of incoming data is crucial for robustness and debugging.
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm install @schema-hub/zod-graphql-query-builder
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
### Query Name
|
|
39
|
+
|
|
40
|
+
**Input:**
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
import { buildGraphqlQuery } from '@schema-hub/zod-graphql-query-builder';
|
|
44
|
+
import { z } from 'zod';
|
|
45
|
+
|
|
46
|
+
const mySchema = z.object({ foo: z.string() }).strict();
|
|
47
|
+
const query = buildGraphqlQuery(mySchema, { queryName: 'MyQuery' });
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
**Built query:**
|
|
51
|
+
|
|
52
|
+
```graphql
|
|
53
|
+
query MyQuery { foo }
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Defining an Alias
|
|
57
|
+
|
|
58
|
+
**Input:**
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
import { buildGraphqlQuery, graphqlFieldOptions } from '@schema-hub/zod-graphql-query-builder';
|
|
62
|
+
import { z } from 'zod';
|
|
63
|
+
|
|
64
|
+
const mySchema = z.object({ foo: graphqlFieldOptions(z.string(), { aliasFor: 'bar' }) }).strict();
|
|
65
|
+
const query = buildGraphqlQuery(mySchema);
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
**Built query:**
|
|
69
|
+
|
|
70
|
+
```graphql
|
|
71
|
+
query MyQuery { foo: bar }
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Defining Field Arguments / Parameters
|
|
75
|
+
|
|
76
|
+
**Input:**
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
import {
|
|
80
|
+
buildGraphqlQuery,
|
|
81
|
+
enumValue,
|
|
82
|
+
graphqlFieldOptions,
|
|
83
|
+
variablePlaceholder
|
|
84
|
+
} from '@schema-hub/zod-graphql-query-builder';
|
|
85
|
+
import { z } from 'zod';
|
|
86
|
+
|
|
87
|
+
const mySchema = z
|
|
88
|
+
.object({
|
|
89
|
+
foo: graphqlFieldOptions(z.string(), {
|
|
90
|
+
parameters: {
|
|
91
|
+
plainValue: 'plain-string',
|
|
92
|
+
enumParameter: enumValue('foo'),
|
|
93
|
+
variable: variablePlaceholder('$var')
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
})
|
|
97
|
+
.strict();
|
|
98
|
+
const query = buildGraphqlQuery(mySchema, { variableDefinitions: { $var: 'String!' } });
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**Built query:**
|
|
102
|
+
|
|
103
|
+
```graphql
|
|
104
|
+
query ($var: String!) { foo(plainValue: "plain-string", enumParameter: foo, variable: $var) }
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Defining Fragments
|
|
108
|
+
|
|
109
|
+
**Input:**
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
import { buildGraphqlQuery } from '@schema-hub/zod-graphql-query-builder';
|
|
113
|
+
import { z } from 'zod';
|
|
114
|
+
|
|
115
|
+
const mySchema = z
|
|
116
|
+
.object({
|
|
117
|
+
foo: z.discriminatedUnion('__typename', [
|
|
118
|
+
z.object({ __typename: 'A', valueA: z.string() }).strict(),
|
|
119
|
+
z.object({ __typename: 'B', valueB: z.number() }).strict()
|
|
120
|
+
])
|
|
121
|
+
})
|
|
122
|
+
.strict();
|
|
123
|
+
const query = buildGraphqlQuery(mySchema);
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
**Built query:**
|
|
127
|
+
|
|
128
|
+
```graphql
|
|
129
|
+
query { foo: { ... on A { __typename, valueA }, ... on B { __typename, valueB } } }
|
|
130
|
+
```
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type ZodLazy } from 'zod';
|
|
2
|
+
import { type FieldSchema, type QuerySchema } from './query-schema.js';
|
|
3
|
+
import type { GraphqlValue } from './values/value.js';
|
|
4
|
+
import { type VariableDefinitions } from './variable-definition.js';
|
|
5
|
+
type GraphqlFieldOptions = {
|
|
6
|
+
aliasFor?: string;
|
|
7
|
+
parameters?: Record<string, GraphqlValue>;
|
|
8
|
+
};
|
|
9
|
+
export type QueryOptions = {
|
|
10
|
+
queryName?: string;
|
|
11
|
+
variableDefinitions?: VariableDefinitions;
|
|
12
|
+
};
|
|
13
|
+
export type QueryBuilder = {
|
|
14
|
+
registerFieldOptions: <Schema extends FieldSchema>(schema: Schema, options: GraphqlFieldOptions) => ZodLazy<Schema>;
|
|
15
|
+
buildQuery: <Schema extends QuerySchema>(schema: Schema, options?: QueryOptions) => string;
|
|
16
|
+
};
|
|
17
|
+
export declare function createQueryBuilder(): QueryBuilder;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsC,KAAK,OAAO,EAAiB,MAAM,KAAK,CAAC;AACtF,OAAO,EACH,KAAK,WAAW,EAUhB,KAAK,WAAW,EAInB,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,YAAY,GAAG;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACvB,oBAAoB,EAAE,CAAC,MAAM,SAAS,WAAW,EAC7C,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,mBAAmB,KAC3B,OAAO,CAAC,MAAM,CAAC,CAAC;IACrB,UAAU,EAAE,CAAC,MAAM,SAAS,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,KAAK,MAAM,CAAC;CAC9F,CAAC;AA+CF,wBAAgB,kBAAkB,IAAI,YAAY,CA+IjD"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { z, ZodArray, ZodDiscriminatedUnion } from 'zod';
|
|
2
|
+
import { isFragmentsSchema, isObjectOrListSchema, isStrictObjectSchema, isUnionOrListSchema, unwrapFieldSchema } from './query-schema.js';
|
|
3
|
+
import { normalizeParameterList } from './values/parameter-list.js';
|
|
4
|
+
import { ensureValidVariableCorrelations } from './variable-correlations.js';
|
|
5
|
+
import { serializeVariableDefinitions } from './variable-definition.js';
|
|
6
|
+
function withTrailingSpace(value) {
|
|
7
|
+
if (value.length === 0) {
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
return `${value} `;
|
|
11
|
+
}
|
|
12
|
+
function unwrapFromArraySchema(predicate, schema) {
|
|
13
|
+
const elementSchema = unwrapFieldSchema(schema.element);
|
|
14
|
+
if (predicate(elementSchema)) {
|
|
15
|
+
return elementSchema;
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
function unwrapFromTupleSchema(predicate, schema) {
|
|
20
|
+
const [firstElementSchema] = schema.items;
|
|
21
|
+
const unwrappedElementSchema = unwrapFieldSchema(firstElementSchema);
|
|
22
|
+
if (predicate(unwrappedElementSchema)) {
|
|
23
|
+
return unwrappedElementSchema;
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
function getObjectSchema(schema) {
|
|
28
|
+
if (isStrictObjectSchema(schema)) {
|
|
29
|
+
return schema;
|
|
30
|
+
}
|
|
31
|
+
if (schema instanceof ZodArray) {
|
|
32
|
+
return unwrapFromArraySchema(isStrictObjectSchema, schema);
|
|
33
|
+
}
|
|
34
|
+
return unwrapFromTupleSchema(isStrictObjectSchema, schema);
|
|
35
|
+
}
|
|
36
|
+
function getUnionSchema(schema) {
|
|
37
|
+
if (schema instanceof ZodDiscriminatedUnion) {
|
|
38
|
+
return schema;
|
|
39
|
+
}
|
|
40
|
+
if (schema instanceof ZodArray) {
|
|
41
|
+
return unwrapFromArraySchema(isFragmentsSchema, schema);
|
|
42
|
+
}
|
|
43
|
+
return unwrapFromTupleSchema(isFragmentsSchema, schema);
|
|
44
|
+
}
|
|
45
|
+
export function createQueryBuilder() {
|
|
46
|
+
const fieldOptionsRegistry = new WeakMap();
|
|
47
|
+
function getFieldOptionsForSchema(schema) {
|
|
48
|
+
const fieldOptions = fieldOptionsRegistry.get(schema);
|
|
49
|
+
return fieldOptions ?? {};
|
|
50
|
+
}
|
|
51
|
+
function serializedFieldSelector(fieldName, fieldSchema) {
|
|
52
|
+
const fieldOptions = getFieldOptionsForSchema(fieldSchema);
|
|
53
|
+
const { aliasFor, parameters } = fieldOptions;
|
|
54
|
+
const selectorName = aliasFor === undefined ? fieldName : `${fieldName}: ${aliasFor}`;
|
|
55
|
+
if (parameters !== undefined) {
|
|
56
|
+
const normalizedParameterList = normalizeParameterList(parameters);
|
|
57
|
+
return {
|
|
58
|
+
serializedValue: `${selectorName}${normalizedParameterList.serializedValue}`,
|
|
59
|
+
referencedVariables: normalizedParameterList.referencedVariables
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
serializedValue: selectorName,
|
|
64
|
+
referencedVariables: new Set()
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function serializeObjectSchema(objectSchema) {
|
|
68
|
+
const entries = Object.entries(objectSchema.shape);
|
|
69
|
+
let referencedVariables = new Set();
|
|
70
|
+
const serializedEntries = [];
|
|
71
|
+
for (const [fieldName, fieldSchema] of entries) {
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define -- recursion
|
|
73
|
+
const serializedField = serializeFieldSchema(fieldName, fieldSchema);
|
|
74
|
+
referencedVariables = new Set([...referencedVariables, ...serializedField.referencedVariables]);
|
|
75
|
+
serializedEntries.push(serializedField.serializedValue);
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
serializedValue: ` { ${serializedEntries.join(', ')} }`,
|
|
79
|
+
referencedVariables
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function serializeFragments(unionOptions) {
|
|
83
|
+
let referencedVariables = new Set();
|
|
84
|
+
const serializedFragments = [];
|
|
85
|
+
for (const [fragmentName, fragmentSchema] of unionOptions.entries()) {
|
|
86
|
+
const serializedFragment = serializeObjectSchema(fragmentSchema);
|
|
87
|
+
referencedVariables = new Set([...referencedVariables, ...serializedFragment.referencedVariables]);
|
|
88
|
+
serializedFragments.push(`... on ${fragmentName}${serializedFragment.serializedValue}`);
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
serializedValue: ` { ${serializedFragments.join(', ')} }`,
|
|
92
|
+
referencedVariables
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function combineFieldSelectorAndFieldBody(fieldSelector, fieldBody) {
|
|
96
|
+
return {
|
|
97
|
+
serializedValue: `${fieldSelector.serializedValue}${fieldBody.serializedValue}`,
|
|
98
|
+
referencedVariables: new Set([
|
|
99
|
+
...fieldSelector.referencedVariables,
|
|
100
|
+
...fieldBody.referencedVariables
|
|
101
|
+
])
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
// eslint-disable-next-line max-statements -- no good idea how to refactor at the moment
|
|
105
|
+
function serializeFieldSchema(fieldName, fieldSchema) {
|
|
106
|
+
const fieldSelector = serializedFieldSelector(fieldName, fieldSchema);
|
|
107
|
+
const unwrappedSchema = unwrapFieldSchema(fieldSchema);
|
|
108
|
+
if (isObjectOrListSchema(unwrappedSchema)) {
|
|
109
|
+
const objectSchema = getObjectSchema(unwrappedSchema);
|
|
110
|
+
if (objectSchema !== null) {
|
|
111
|
+
return combineFieldSelectorAndFieldBody(fieldSelector, serializeObjectSchema(objectSchema));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (isUnionOrListSchema(unwrappedSchema)) {
|
|
115
|
+
const unionSchema = getUnionSchema(unwrappedSchema);
|
|
116
|
+
if (unionSchema !== null) {
|
|
117
|
+
return combineFieldSelectorAndFieldBody(fieldSelector, serializeFragments(unionSchema.optionsMap));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return fieldSelector;
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
registerFieldOptions(schema, options) {
|
|
124
|
+
const newSchemaInstance = z.lazy(() => {
|
|
125
|
+
return schema;
|
|
126
|
+
});
|
|
127
|
+
fieldOptionsRegistry.set(newSchemaInstance, options);
|
|
128
|
+
return newSchemaInstance;
|
|
129
|
+
},
|
|
130
|
+
buildQuery(schema, options = {}) {
|
|
131
|
+
let referencedVariables = new Set();
|
|
132
|
+
const { variableDefinitions = {}, queryName = '' } = options;
|
|
133
|
+
const bodyEntries = [];
|
|
134
|
+
for (const [fieldName, fieldSchema] of Object.entries(schema.shape)) {
|
|
135
|
+
const serializedField = serializeFieldSchema(fieldName, fieldSchema);
|
|
136
|
+
bodyEntries.push(serializedField.serializedValue);
|
|
137
|
+
referencedVariables = new Set([
|
|
138
|
+
...referencedVariables,
|
|
139
|
+
...serializedField.referencedVariables
|
|
140
|
+
]);
|
|
141
|
+
}
|
|
142
|
+
ensureValidVariableCorrelations(variableDefinitions, referencedVariables);
|
|
143
|
+
const queryNameAndParams = withTrailingSpace(`${queryName}${serializeVariableDefinitions(variableDefinitions)}`);
|
|
144
|
+
return `query ${queryNameAndParams}{ ${bodyEntries.join(', ')} }`;
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.js","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,qBAAqB,EAA+B,MAAM,KAAK,CAAC;AACtF,OAAO,EAMH,iBAAiB,EACjB,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,EAKnB,iBAAiB,EACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAEpE,OAAO,EAAE,+BAA+B,EAAE,MAAM,4BAA4B,CAAC;AAC7E,OAAO,EAAE,4BAA4B,EAA4B,MAAM,0BAA0B,CAAC;AAElG,SAAS,iBAAiB,CAAC,KAAa;IACpC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrB,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,OAAO,GAAG,KAAK,GAAG,CAAC;AACvB,CAAC;AAoBD,SAAS,qBAAqB,CAC1B,SAAwD,EACxD,MAA6B;IAE7B,MAAM,aAAa,GAAG,iBAAiB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACxD,IAAI,SAAS,CAAC,aAAa,CAAC,EAAE,CAAC;QAC3B,OAAO,aAAa,CAAC;IACzB,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,SAAS,qBAAqB,CAC1B,SAAwD,EACxD,MAAiD;IAEjD,MAAM,CAAC,kBAAkB,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC;IAC1C,MAAM,sBAAsB,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O,SAAS,kBAAkB,KAAK,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;QACtE,CAAC;KACJ,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
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
|
+
}) => import("zod").ZodLazy<Schema>;
|
|
5
|
+
export declare const buildGraphqlQuery: <Schema extends import("./query-schema.js").QuerySchema>(schema: Schema, options?: import("./builder.js").QueryOptions | undefined) => string;
|
|
6
|
+
export { enumValue } from './values/enum.js';
|
|
7
|
+
export { variablePlaceholder } from './values/variable-placeholder.js';
|
|
8
|
+
//# sourceMappingURL=entry-point.d.ts.map
|
|
@@ -0,0 +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;;;mCAA+B,CAAC;AAChE,eAAO,MAAM,iBAAiB,+IAAqB,CAAC;AAEpD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createQueryBuilder } from './builder.js';
|
|
2
|
+
const builder = createQueryBuilder();
|
|
3
|
+
export const graphqlFieldOptions = builder.registerFieldOptions;
|
|
4
|
+
export const buildGraphqlQuery = builder.buildQuery;
|
|
5
|
+
export { enumValue } from './values/enum.js';
|
|
6
|
+
export { variablePlaceholder } from './values/variable-placeholder.js';
|
|
7
|
+
//# sourceMappingURL=entry-point.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-point.js","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/entry-point.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElD,MAAM,OAAO,GAAG,kBAAkB,EAAE,CAAC;AAErC,MAAM,CAAC,MAAM,mBAAmB,GAAG,OAAO,CAAC,oBAAoB,CAAC;AAChE,MAAM,CAAC,MAAM,iBAAiB,GAAG,OAAO,CAAC,UAAU,CAAC;AAEpD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ZodArray, type ZodBoolean, ZodDiscriminatedUnion, ZodEffects, ZodLazy, type ZodLiteral, type ZodNull, ZodNullable, type ZodNumber, ZodObject, type ZodRawShape, type ZodString, ZodTuple, type ZodTypeAny } from 'zod';
|
|
2
|
+
export interface StrictObjectSchema<Shape extends ZodRawShape> extends Omit<ZodObject<Shape, 'strict'>, 'deepPartial' | 'keyof'> {
|
|
3
|
+
}
|
|
4
|
+
export declare function isStrictObjectSchema(schema: unknown): schema is StrictObjectSchema<FieldShape>;
|
|
5
|
+
interface EffectSchema<Schema extends ZodTypeAny> extends ZodEffects<Schema> {
|
|
6
|
+
}
|
|
7
|
+
type LiteralSchema = ZodLiteral<null> | ZodLiteral<number> | ZodLiteral<string>;
|
|
8
|
+
type PrimitiveSchema = LiteralSchema | ZodBoolean | ZodNull | ZodNumber | ZodString;
|
|
9
|
+
export type FragmentTypeName = boolean | number | string | null;
|
|
10
|
+
export declare type FragmentUnionOptionSchema = ZodObject<FieldShape & {
|
|
11
|
+
__typename: PrimitiveSchema;
|
|
12
|
+
}, 'strict'>;
|
|
13
|
+
export type FieldShape = {
|
|
14
|
+
readonly [FieldName: string]: FieldSchema;
|
|
15
|
+
};
|
|
16
|
+
export type NonWrappedFieldSchema = PrimitiveSchema | StrictObjectSchema<FieldShape> | ZodArray<FieldSchema> | ZodDiscriminatedUnion<'__typename', FragmentUnionOptionSchema[]> | ZodTuple<[FieldSchema, ...FieldSchema[]]>;
|
|
17
|
+
export type WrappedFieldSchema = EffectSchema<FieldSchema> | ZodLazy<FieldSchema> | ZodNullable<FieldSchema>;
|
|
18
|
+
export type FieldSchema = NonWrappedFieldSchema | WrappedFieldSchema;
|
|
19
|
+
export declare function unwrapFieldSchema(parent: FieldSchema): NonWrappedFieldSchema;
|
|
20
|
+
type QueryShape = Record<string, FieldSchema>;
|
|
21
|
+
export type QuerySchema = StrictObjectSchema<QueryShape>;
|
|
22
|
+
export type ObjectOrListSchema = StrictObjectSchema<FieldShape> | ZodArray<FieldSchema> | ZodTuple<[FieldSchema, ...FieldSchema[]]>;
|
|
23
|
+
export declare function isObjectOrListSchema(schema: FieldSchema): schema is ObjectOrListSchema;
|
|
24
|
+
export type FragmentsSchema = ZodDiscriminatedUnion<'__typename', FragmentUnionOptionSchema[]>;
|
|
25
|
+
export declare function isFragmentsSchema(schema: FieldSchema): schema is FragmentsSchema;
|
|
26
|
+
export type UnionOrListSchema = FragmentsSchema | ZodArray<FieldSchema> | ZodTuple<[FieldSchema, ...FieldSchema[]]>;
|
|
27
|
+
export declare function isUnionOrListSchema(schema: FieldSchema): schema is UnionOrListSchema;
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=query-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-schema.d.ts","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/query-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,QAAQ,EACR,KAAK,UAAU,EACf,qBAAqB,EACrB,UAAU,EACV,OAAO,EACP,KAAK,UAAU,EACf,KAAK,OAAO,EACZ,WAAW,EACX,KAAK,SAAS,EACd,SAAS,EACT,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,QAAQ,EACR,KAAK,UAAU,EAClB,MAAM,KAAK,CAAC;AAGb,MAAM,WAAW,kBAAkB,CAAC,KAAK,SAAS,WAAW,CACzD,S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AAE,WAAW,GAAG,qBAAqB,CAgB5E;AAED,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;AAC9C,MAAM,MAAM,WAAW,GAAG,kBAAkB,CAAC,UAAU,CAAC,CAAC;AAEzD,MAAM,MAAM,kBAAkB,GACxB,kBAAkB,CAAC,UAAU,CAAC,GAC9B,QAAQ,CAAC,WAAW,CAAC,GACrB,QAAQ,CAAC,CAAC,WAAW,EAAE,GAAG,WAAW,EAAE,CAAC,CAAC,CAAC;AAEhD,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,IAAI,kBAAkB,CAEtF;AAED,MAAM,MAAM,eAAe,GAAG,qBAAqB,CAAC,YAAY,EAAE,yBAAyB,EAAE,CAAC,CAAC;AAE/F,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,IAAI,eAAe,CAEhF;AAED,MAAM,MAAM,iBAAiB,GAAG,eAAe,GAAG,QAAQ,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAC,CAAC,WAAW,EAAE,GAAG,WAAW,EAAE,CAAC,CAAC,CAAC;AAEpH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,IAAI,iBAAiB,CAEpF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ZodArray, ZodDiscriminatedUnion, ZodEffects, ZodLazy, ZodNullable, ZodObject, ZodTuple } from 'zod';
|
|
2
|
+
export function isStrictObjectSchema(schema) {
|
|
3
|
+
return schema instanceof ZodObject;
|
|
4
|
+
}
|
|
5
|
+
function isWrappedFieldSchema(schema) {
|
|
6
|
+
return schema instanceof ZodLazy || schema instanceof ZodEffects || schema instanceof ZodNullable;
|
|
7
|
+
}
|
|
8
|
+
export function unwrapFieldSchema(parent) {
|
|
9
|
+
let unwrapped = parent;
|
|
10
|
+
if (parent instanceof ZodLazy) {
|
|
11
|
+
unwrapped = parent.schema;
|
|
12
|
+
}
|
|
13
|
+
else if (parent instanceof ZodEffects) {
|
|
14
|
+
unwrapped = parent.innerType();
|
|
15
|
+
}
|
|
16
|
+
else if (parent instanceof ZodNullable) {
|
|
17
|
+
unwrapped = parent.unwrap();
|
|
18
|
+
}
|
|
19
|
+
if (isWrappedFieldSchema(unwrapped)) {
|
|
20
|
+
return unwrapFieldSchema(unwrapped);
|
|
21
|
+
}
|
|
22
|
+
return unwrapped;
|
|
23
|
+
}
|
|
24
|
+
export function isObjectOrListSchema(schema) {
|
|
25
|
+
return isStrictObjectSchema(schema) || schema instanceof ZodArray || schema instanceof ZodTuple;
|
|
26
|
+
}
|
|
27
|
+
export function isFragmentsSchema(schema) {
|
|
28
|
+
return schema instanceof ZodDiscriminatedUnion;
|
|
29
|
+
}
|
|
30
|
+
export function isUnionOrListSchema(schema) {
|
|
31
|
+
return isFragmentsSchema(schema) || schema instanceof ZodArray || schema instanceof ZodTuple;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=query-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-schema.js","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/query-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,QAAQ,EAER,qBAAqB,EACrB,UAAU,EACV,OAAO,EAGP,WAAW,EAEX,SAAS,EAGT,QAAQ,EAEX,MAAM,KAAK,CAAC;AAMb,MAAM,UAAU,oBAAoB,CAAC,MAAe;IAChD,OAAO,MAAM,YAAY,SAAS,CAAC;AACvC,CAAC;AA4BD,SAAS,oBAAoB,CAAC,MAAmB;IAC7C,OAAO,MAAM,YAAY,OAAO,IAAI,MAAM,YAAY,UAAU,IAAI,MAAM,YAAY,WAAW,CAAC;AACtG,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,MAAmB;IACjD,IAAI,SAAS,GAAgB,MAAM,CAAC;IAEpC,IAAI,MAAM,YAAY,OAAO,EAAE,CAAC;QAC5B,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC;IAC9B,CAAC;SAAM,IAAI,MAAM,YAAY,UAAU,EAAE,CAAC;QACtC,SAAS,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;IACnC,CAAC;SAAM,IAAI,MAAM,YAAY,WAAW,EAAE,CAAC;QACvC,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;IAChC,CAAC;IAED,IAAI,oBAAoB,CAAC,SAAS,CAAC,EAAE,CAAC;QAClC,OAAO,iBAAiB,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC;IAED,OAAO,SAAS,CAAC;AACrB,CAAC;AAUD,MAAM,UAAU,oBAAoB,CAAC,MAAmB;IACpD,OAAO,oBAAoB,CAAC,MAAM,CAAC,IAAI,MAAM,YAAY,QAAQ,IAAI,MAAM,YAAY,QAAQ,CAAC;AACpG,CAAC;AAID,MAAM,UAAU,iBAAiB,CAAC,MAAmB;IACjD,OAAO,MAAM,YAAY,qBAAqB,CAAC;AACnD,CAAC;AAID,MAAM,UAAU,mBAAmB,CAAC,MAAmB;IACnD,OAAO,iBAAiB,CAAC,MAAM,CAAC,IAAI,MAAM,YAAY,QAAQ,IAAI,MAAM,YAAY,QAAQ,CAAC;AACjG,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type GraphqlEnumValue = {
|
|
2
|
+
readonly enumValue: string;
|
|
3
|
+
readonly tag: symbol;
|
|
4
|
+
};
|
|
5
|
+
export declare function isEnumValue(value: unknown): value is GraphqlEnumValue;
|
|
6
|
+
export declare function enumValue(value: string): GraphqlEnumValue;
|
|
7
|
+
//# sourceMappingURL=enum.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enum.d.ts","sourceRoot":"","sources":["../../../../../source/zod-graphql-query-builder/values/enum.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,gBAAgB,GAAG;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACxB,CAAC;AAIF,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,gBAAgB,CAErE;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,gBAAgB,CASzD"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { isValidGraphqlName } from './name.js';
|
|
2
|
+
import { hasProperty, isRecord } from './record.js';
|
|
3
|
+
const enumValueSymbol = Symbol('GraphQL enum value');
|
|
4
|
+
export function isEnumValue(value) {
|
|
5
|
+
return isRecord(value) && hasProperty(value, 'tag') && value.tag === enumValueSymbol;
|
|
6
|
+
}
|
|
7
|
+
export function enumValue(value) {
|
|
8
|
+
if (!isValidGraphqlName(value)) {
|
|
9
|
+
throw new Error(`Enum value "${value}" is not a valid enum value`);
|
|
10
|
+
}
|
|
11
|
+
return {
|
|
12
|
+
enumValue: value,
|
|
13
|
+
tag: enumValueSymbol
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=enum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enum.js","sourceRoot":"","sources":["../../../../../source/zod-graphql-query-builder/values/enum.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAOpD,MAAM,eAAe,GAAG,MAAM,CAAC,oBAAoB,CAAC,CAAC;AAErD,MAAM,UAAU,WAAW,CAAC,KAAc;IACtC,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,WAAW,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,KAAK,CAAC,GAAG,KAAK,eAAe,CAAC;AACzF,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,KAAa;IACnC,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,eAAe,KAAK,6BAA6B,CAAC,CAAC;IACvE,CAAC;IAED,OAAO;QACH,SAAS,EAAE,KAAK;QAChB,GAAG,EAAE,eAAe;KACvB,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"name.js","sourceRoot":"","sources":["../../../../../source/zod-graphql-query-builder/values/name.ts"],"names":[],"mappings":"AAAA,MAAM,kBAAkB,GAAG,gBAAgB,CAAC;AAE5C,MAAM,UAAU,kBAAkB,CAAC,KAAa;IAC5C,OAAO,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { isValidGraphqlName } from './name.js';
|
|
2
|
+
import { normalizeGraphqlValue } from './value.js';
|
|
3
|
+
export function normalizeParameterList(parameters) {
|
|
4
|
+
let referencedVariables = new Set();
|
|
5
|
+
const serializedParameters = [];
|
|
6
|
+
for (const [parameterName, parameterValue] of Object.entries(parameters)) {
|
|
7
|
+
if (!isValidGraphqlName(parameterName)) {
|
|
8
|
+
throw new Error(`Parameter name "${parameterName}" is not a valid GraphQL parameter name`);
|
|
9
|
+
}
|
|
10
|
+
const normalizedParameterValue = normalizeGraphqlValue(parameterValue);
|
|
11
|
+
serializedParameters.push(`${parameterName}: ${normalizedParameterValue.serializedValue}`);
|
|
12
|
+
referencedVariables = new Set([...referencedVariables, ...normalizedParameterValue.referencedVariables]);
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
serializedValue: serializedParameters.length > 0 ? `(${serializedParameters.join(', ')})` : '',
|
|
16
|
+
referencedVariables
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=parameter-list.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parameter-list.js","sourceRoot":"","sources":["../../../../../source/zod-graphql-query-builder/values/parameter-list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EA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AI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAChF,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type GraphqlEnumValue } from './enum.js';
|
|
2
|
+
import { type GraphqlVariablePlaceholder } from './variable-placeholder.js';
|
|
3
|
+
type GraphqlObjectValue = {
|
|
4
|
+
[Key: string]: GraphqlValue;
|
|
5
|
+
};
|
|
6
|
+
type GraphqlPrimitiveValue = boolean | number | string | null;
|
|
7
|
+
export type GraphqlValue = GraphqlEnumValue | GraphqlObjectValue | GraphqlPrimitiveValue | GraphqlValue[] | GraphqlVariablePlaceholder;
|
|
8
|
+
export type NormalizedGraphqlValue = {
|
|
9
|
+
serializedValue: string;
|
|
10
|
+
referencedVariables: Set<string>;
|
|
11
|
+
};
|
|
12
|
+
export declare function normalizeGraphqlValue(value: GraphqlValue): NormalizedGraphqlValue;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=value.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value.d.ts","sourceRoot":"","sources":["../../../../../source/zod-graphql-query-builder/values/value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAe,MAAM,WAAW,CAAC;AAG/D,OAAO,EAAE,KAAK,0BAA0B,EAAyB,MAAM,2BAA2B,CAAC;AAGnG,KAAK,kBAAkB,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAAC;CAAE,CAAC;AAM3D,KAAK,qBAAqB,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;AAO9D,MAAM,MAAM,YAAY,GAClB,gBAAgB,GAChB,kBAAkB,GAClB,qBAAqB,GACrB,YAAY,EAAE,GACd,0BAA0B,CAAC;AAEjC,MAAM,MAAM,sBAAsB,GAAG;IACjC,eAAe,EAAE,MAAM,CAAC;IACxB,mBAAmB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CACpC,CAAC;AA0CF,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,YAAY,GAAG,sBAAsB,CA0BjF"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { isEnumValue } from './enum.js';
|
|
2
|
+
import { isValidGraphqlName } from './name.js';
|
|
3
|
+
import { isRecord } from './record.js';
|
|
4
|
+
import { isVariablePlaceholder } from './variable-placeholder.js';
|
|
5
|
+
function isObjectValue(value) {
|
|
6
|
+
return isRecord(value) && !isEnumValue(value) && !isVariablePlaceholder(value);
|
|
7
|
+
}
|
|
8
|
+
function isPrimitive(value) {
|
|
9
|
+
const type = typeof value;
|
|
10
|
+
return value === null || type === 'number' || type === 'string' || type === 'boolean';
|
|
11
|
+
}
|
|
12
|
+
function serializePrimitiveValue(value) {
|
|
13
|
+
return JSON.stringify(value);
|
|
14
|
+
}
|
|
15
|
+
function normalizeObjectValue(value) {
|
|
16
|
+
let referencedVariables = new Set();
|
|
17
|
+
const serializedFields = [];
|
|
18
|
+
for (const [fieldName, fieldValue] of Object.entries(value)) {
|
|
19
|
+
if (!isValidGraphqlName(fieldName)) {
|
|
20
|
+
throw new Error(`Field name "${fieldName}" is not a valid GraphQL field name`);
|
|
21
|
+
}
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define -- mutual recursion
|
|
23
|
+
const normalizedFieldValue = normalizeGraphqlValue(fieldValue);
|
|
24
|
+
serializedFields.push(`${fieldName}: ${normalizedFieldValue.serializedValue}`);
|
|
25
|
+
referencedVariables = new Set([...referencedVariables, ...normalizedFieldValue.referencedVariables]);
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
serializedValue: `{${serializedFields.join(', ')}}`,
|
|
29
|
+
referencedVariables
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function normalizeListValue(value) {
|
|
33
|
+
let referencedVariables = new Set();
|
|
34
|
+
const serializedItems = [];
|
|
35
|
+
for (const item of value) {
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define -- mutual recursion
|
|
37
|
+
const normalizedItem = normalizeGraphqlValue(item);
|
|
38
|
+
serializedItems.push(normalizedItem.serializedValue);
|
|
39
|
+
referencedVariables = new Set([...referencedVariables, ...normalizedItem.referencedVariables]);
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
serializedValue: `[${serializedItems.join(', ')}]`,
|
|
43
|
+
referencedVariables
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export function normalizeGraphqlValue(value) {
|
|
47
|
+
const referencedVariables = new Set();
|
|
48
|
+
if (isPrimitive(value)) {
|
|
49
|
+
return {
|
|
50
|
+
serializedValue: serializePrimitiveValue(value),
|
|
51
|
+
referencedVariables
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
if (isEnumValue(value)) {
|
|
55
|
+
return {
|
|
56
|
+
serializedValue: value.enumValue,
|
|
57
|
+
referencedVariables
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
if (isVariablePlaceholder(value)) {
|
|
61
|
+
return {
|
|
62
|
+
serializedValue: value.variableName,
|
|
63
|
+
referencedVariables: new Set([...referencedVariables, value.variableName])
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
if (isObjectValue(value)) {
|
|
67
|
+
return normalizeObjectValue(value);
|
|
68
|
+
}
|
|
69
|
+
return normalizeListValue(value);
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=value.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value.js","sourceRoot":"","sources":["../../../../../source/zod-graphql-query-builder/values/value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,WAAW,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAmC,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;A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KAAK,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type GraphqlVariablePlaceholder = {
|
|
2
|
+
readonly variableName: string;
|
|
3
|
+
readonly tag: symbol;
|
|
4
|
+
};
|
|
5
|
+
export declare function isVariablePlaceholder(value: unknown): value is GraphqlVariablePlaceholder;
|
|
6
|
+
export declare function isValidVariableIdentifier(value: string): boolean;
|
|
7
|
+
export declare function variablePlaceholder(variableName: string): GraphqlVariablePlaceholder;
|
|
8
|
+
//# sourceMappingURL=variable-placeholder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variable-placeholder.d.ts","sourceRoot":"","sources":["../../../../../source/zod-graphql-query-builder/values/variable-placeholder.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,0BAA0B,GAAG;IACrC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACxB,CAAC;AAIF,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,0BAA0B,CAEzF;AAID,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEhE;AAED,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,MAAM,GAAG,0BAA0B,CASpF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { hasProperty, isRecord } from './record.js';
|
|
2
|
+
const variablePlaceholderSymbol = Symbol('GraphQL Variable Placeholder');
|
|
3
|
+
export function isVariablePlaceholder(value) {
|
|
4
|
+
return isRecord(value) && hasProperty(value, 'tag') && value.tag === variablePlaceholderSymbol;
|
|
5
|
+
}
|
|
6
|
+
const graphqlVariableIdentifierPattern = /^\$[A-Z_a-z]\w*$/;
|
|
7
|
+
export function isValidVariableIdentifier(value) {
|
|
8
|
+
return graphqlVariableIdentifierPattern.test(value);
|
|
9
|
+
}
|
|
10
|
+
export function variablePlaceholder(variableName) {
|
|
11
|
+
if (!isValidVariableIdentifier(variableName)) {
|
|
12
|
+
throw new Error(`Variable "${variableName}" is not a valid variable name`);
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
variableName,
|
|
16
|
+
tag: variablePlaceholderSymbol
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=variable-placeholder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variable-placeholder.js","sourceRoot":"","sources":["../../../../../source/zod-graphql-query-builder/values/variable-placeholder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAOpD,MAAM,yBAAyB,GAAG,MAAM,CAAC,8BAA8B,CAAC,CAAC;AAEzE,MAAM,UAAU,qBAAqB,CAAC,KAAc;IAChD,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,WAAW,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,KAAK,CAAC,GAAG,KAAK,yBAAyB,CAAC;AACnG,CAAC;AAED,MAAM,gCAAgC,GAAG,kBAAkB,CAAC;AAE5D,MAAM,UAAU,yBAAyB,CAAC,KAAa;IACnD,OAAO,gCAAgC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACxD,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,YAAoB;IACpD,IAAI,CAAC,yBAAyB,CAAC,YAAY,CAAC,EAAE,CAAC;QAC3C,MAAM,IAAI,KAAK,CAAC,aAAa,YAAY,gCAAgC,CAAC,CAAC;IAC/E,CAAC;IAED,OAAO;QACH,YAAY;QACZ,GAAG,EAAE,yBAAyB;KACjC,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function ensureValidVariableCorrelations(variableDefinitions, referencedVariables) {
|
|
2
|
+
const unusedVariableDefinitions = new Set(Object.keys(variableDefinitions));
|
|
3
|
+
for (const referencedVariable of referencedVariables) {
|
|
4
|
+
unusedVariableDefinitions.delete(referencedVariable);
|
|
5
|
+
if (!Object.hasOwn(variableDefinitions, referencedVariable)) {
|
|
6
|
+
throw new Error(`Referenced variable "${referencedVariable}" is missing in variableDefinitions`);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
const [firstUnusedVariable] = Array.from(unusedVariableDefinitions);
|
|
10
|
+
if (firstUnusedVariable !== undefined) {
|
|
11
|
+
throw new Error(`Variable definition for "${firstUnusedVariable}" is never referenced`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=variable-correlations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variable-correlations.js","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/variable-correlations.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,+BAA+B,CAC3C,mBAAwC,EACxC,mBAAgC;IAEhC,MAAM,yBAAyB,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAC;IAE5E,KAAK,MAAM,kBAAkB,IAAI,mBAAmB,EAAE,CAAC;QACnD,yBAAyB,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;QACrD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,mBAAmB,EAAE,kBAAkB,CAAC,EAAE,CAAC;YAC1D,MAAM,IAAI,KAAK,CAAC,wBAAwB,kBAAkB,qCAAqC,CAAC,CAAC;QACrG,CAAC;IACL,CAAC;IAED,MAAM,CAAC,mBAAmB,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;IACpE,IAAI,mBAAmB,KAAK,SAAS,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CAAC,4BAA4B,mBAAmB,uBAAuB,CAAC,CAAC;IAC5F,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variable-definition.d.ts","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/variable-definition.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAoBzD,wBAAgB,4BAA4B,CAAC,WAAW,EAAE,mBAAmB,GAAG,MAAM,CAWrF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { isValidVariableIdentifier } from './values/variable-placeholder.js';
|
|
2
|
+
import { isValidGraphqlType } from './variable-type.js';
|
|
3
|
+
function ensureValidVariableDefinition(variableDefinition) {
|
|
4
|
+
const [variableName, variableType] = variableDefinition;
|
|
5
|
+
if (!isValidVariableIdentifier(variableName)) {
|
|
6
|
+
throw new Error(`Variable name "${variableName}" is not a valid GraphQL variable name`);
|
|
7
|
+
}
|
|
8
|
+
if (!isValidGraphqlType(variableType)) {
|
|
9
|
+
throw new Error(`Type "${variableType}" for variable "${variableName}" is invalid`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function serializeVariableDefinitionPair(variableDefinition) {
|
|
13
|
+
const [variableName, variableType] = variableDefinition;
|
|
14
|
+
return `${variableName}: ${variableType}`;
|
|
15
|
+
}
|
|
16
|
+
export function serializeVariableDefinitions(definitions) {
|
|
17
|
+
const entries = Object.entries(definitions);
|
|
18
|
+
if (entries.length === 0) {
|
|
19
|
+
return '';
|
|
20
|
+
}
|
|
21
|
+
entries.forEach(ensureValidVariableDefinition);
|
|
22
|
+
const serializedEntries = entries.map(serializeVariableDefinitionPair);
|
|
23
|
+
return `(${serializedEntries.join(', ')})`;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=variable-definition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variable-definition.js","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/variable-definition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAC;AAC7E,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,C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CAAC;IAChB,CAAC;IAAC,MAAM,CAAC;QACL,OAAO,KAAK,CAAC;IACjB,CAAC;AACL,CAAC"}
|