@constructive-io/graphql-query 2.4.7 → 2.5.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.
@@ -0,0 +1,47 @@
1
+ import type { FieldSelection, IntrospectionSchema, MetaObject, QueryBuilderOptions, QueryBuilderResult, QueryDefinition, SelectionOptions } from './types';
2
+ export * as MetaObject from './meta-object';
3
+ export declare class QueryBuilder {
4
+ _introspection: IntrospectionSchema;
5
+ _meta: MetaObject;
6
+ private _models;
7
+ private _model;
8
+ private _fields;
9
+ private _key;
10
+ private _queryName;
11
+ private _ast;
12
+ _edges: boolean;
13
+ private _op;
14
+ private _mutation;
15
+ private _select;
16
+ constructor({ meta, introspection }: QueryBuilderOptions);
17
+ initModelMap(): void;
18
+ clear(): void;
19
+ query(model: string): QueryBuilder;
20
+ _findQuery(): string;
21
+ _findMutation(): string;
22
+ select(selection?: SelectionOptions | null): QueryBuilder;
23
+ edges(useEdges: boolean): QueryBuilder;
24
+ getMany({ select }?: {
25
+ select?: SelectionOptions;
26
+ }): QueryBuilder;
27
+ all({ select }?: {
28
+ select?: SelectionOptions;
29
+ }): QueryBuilder;
30
+ count(): QueryBuilder;
31
+ getOne({ select }?: {
32
+ select?: SelectionOptions;
33
+ }): QueryBuilder;
34
+ create({ select }?: {
35
+ select?: SelectionOptions;
36
+ }): QueryBuilder;
37
+ delete({ select }?: {
38
+ select?: SelectionOptions;
39
+ }): QueryBuilder;
40
+ update({ select }?: {
41
+ select?: SelectionOptions;
42
+ }): QueryBuilder;
43
+ queryName(name: string): QueryBuilder;
44
+ print(): QueryBuilderResult;
45
+ pickScalarFields: (selection: SelectionOptions | null, defn: QueryDefinition) => FieldSelection[];
46
+ pickAllFields: (selection: SelectionOptions, defn: QueryDefinition) => FieldSelection[];
47
+ }
@@ -0,0 +1,416 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.QueryBuilder = exports.MetaObject = void 0;
37
+ const graphql_1 = require("graphql");
38
+ const inflection_1 = require("inflection");
39
+ const ast_1 = require("./ast");
40
+ const meta_object_1 = require("./meta-object");
41
+ exports.MetaObject = __importStar(require("./meta-object"));
42
+ const isObject = (val) => val !== null && typeof val === 'object';
43
+ class QueryBuilder {
44
+ _introspection;
45
+ _meta;
46
+ _models;
47
+ _model;
48
+ _fields;
49
+ _key;
50
+ _queryName;
51
+ _ast;
52
+ _edges;
53
+ _op;
54
+ _mutation;
55
+ _select;
56
+ constructor({ meta = {}, introspection }) {
57
+ this._introspection = introspection;
58
+ this._meta = meta;
59
+ this.clear();
60
+ this.initModelMap();
61
+ this.pickScalarFields = pickScalarFields.bind(this);
62
+ this.pickAllFields = pickAllFields.bind(this);
63
+ const result = (0, meta_object_1.validateMetaObject)(this._meta);
64
+ if (typeof result === 'object' && result.errors) {
65
+ throw new Error(`QueryBuilder: meta object is invalid:\n${result.message}`);
66
+ }
67
+ }
68
+ /*
69
+ * Save all gql queries and mutations by model name for quicker lookup
70
+ */
71
+ initModelMap() {
72
+ this._models = Object.keys(this._introspection).reduce((map, key) => {
73
+ const defn = this._introspection[key];
74
+ map = {
75
+ ...map,
76
+ [defn.model]: {
77
+ ...map[defn.model],
78
+ ...{ [key]: defn },
79
+ },
80
+ };
81
+ return map;
82
+ }, {});
83
+ }
84
+ clear() {
85
+ this._model = '';
86
+ this._fields = [];
87
+ this._key = null;
88
+ this._queryName = '';
89
+ this._ast = null;
90
+ this._edges = false;
91
+ this._op = '';
92
+ this._mutation = '';
93
+ this._select = [];
94
+ }
95
+ query(model) {
96
+ this.clear();
97
+ this._model = model;
98
+ return this;
99
+ }
100
+ _findQuery() {
101
+ // based on the op, finds the relevant GQL query
102
+ const queries = this._models[this._model];
103
+ if (!queries) {
104
+ throw new Error('No queries found for ' + this._model);
105
+ }
106
+ const matchQuery = Object.entries(queries).find(([_, defn]) => defn.qtype === this._op);
107
+ if (!matchQuery) {
108
+ throw new Error('No query found for ' + this._model + ':' + this._op);
109
+ }
110
+ const queryKey = matchQuery[0];
111
+ return queryKey;
112
+ }
113
+ _findMutation() {
114
+ // For mutation, there can be many defns that match the operation being requested
115
+ // .ie: deleteAction, deleteActionBySlug, deleteActionByName
116
+ const matchingDefns = Object.keys(this._introspection).reduce((arr, mutationKey) => {
117
+ const defn = this._introspection[mutationKey];
118
+ if (defn.model === this._model &&
119
+ defn.qtype === this._op &&
120
+ defn.qtype === 'mutation' &&
121
+ defn.mutationType === this._mutation) {
122
+ arr = [...arr, { defn, mutationKey }];
123
+ }
124
+ return arr;
125
+ }, []);
126
+ if (matchingDefns.length === 0) {
127
+ throw new Error('no mutation found for ' + this._model + ':' + this._mutation);
128
+ }
129
+ // We only need deleteAction from all of [deleteAction, deleteActionBySlug, deleteActionByName]
130
+ const getInputName = (mutationType) => {
131
+ switch (mutationType) {
132
+ case 'delete': {
133
+ return `Delete${(0, inflection_1.camelize)(this._model)}Input`;
134
+ }
135
+ case 'create': {
136
+ return `Create${(0, inflection_1.camelize)(this._model)}Input`;
137
+ }
138
+ case 'patch': {
139
+ return `Update${(0, inflection_1.camelize)(this._model)}Input`;
140
+ }
141
+ default:
142
+ throw new Error('Unhandled mutation type' + mutationType);
143
+ }
144
+ };
145
+ const matchDefn = matchingDefns.find(({ defn }) => defn.properties.input.type === getInputName(this._mutation));
146
+ if (!matchDefn) {
147
+ throw new Error('no mutation found for ' + this._model + ':' + this._mutation);
148
+ }
149
+ return matchDefn.mutationKey;
150
+ }
151
+ select(selection) {
152
+ const defn = this._introspection[this._key];
153
+ // If selection not given, pick only scalar fields
154
+ if (selection == null) {
155
+ this._select = this.pickScalarFields(null, defn);
156
+ return this;
157
+ }
158
+ this._select = this.pickAllFields(selection, defn);
159
+ return this;
160
+ }
161
+ edges(useEdges) {
162
+ this._edges = useEdges;
163
+ return this;
164
+ }
165
+ getMany({ select } = {}) {
166
+ this._op = 'getMany';
167
+ this._key = this._findQuery();
168
+ this.queryName((0, inflection_1.camelize)(['get', (0, inflection_1.underscore)(this._key), 'query'].join('_'), true));
169
+ const defn = this._introspection[this._key];
170
+ this.select(select);
171
+ this._ast = (0, ast_1.getMany)({
172
+ builder: this,
173
+ queryName: this._queryName,
174
+ operationName: this._key,
175
+ query: defn,
176
+ selection: this._select,
177
+ });
178
+ return this;
179
+ }
180
+ all({ select } = {}) {
181
+ this._op = 'getMany';
182
+ this._key = this._findQuery();
183
+ this.queryName((0, inflection_1.camelize)(['get', (0, inflection_1.underscore)(this._key), 'query', 'all'].join('_'), true));
184
+ const defn = this._introspection[this._key];
185
+ this.select(select);
186
+ this._ast = (0, ast_1.getAll)({
187
+ queryName: this._queryName,
188
+ operationName: this._key,
189
+ query: defn,
190
+ selection: this._select,
191
+ });
192
+ return this;
193
+ }
194
+ count() {
195
+ this._op = 'getMany';
196
+ this._key = this._findQuery();
197
+ this.queryName((0, inflection_1.camelize)(['get', (0, inflection_1.underscore)(this._key), 'count', 'query'].join('_'), true));
198
+ const defn = this._introspection[this._key];
199
+ this._ast = (0, ast_1.getCount)({
200
+ queryName: this._queryName,
201
+ operationName: this._key,
202
+ query: defn,
203
+ });
204
+ return this;
205
+ }
206
+ getOne({ select } = {}) {
207
+ this._op = 'getOne';
208
+ this._key = this._findQuery();
209
+ this.queryName((0, inflection_1.camelize)(['get', (0, inflection_1.underscore)(this._key), 'query'].join('_'), true));
210
+ const defn = this._introspection[this._key];
211
+ this.select(select);
212
+ this._ast = (0, ast_1.getOne)({
213
+ builder: this,
214
+ queryName: this._queryName,
215
+ operationName: this._key,
216
+ query: defn,
217
+ selection: this._select,
218
+ });
219
+ return this;
220
+ }
221
+ create({ select } = {}) {
222
+ this._op = 'mutation';
223
+ this._mutation = 'create';
224
+ this._key = this._findMutation();
225
+ this.queryName((0, inflection_1.camelize)([(0, inflection_1.underscore)(this._key), 'mutation'].join('_'), true));
226
+ const defn = this._introspection[this._key];
227
+ this.select(select);
228
+ this._ast = (0, ast_1.createOne)({
229
+ operationName: this._key,
230
+ mutationName: this._queryName,
231
+ mutation: defn,
232
+ selection: this._select,
233
+ });
234
+ return this;
235
+ }
236
+ delete({ select } = {}) {
237
+ this._op = 'mutation';
238
+ this._mutation = 'delete';
239
+ this._key = this._findMutation();
240
+ this.queryName((0, inflection_1.camelize)([(0, inflection_1.underscore)(this._key), 'mutation'].join('_'), true));
241
+ const defn = this._introspection[this._key];
242
+ this.select(select);
243
+ this._ast = (0, ast_1.deleteOne)({
244
+ operationName: this._key,
245
+ mutationName: this._queryName,
246
+ mutation: defn,
247
+ });
248
+ return this;
249
+ }
250
+ update({ select } = {}) {
251
+ this._op = 'mutation';
252
+ this._mutation = 'patch';
253
+ this._key = this._findMutation();
254
+ this.queryName((0, inflection_1.camelize)([(0, inflection_1.underscore)(this._key), 'mutation'].join('_'), true));
255
+ const defn = this._introspection[this._key];
256
+ this.select(select);
257
+ this._ast = (0, ast_1.patchOne)({
258
+ operationName: this._key,
259
+ mutationName: this._queryName,
260
+ mutation: defn,
261
+ selection: this._select,
262
+ });
263
+ return this;
264
+ }
265
+ queryName(name) {
266
+ this._queryName = name;
267
+ return this;
268
+ }
269
+ print() {
270
+ if (!this._ast) {
271
+ throw new Error('No AST generated. Please call a query method first.');
272
+ }
273
+ const _hash = (0, graphql_1.print)(this._ast);
274
+ return {
275
+ _hash,
276
+ _queryName: this._queryName,
277
+ _ast: this._ast,
278
+ };
279
+ }
280
+ // Bind methods that will be called with different this context
281
+ pickScalarFields;
282
+ pickAllFields;
283
+ }
284
+ exports.QueryBuilder = QueryBuilder;
285
+ /**
286
+ * Pick scalar fields of a query definition
287
+ * @param {Object} defn Query definition
288
+ * @param {Object} meta Meta object containing info about table relations
289
+ * @returns {Array}
290
+ */
291
+ function pickScalarFields(selection, defn) {
292
+ const model = defn.model;
293
+ const modelMeta = this._meta.tables.find((t) => t.name === model);
294
+ if (!modelMeta) {
295
+ throw new Error(`Model meta not found for ${model}`);
296
+ }
297
+ const isInTableSchema = (fieldName) => !!modelMeta.fields.find((field) => field.name === fieldName);
298
+ const pickFrom = (modelSelection) => modelSelection
299
+ .filter((fieldName) => {
300
+ // If not specified or not a valid selection list, allow all
301
+ if (selection == null || !Array.isArray(selection))
302
+ return true;
303
+ return Object.keys(selection).includes(fieldName);
304
+ })
305
+ .filter((fieldName) => !isRelationalField(fieldName, modelMeta) && isInTableSchema(fieldName))
306
+ .map((fieldName) => ({
307
+ name: fieldName,
308
+ isObject: false,
309
+ fieldDefn: modelMeta.fields.find((f) => f.name === fieldName),
310
+ }));
311
+ // This is for inferring the sub-selection of a mutation query
312
+ // from a definition model .eg UserSetting, find its related queries in the introspection object, and pick its selection fields
313
+ if (defn.qtype === 'mutation') {
314
+ const relatedQuery = this._introspection[`${modelNameToGetMany(defn.model)}`];
315
+ return pickFrom(relatedQuery.selection);
316
+ }
317
+ return pickFrom(defn.selection);
318
+ }
319
+ /**
320
+ * Pick scalar fields and sub-selection fields of a query definition
321
+ * @param {Object} selection Selection clause object
322
+ * @param {Object} defn Query definition
323
+ * @param {Object} meta Meta object containing info about table relations
324
+ * @returns {Array}
325
+ */
326
+ function pickAllFields(selection, defn) {
327
+ const model = defn.model;
328
+ const modelMeta = this._meta.tables.find((t) => t.name === model);
329
+ if (!modelMeta) {
330
+ throw new Error(`Model meta not found for ${model}`);
331
+ }
332
+ const selectionEntries = Object.entries(selection);
333
+ let fields = [];
334
+ const isWhiteListed = (selectValue) => {
335
+ return typeof selectValue === 'boolean' && selectValue;
336
+ };
337
+ for (const entry of selectionEntries) {
338
+ const [fieldName, fieldOptions] = entry;
339
+ // Case
340
+ // {
341
+ // goalResults: // fieldName
342
+ // { select: { id: true }, variables: { first: 100 } } // fieldOptions
343
+ // }
344
+ if (isObject(fieldOptions)) {
345
+ if (!isFieldInDefinition(fieldName, defn, modelMeta)) {
346
+ continue;
347
+ }
348
+ const referencedForeignConstraint = modelMeta.foreignConstraints.find((constraint) => constraint.fromKey.name === fieldName ||
349
+ constraint.fromKey.alias === fieldName);
350
+ const subFields = Object.keys(fieldOptions.select).filter((subField) => {
351
+ return (!isRelationalField(subField, modelMeta) &&
352
+ isWhiteListed(fieldOptions.select[subField]));
353
+ });
354
+ const isBelongTo = !!referencedForeignConstraint;
355
+ const fieldSelection = {
356
+ name: fieldName,
357
+ isObject: true,
358
+ isBelongTo,
359
+ selection: subFields.map((name) => ({ name, isObject: false })),
360
+ variables: fieldOptions.variables,
361
+ };
362
+ // Need to further expand selection of object fields,
363
+ // but only non-graphql-builtin, non-relation fields
364
+ // .ie action { id location }
365
+ // location is non-scalar and non-relational, thus need to further expand into { x y ... }
366
+ if (isBelongTo) {
367
+ const getManyName = modelNameToGetMany(referencedForeignConstraint.refTable);
368
+ const refDefn = this._introspection[getManyName];
369
+ fieldSelection.selection = pickScalarFields.call(this, { [fieldName]: true }, refDefn);
370
+ }
371
+ fields = [...fields, fieldSelection];
372
+ }
373
+ else {
374
+ // Case
375
+ // {
376
+ // userId: true // [fieldName, fieldOptions]
377
+ // }
378
+ if (isWhiteListed(fieldOptions)) {
379
+ fields = [
380
+ ...fields,
381
+ {
382
+ name: fieldName,
383
+ isObject: false,
384
+ fieldDefn: modelMeta.fields.find((f) => f.name === fieldName),
385
+ },
386
+ ];
387
+ }
388
+ }
389
+ }
390
+ return fields;
391
+ }
392
+ function isFieldInDefinition(fieldName, defn, modelMeta) {
393
+ const isReferenced = !!modelMeta.foreignConstraints.find((constraint) => constraint.fromKey.name === fieldName ||
394
+ constraint.fromKey.alias === fieldName);
395
+ return (isReferenced ||
396
+ defn.selection.some((selectionItem) => {
397
+ if (typeof selectionItem === 'string') {
398
+ return fieldName === selectionItem;
399
+ }
400
+ if (isObject(selectionItem)) {
401
+ return selectionItem.name === fieldName;
402
+ }
403
+ return false;
404
+ }));
405
+ }
406
+ // TODO: see if there is a possibility of supertyping table (a key is both a foreign and primary key)
407
+ // A relational field is a foreign key but not a primary key
408
+ function isRelationalField(fieldName, modelMeta) {
409
+ return (!modelMeta.primaryConstraints.find((field) => field.name === fieldName) &&
410
+ !!modelMeta.foreignConstraints.find((constraint) => constraint.fromKey.name === fieldName));
411
+ }
412
+ // Get getMany op name from model
413
+ // ie. UserSetting => userSettings
414
+ function modelNameToGetMany(model) {
415
+ return (0, inflection_1.camelize)((0, inflection_1.pluralize)((0, inflection_1.underscore)(model)), true);
416
+ }
package/types.d.ts ADDED
@@ -0,0 +1,139 @@
1
+ import type { DocumentNode, FieldNode, SelectionSetNode, VariableDefinitionNode } from 'graphql';
2
+ export type ASTNode = DocumentNode | FieldNode | SelectionSetNode | VariableDefinitionNode;
3
+ export interface NestedProperties {
4
+ [key: string]: QueryProperty | NestedProperties;
5
+ }
6
+ export interface QueryProperty {
7
+ name: string;
8
+ type: string;
9
+ isNotNull: boolean;
10
+ isArray: boolean;
11
+ isArrayNotNull: boolean;
12
+ properties?: NestedProperties;
13
+ }
14
+ export interface QueryDefinition {
15
+ model: string;
16
+ qtype: 'getMany' | 'getOne' | 'mutation';
17
+ mutationType?: 'create' | 'patch' | 'delete';
18
+ selection: string[];
19
+ properties: Record<string, QueryProperty>;
20
+ }
21
+ export interface MutationDefinition extends QueryDefinition {
22
+ qtype: 'mutation';
23
+ mutationType: 'create' | 'patch' | 'delete';
24
+ }
25
+ export interface IntrospectionSchema {
26
+ [key: string]: QueryDefinition | MutationDefinition;
27
+ }
28
+ export interface MetaFieldType {
29
+ gqlType: string;
30
+ isArray: boolean;
31
+ modifier?: string | number | null;
32
+ pgAlias?: string | null;
33
+ pgType?: string | null;
34
+ subtype?: string | null;
35
+ typmod?: number | null;
36
+ }
37
+ export interface MetaField {
38
+ name: string;
39
+ type: MetaFieldType;
40
+ }
41
+ export type CleanField = MetaField;
42
+ export interface MetaConstraint {
43
+ name: string;
44
+ type: MetaFieldType;
45
+ alias?: string;
46
+ }
47
+ export interface MetaForeignConstraint {
48
+ fromKey: MetaConstraint;
49
+ refTable: string;
50
+ toKey: MetaConstraint;
51
+ }
52
+ export interface MetaTable {
53
+ name: string;
54
+ fields: MetaField[];
55
+ primaryConstraints: MetaConstraint[];
56
+ uniqueConstraints: MetaConstraint[];
57
+ foreignConstraints: MetaForeignConstraint[];
58
+ }
59
+ export interface MetaObject {
60
+ tables: MetaTable[];
61
+ }
62
+ export type GraphQLVariableValue = string | number | boolean | null;
63
+ export interface GraphQLVariables {
64
+ [key: string]: GraphQLVariableValue | GraphQLVariableValue[] | GraphQLVariables | GraphQLVariables[];
65
+ }
66
+ export interface FieldSelection {
67
+ name: string;
68
+ isObject: boolean;
69
+ fieldDefn?: MetaField;
70
+ selection?: FieldSelection[];
71
+ variables?: GraphQLVariables;
72
+ isBelongTo?: boolean;
73
+ }
74
+ export interface SelectionOptions {
75
+ [fieldName: string]: boolean | {
76
+ select: Record<string, boolean>;
77
+ variables?: GraphQLVariables;
78
+ };
79
+ }
80
+ export interface QueryBuilderInstance {
81
+ _introspection: IntrospectionSchema;
82
+ _meta: MetaObject;
83
+ _edges?: boolean;
84
+ }
85
+ export interface ASTFunctionParams {
86
+ queryName: string;
87
+ operationName: string;
88
+ query: QueryDefinition;
89
+ selection: FieldSelection[];
90
+ builder?: QueryBuilderInstance;
91
+ }
92
+ export interface MutationASTParams {
93
+ mutationName: string;
94
+ operationName: string;
95
+ mutation: MutationDefinition;
96
+ selection?: FieldSelection[];
97
+ }
98
+ export interface QueryBuilderOptions {
99
+ meta: MetaObject;
100
+ introspection: IntrospectionSchema;
101
+ }
102
+ export interface QueryBuilderResult {
103
+ _hash: string;
104
+ _queryName: string;
105
+ _ast: DocumentNode;
106
+ }
107
+ export interface IQueryBuilder {
108
+ query(model: string): IQueryBuilder;
109
+ getMany(options?: {
110
+ select?: SelectionOptions;
111
+ }): IQueryBuilder;
112
+ getOne(options?: {
113
+ select?: SelectionOptions;
114
+ }): IQueryBuilder;
115
+ all(options?: {
116
+ select?: SelectionOptions;
117
+ }): IQueryBuilder;
118
+ count(): IQueryBuilder;
119
+ create(options?: {
120
+ select?: SelectionOptions;
121
+ }): IQueryBuilder;
122
+ update(options?: {
123
+ select?: SelectionOptions;
124
+ }): IQueryBuilder;
125
+ delete(options?: {
126
+ select?: SelectionOptions;
127
+ }): IQueryBuilder;
128
+ edges(useEdges: boolean): IQueryBuilder;
129
+ print(): QueryBuilderResult;
130
+ }
131
+ export interface ObjectArrayItem extends QueryProperty {
132
+ name: string;
133
+ key?: string;
134
+ }
135
+ export declare function isGraphQLVariableValue(value: unknown): value is GraphQLVariableValue;
136
+ export declare function isGraphQLVariables(obj: unknown): obj is GraphQLVariables;
137
+ export type StrictRecord<K extends PropertyKey, V> = Record<K, V> & {
138
+ [P in PropertyKey]: P extends K ? V : never;
139
+ };
package/types.js ADDED
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isGraphQLVariableValue = isGraphQLVariableValue;
4
+ exports.isGraphQLVariables = isGraphQLVariables;
5
+ // Type guards for runtime validation
6
+ function isGraphQLVariableValue(value) {
7
+ return (value === null ||
8
+ typeof value === 'string' ||
9
+ typeof value === 'number' ||
10
+ typeof value === 'boolean');
11
+ }
12
+ function isGraphQLVariables(obj) {
13
+ if (!obj || typeof obj !== 'object')
14
+ return false;
15
+ for (const [key, value] of Object.entries(obj)) {
16
+ if (typeof key !== 'string')
17
+ return false;
18
+ if (Array.isArray(value)) {
19
+ if (!value.every((item) => isGraphQLVariableValue(item) || isGraphQLVariables(item))) {
20
+ return false;
21
+ }
22
+ }
23
+ else if (!isGraphQLVariableValue(value) && !isGraphQLVariables(value)) {
24
+ return false;
25
+ }
26
+ }
27
+ return true;
28
+ }