graphql-jit 0.8.9-canary.f7574a0 → 0.8.10

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 (178) hide show
  1. package/README.md +0 -25
  2. package/dist/ast.d.mts +7 -0
  3. package/dist/ast.d.ts +7 -0
  4. package/dist/ast.js +635 -0
  5. package/dist/ast.js.map +1 -0
  6. package/dist/ast.mjs +612 -0
  7. package/dist/ast.mjs.map +1 -0
  8. package/dist/compat.d.mts +7 -0
  9. package/dist/compat.d.ts +7 -0
  10. package/dist/compat.js +113 -0
  11. package/dist/compat.js.map +1 -0
  12. package/dist/compat.mjs +75 -0
  13. package/dist/compat.mjs.map +1 -0
  14. package/dist/error.d.mts +11 -0
  15. package/dist/error.d.ts +11 -0
  16. package/dist/error.js +79 -0
  17. package/dist/error.js.map +1 -0
  18. package/dist/error.mjs +57 -0
  19. package/dist/error.mjs.map +1 -0
  20. package/dist/execution.d.mts +7 -0
  21. package/dist/execution.d.ts +7 -0
  22. package/dist/execution.js +1322 -0
  23. package/dist/execution.js.map +1 -0
  24. package/dist/execution.mjs +1308 -0
  25. package/dist/execution.mjs.map +1 -0
  26. package/dist/generate.d.mts +6 -0
  27. package/dist/generate.d.ts +6 -0
  28. package/dist/generate.js +37 -0
  29. package/dist/generate.js.map +1 -0
  30. package/dist/generate.mjs +13 -0
  31. package/dist/generate.mjs.map +1 -0
  32. package/dist/index-CZg-2UMZ.d.ts +335 -0
  33. package/dist/index-DtKZ-jVv.d.mts +335 -0
  34. package/dist/index.d.mts +7 -0
  35. package/dist/index.d.ts +7 -0
  36. package/dist/index.js +36 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/index.mjs +15 -0
  39. package/dist/index.mjs.map +1 -0
  40. package/dist/inspect.d.mts +7 -0
  41. package/dist/inspect.d.ts +7 -0
  42. package/dist/inspect.js +121 -0
  43. package/dist/inspect.js.map +1 -0
  44. package/dist/inspect.mjs +97 -0
  45. package/dist/inspect.mjs.map +1 -0
  46. package/dist/json.d.mts +18 -0
  47. package/dist/json.d.ts +18 -0
  48. package/dist/json.js +181 -0
  49. package/dist/json.js.map +1 -0
  50. package/dist/json.mjs +164 -0
  51. package/dist/json.mjs.map +1 -0
  52. package/dist/memoize.d.mts +6 -0
  53. package/dist/memoize.d.ts +6 -0
  54. package/dist/memoize.js +67 -0
  55. package/dist/memoize.js.map +1 -0
  56. package/dist/memoize.mjs +31 -0
  57. package/dist/memoize.mjs.map +1 -0
  58. package/dist/non-null.d.mts +7 -0
  59. package/dist/non-null.d.ts +7 -0
  60. package/dist/non-null.js +196 -0
  61. package/dist/non-null.js.map +1 -0
  62. package/dist/non-null.mjs +167 -0
  63. package/dist/non-null.mjs.map +1 -0
  64. package/dist/{cjs/resolve-info.d.ts → resolve-info.d.mts} +12 -10
  65. package/dist/{esm/resolve-info.d.ts → resolve-info.d.ts} +12 -10
  66. package/dist/resolve-info.js +245 -0
  67. package/dist/resolve-info.js.map +1 -0
  68. package/dist/resolve-info.mjs +219 -0
  69. package/dist/resolve-info.mjs.map +1 -0
  70. package/dist/runtime.d.mts +7 -0
  71. package/dist/runtime.d.ts +7 -0
  72. package/dist/runtime.js +115 -0
  73. package/dist/runtime.js.map +1 -0
  74. package/dist/runtime.mjs +91 -0
  75. package/dist/runtime.mjs.map +1 -0
  76. package/dist/types.d.mts +3 -0
  77. package/dist/types.d.ts +3 -0
  78. package/dist/types.js +17 -0
  79. package/dist/types.js.map +1 -0
  80. package/dist/types.mjs +1 -0
  81. package/dist/types.mjs.map +1 -0
  82. package/dist/variables.d.mts +17 -0
  83. package/dist/variables.d.ts +17 -0
  84. package/dist/variables.js +412 -0
  85. package/dist/variables.js.map +1 -0
  86. package/dist/variables.mjs +391 -0
  87. package/dist/variables.mjs.map +1 -0
  88. package/package.json +35 -39
  89. package/dist/cjs/ast.d.ts +0 -89
  90. package/dist/cjs/ast.js +0 -766
  91. package/dist/cjs/ast.js.map +0 -1
  92. package/dist/cjs/compat.d.ts +0 -74
  93. package/dist/cjs/compat.js +0 -141
  94. package/dist/cjs/compat.js.map +0 -1
  95. package/dist/cjs/debug.d.ts +0 -29
  96. package/dist/cjs/debug.js +0 -46
  97. package/dist/cjs/debug.js.map +0 -1
  98. package/dist/cjs/error.d.ts +0 -7
  99. package/dist/cjs/error.js +0 -58
  100. package/dist/cjs/error.js.map +0 -1
  101. package/dist/cjs/execution.d.ts +0 -154
  102. package/dist/cjs/execution.js +0 -1241
  103. package/dist/cjs/execution.js.map +0 -1
  104. package/dist/cjs/generate.d.ts +0 -4
  105. package/dist/cjs/generate.js +0 -13
  106. package/dist/cjs/generate.js.map +0 -1
  107. package/dist/cjs/index.d.ts +0 -3
  108. package/dist/cjs/index.js +0 -10
  109. package/dist/cjs/index.js.map +0 -1
  110. package/dist/cjs/inspect.d.ts +0 -5
  111. package/dist/cjs/inspect.js +0 -110
  112. package/dist/cjs/inspect.js.map +0 -1
  113. package/dist/cjs/json.d.ts +0 -9
  114. package/dist/cjs/json.js +0 -144
  115. package/dist/cjs/json.js.map +0 -1
  116. package/dist/cjs/memoize.d.ts +0 -5
  117. package/dist/cjs/memoize.js +0 -28
  118. package/dist/cjs/memoize.js.map +0 -1
  119. package/dist/cjs/non-null.d.ts +0 -9
  120. package/dist/cjs/non-null.js +0 -205
  121. package/dist/cjs/non-null.js.map +0 -1
  122. package/dist/cjs/package.json +0 -3
  123. package/dist/cjs/resolve-info.js +0 -232
  124. package/dist/cjs/resolve-info.js.map +0 -1
  125. package/dist/cjs/runtime.d.ts +0 -14
  126. package/dist/cjs/runtime.js +0 -92
  127. package/dist/cjs/runtime.js.map +0 -1
  128. package/dist/cjs/types.d.ts +0 -1
  129. package/dist/cjs/types.js +0 -3
  130. package/dist/cjs/types.js.map +0 -1
  131. package/dist/cjs/variables.d.ts +0 -20
  132. package/dist/cjs/variables.js +0 -357
  133. package/dist/cjs/variables.js.map +0 -1
  134. package/dist/esm/ast.d.ts +0 -89
  135. package/dist/esm/ast.js +0 -751
  136. package/dist/esm/ast.js.map +0 -1
  137. package/dist/esm/compat.d.ts +0 -74
  138. package/dist/esm/compat.js +0 -99
  139. package/dist/esm/compat.js.map +0 -1
  140. package/dist/esm/debug.d.ts +0 -29
  141. package/dist/esm/debug.js +0 -40
  142. package/dist/esm/debug.js.map +0 -1
  143. package/dist/esm/error.d.ts +0 -7
  144. package/dist/esm/error.js +0 -55
  145. package/dist/esm/error.js.map +0 -1
  146. package/dist/esm/execution.d.ts +0 -154
  147. package/dist/esm/execution.js +0 -1228
  148. package/dist/esm/execution.js.map +0 -1
  149. package/dist/esm/generate.d.ts +0 -4
  150. package/dist/esm/generate.js +0 -10
  151. package/dist/esm/generate.js.map +0 -1
  152. package/dist/esm/index.d.ts +0 -3
  153. package/dist/esm/index.js +0 -3
  154. package/dist/esm/index.js.map +0 -1
  155. package/dist/esm/inspect.d.ts +0 -5
  156. package/dist/esm/inspect.js +0 -106
  157. package/dist/esm/inspect.js.map +0 -1
  158. package/dist/esm/json.d.ts +0 -9
  159. package/dist/esm/json.js +0 -141
  160. package/dist/esm/json.js.map +0 -1
  161. package/dist/esm/memoize.d.ts +0 -5
  162. package/dist/esm/memoize.js +0 -20
  163. package/dist/esm/memoize.js.map +0 -1
  164. package/dist/esm/non-null.d.ts +0 -9
  165. package/dist/esm/non-null.js +0 -199
  166. package/dist/esm/non-null.js.map +0 -1
  167. package/dist/esm/package.json +0 -3
  168. package/dist/esm/resolve-info.js +0 -224
  169. package/dist/esm/resolve-info.js.map +0 -1
  170. package/dist/esm/runtime.d.ts +0 -14
  171. package/dist/esm/runtime.js +0 -89
  172. package/dist/esm/runtime.js.map +0 -1
  173. package/dist/esm/types.d.ts +0 -1
  174. package/dist/esm/types.js +0 -2
  175. package/dist/esm/types.js.map +0 -1
  176. package/dist/esm/variables.d.ts +0 -20
  177. package/dist/esm/variables.js +0 -350
  178. package/dist/esm/variables.js.map +0 -1
package/README.md CHANGED
@@ -123,31 +123,6 @@ Compiles the `document` AST, using an optional operationName and compiler option
123
123
  - `customSerializers` {Object as Map, default: {}} - Replace serializer functions for specific types. Can be used as a safer alternative
124
124
  for overly expensive serializers
125
125
  - `customJSONSerializer` {boolean, default: false} - Whether to produce also a JSON serializer function using `fast-json-stringify`. The default stringifier function is `JSON.stringify`
126
- - `debug` {object, optional} - Publishes formatted generated executors as virtual JavaScript sources. This is intended for local development.
127
- - `enabled` {boolean, required} - Enables all debug-only work. Set this to `false` to skip formatting and generated-source changes.
128
- - `querySourceName` {string, optional} - A stable name for the generated query source, such as `graphql-jit://graphql-jit/my-service/GetProduct.query.js`.
129
- - `variablesSourceName` {string, optional} - A stable name for the generated variable-coercion source, such as `graphql-jit://graphql-jit/my-service/GetProduct.variables.js`.
130
- - `formatSourceCode` {(source: string) => string, optional} - A synchronous formatter that runs before compilation. e.g. `@prettier/sync`.
131
-
132
- ### Debugging generated executors
133
-
134
- Start Node with `--inspect` and enable `debug` for the operation being investigated:
135
-
136
- ```js
137
- const { format } = require("@prettier/sync");
138
-
139
- const compiledQuery = compileQuery(schema, document, "GetProduct", {
140
- debug: {
141
- enabled: true,
142
- querySourceName: "graphql-jit://graphql-jit/shop/GetProduct.query.js",
143
- variablesSourceName:
144
- "graphql-jit://graphql-jit/shop/GetProduct.variables.js",
145
- formatSourceCode: (source) => format(source, { parser: "babel" })
146
- }
147
- });
148
- ```
149
-
150
- The debugger exposes separate query and variable-coercion scripts. Set breakpoints directly in those generated JavaScript sources.
151
126
 
152
127
  #### compiledQuery.query(root: any, context: any, variables: Maybe<{ [key: string]: any }>)
153
128
 
package/dist/ast.d.mts ADDED
@@ -0,0 +1,7 @@
1
+ import 'graphql';
2
+ export { A as Arguments, F as FieldsAndNodes, t as JitFieldNode, O as ObjectPath, z as addPath, u as collectFields, v as collectSubfields, y as computeLocations, B as flattenPath, w as getArgumentDefs, H as joinSkipIncludePath, r as resolveFieldDef, D as serializeObjectPathForSkipInclude, x as valueFromAST } from './index-DtKZ-jVv.mjs';
3
+ import '@graphql-typed-document-node/core';
4
+ import './types.mjs';
5
+ import './error.mjs';
6
+ import './resolve-info.mjs';
7
+ import './variables.mjs';
package/dist/ast.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import 'graphql';
2
+ export { A as Arguments, F as FieldsAndNodes, t as JitFieldNode, O as ObjectPath, z as addPath, u as collectFields, v as collectSubfields, y as computeLocations, B as flattenPath, w as getArgumentDefs, H as joinSkipIncludePath, r as resolveFieldDef, D as serializeObjectPathForSkipInclude, x as valueFromAST } from './index-CZg-2UMZ.js';
3
+ import '@graphql-typed-document-node/core';
4
+ import './types.js';
5
+ import './error.js';
6
+ import './resolve-info.js';
7
+ import './variables.js';
package/dist/ast.js ADDED
@@ -0,0 +1,635 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var ast_exports = {};
30
+ __export(ast_exports, {
31
+ addPath: () => addPath,
32
+ collectFields: () => collectFields,
33
+ collectSubfields: () => collectSubfields,
34
+ computeLocations: () => computeLocations,
35
+ flattenPath: () => flattenPath,
36
+ getArgumentDefs: () => getArgumentDefs,
37
+ joinSkipIncludePath: () => joinSkipIncludePath,
38
+ resolveFieldDef: () => import_compat.resolveFieldDef,
39
+ serializeObjectPathForSkipInclude: () => serializeObjectPathForSkipInclude,
40
+ valueFromAST: () => valueFromAST
41
+ });
42
+ module.exports = __toCommonJS(ast_exports);
43
+ var import_graphql = require("graphql");
44
+ var import_execution = require("./execution.js");
45
+ var import_inspect = __toESM(require("./inspect.js"));
46
+ var import_compat = require("./compat.js");
47
+ const inspect = (0, import_inspect.default)();
48
+ function collectFields(compilationContext, runtimeType, selectionSet, fields, visitedFragmentNames, parentResponsePath) {
49
+ return collectFieldsImpl(
50
+ compilationContext,
51
+ runtimeType,
52
+ selectionSet,
53
+ fields,
54
+ visitedFragmentNames,
55
+ void 0,
56
+ serializeObjectPathForSkipInclude(parentResponsePath)
57
+ );
58
+ }
59
+ function collectFieldsImpl(compilationContext, runtimeType, selectionSet, fields, visitedFragmentNames, previousShouldInclude = [], parentResponsePath = "") {
60
+ const stack = [];
61
+ for (let i = selectionSet.selections.length - 1; i >= 0; i--) {
62
+ stack.push({
63
+ selection: selectionSet.selections[i],
64
+ parentResponsePath,
65
+ previousShouldInclude
66
+ });
67
+ }
68
+ while (stack.length > 0) {
69
+ const { selection, parentResponsePath: parentResponsePath2, previousShouldInclude: previousShouldInclude2 } = stack.pop();
70
+ switch (selection.kind) {
71
+ case import_graphql.Kind.FIELD: {
72
+ collectFieldsForField({
73
+ compilationContext,
74
+ fields,
75
+ parentResponsePath: parentResponsePath2,
76
+ previousShouldInclude: previousShouldInclude2,
77
+ selection
78
+ });
79
+ break;
80
+ }
81
+ case import_graphql.Kind.INLINE_FRAGMENT: {
82
+ if (!doesFragmentConditionMatch(
83
+ compilationContext,
84
+ selection,
85
+ runtimeType
86
+ )) {
87
+ break;
88
+ }
89
+ const compiledSkipInclude = compileSkipInclude(
90
+ compilationContext,
91
+ selection
92
+ );
93
+ const mergedShouldInclude = joinShouldIncludeCompilations(
94
+ previousShouldInclude2,
95
+ [compiledSkipInclude]
96
+ );
97
+ const selectionsLength = selection.selectionSet.selections.length;
98
+ for (let i = selectionsLength - 1; i >= 0; i--) {
99
+ stack.push({
100
+ selection: selection.selectionSet.selections[i],
101
+ parentResponsePath: parentResponsePath2,
102
+ previousShouldInclude: mergedShouldInclude
103
+ });
104
+ }
105
+ break;
106
+ }
107
+ case import_graphql.Kind.FRAGMENT_SPREAD: {
108
+ const fragName = selection.name.value;
109
+ if (visitedFragmentNames[fragName]) {
110
+ break;
111
+ }
112
+ visitedFragmentNames[fragName] = true;
113
+ const fragment = compilationContext.fragments[fragName];
114
+ if (!fragment || !doesFragmentConditionMatch(compilationContext, fragment, runtimeType)) {
115
+ break;
116
+ }
117
+ const compiledSkipInclude = compileSkipInclude(
118
+ compilationContext,
119
+ selection
120
+ );
121
+ const mergedShouldInclude = joinShouldIncludeCompilations(
122
+ previousShouldInclude2,
123
+ [compiledSkipInclude]
124
+ );
125
+ const selectionsLength = fragment.selectionSet.selections.length;
126
+ for (let i = selectionsLength - 1; i >= 0; i--) {
127
+ stack.push({
128
+ selection: fragment.selectionSet.selections[i],
129
+ parentResponsePath: parentResponsePath2,
130
+ previousShouldInclude: mergedShouldInclude
131
+ });
132
+ }
133
+ break;
134
+ }
135
+ }
136
+ }
137
+ return fields;
138
+ }
139
+ function collectFieldsForField({
140
+ compilationContext,
141
+ fields,
142
+ parentResponsePath,
143
+ previousShouldInclude,
144
+ selection
145
+ }) {
146
+ const name = getFieldEntryKey(selection);
147
+ if (!fields[name]) {
148
+ fields[name] = [];
149
+ }
150
+ const fieldNode = selection;
151
+ const currentPath = joinSkipIncludePath(
152
+ parentResponsePath,
153
+ // use alias(instead of selection.name.value) if available as the responsePath used for lookup uses alias
154
+ name
155
+ );
156
+ const compiledSkipInclude = compileSkipInclude(compilationContext, selection);
157
+ if (compilationContext.options.useExperimentalPathBasedSkipInclude) {
158
+ if (!fieldNode.__internalShouldIncludePath)
159
+ fieldNode.__internalShouldIncludePath = {};
160
+ fieldNode.__internalShouldIncludePath[currentPath] = joinShouldIncludeCompilations(
161
+ fieldNode.__internalShouldIncludePath?.[currentPath] ?? [],
162
+ previousShouldInclude,
163
+ [compiledSkipInclude]
164
+ );
165
+ } else {
166
+ fieldNode.__internalShouldInclude = joinShouldIncludeCompilations(
167
+ fieldNode.__internalShouldInclude ?? [],
168
+ previousShouldInclude,
169
+ [compiledSkipInclude]
170
+ );
171
+ }
172
+ augmentFieldNodeTree(compilationContext, fieldNode, currentPath);
173
+ fields[name].push(fieldNode);
174
+ }
175
+ function augmentFieldNodeTree(compilationContext, rootFieldNode, parentResponsePath) {
176
+ for (const selection of rootFieldNode.selectionSet?.selections ?? []) {
177
+ const stack = [];
178
+ stack.push({
179
+ parentFieldNode: rootFieldNode,
180
+ selection,
181
+ comesFromFragmentSpread: false,
182
+ parentResponsePath
183
+ });
184
+ while (stack.length > 0) {
185
+ const {
186
+ parentFieldNode,
187
+ selection: selection2,
188
+ comesFromFragmentSpread,
189
+ parentResponsePath: parentResponsePath2
190
+ } = stack.pop();
191
+ switch (selection2.kind) {
192
+ case import_graphql.Kind.FIELD: {
193
+ const jitFieldNode = selection2;
194
+ const currentPath = joinSkipIncludePath(
195
+ parentResponsePath2,
196
+ // use alias(instead of selection.name.value) if available as the responsePath used for lookup uses alias
197
+ getFieldEntryKey(jitFieldNode)
198
+ );
199
+ if (!comesFromFragmentSpread) {
200
+ if (compilationContext.options.useExperimentalPathBasedSkipInclude) {
201
+ if (!jitFieldNode.__internalShouldIncludePath)
202
+ jitFieldNode.__internalShouldIncludePath = {};
203
+ jitFieldNode.__internalShouldIncludePath[currentPath] = joinShouldIncludeCompilations(
204
+ parentFieldNode.__internalShouldIncludePath?.[parentResponsePath2] ?? [],
205
+ jitFieldNode.__internalShouldIncludePath?.[currentPath] ?? []
206
+ );
207
+ } else {
208
+ jitFieldNode.__internalShouldInclude = joinShouldIncludeCompilations(
209
+ parentFieldNode.__internalShouldInclude ?? [],
210
+ jitFieldNode.__internalShouldInclude ?? []
211
+ );
212
+ }
213
+ }
214
+ for (const selection3 of jitFieldNode.selectionSet?.selections ?? []) {
215
+ stack.push({
216
+ parentFieldNode: jitFieldNode,
217
+ selection: selection3,
218
+ comesFromFragmentSpread: false,
219
+ parentResponsePath: currentPath
220
+ });
221
+ }
222
+ break;
223
+ }
224
+ case import_graphql.Kind.INLINE_FRAGMENT: {
225
+ for (const subSelection of selection2.selectionSet.selections) {
226
+ stack.push({
227
+ parentFieldNode,
228
+ selection: subSelection,
229
+ comesFromFragmentSpread: true,
230
+ parentResponsePath: parentResponsePath2
231
+ });
232
+ }
233
+ break;
234
+ }
235
+ case import_graphql.Kind.FRAGMENT_SPREAD: {
236
+ const fragment = compilationContext.fragments[selection2.name.value];
237
+ for (const subSelection of fragment.selectionSet.selections) {
238
+ stack.push({
239
+ parentFieldNode,
240
+ selection: subSelection,
241
+ comesFromFragmentSpread: true,
242
+ parentResponsePath: parentResponsePath2
243
+ });
244
+ }
245
+ }
246
+ }
247
+ }
248
+ }
249
+ }
250
+ function joinShouldIncludeCompilations(...compilations) {
251
+ const conditionsSet = /* @__PURE__ */ new Set();
252
+ for (const conditions of compilations) {
253
+ for (const condition of conditions) {
254
+ if (condition !== "true") {
255
+ conditionsSet.add(condition);
256
+ }
257
+ }
258
+ }
259
+ return Array.from(conditionsSet);
260
+ }
261
+ function compileSkipInclude(compilationContext, node) {
262
+ if (node.directives == null || node.directives.length < 1) {
263
+ return "true";
264
+ }
265
+ const { skipValue, includeValue } = compileSkipIncludeDirectiveValues(
266
+ compilationContext,
267
+ node
268
+ );
269
+ if (skipValue != null && includeValue != null) {
270
+ return `${skipValue} === false && ${includeValue} === true`;
271
+ } else if (skipValue != null) {
272
+ return `(${skipValue} === false)`;
273
+ } else if (includeValue != null) {
274
+ return `(${includeValue} === true)`;
275
+ } else {
276
+ return `true`;
277
+ }
278
+ }
279
+ function compileSkipIncludeDirectiveValues(compilationContext, node) {
280
+ const skipDirective = node.directives?.find(
281
+ (it) => it.name.value === import_graphql.GraphQLSkipDirective.name
282
+ );
283
+ const includeDirective = node.directives?.find(
284
+ (it) => it.name.value === import_graphql.GraphQLIncludeDirective.name
285
+ );
286
+ const skipValue = skipDirective ? compileSkipIncludeDirective(compilationContext, skipDirective) : (
287
+ // The null here indicates the absense of the directive
288
+ // which is later used to determine if both skip and include
289
+ // are present
290
+ null
291
+ );
292
+ const includeValue = includeDirective ? compileSkipIncludeDirective(compilationContext, includeDirective) : (
293
+ // The null here indicates the absense of the directive
294
+ // which is later used to determine if both skip and include
295
+ // are present
296
+ null
297
+ );
298
+ return { skipValue, includeValue };
299
+ }
300
+ function compileSkipIncludeDirective(compilationContext, directive) {
301
+ const ifNode = directive.arguments?.find((it) => it.name.value === "if");
302
+ if (ifNode == null) {
303
+ throw new import_graphql.GraphQLError(
304
+ `Directive '${directive.name.value}' is missing required arguments: 'if'`,
305
+ (0, import_compat.getGraphQLErrorOptions)([directive])
306
+ );
307
+ }
308
+ switch (ifNode.value.kind) {
309
+ case import_graphql.Kind.VARIABLE:
310
+ validateSkipIncludeVariableType(compilationContext, ifNode.value);
311
+ return `${import_execution.GLOBAL_VARIABLES_NAME}["${ifNode.value.name.value}"]`;
312
+ case import_graphql.Kind.BOOLEAN:
313
+ return `${ifNode.value.value.toString()}`;
314
+ default:
315
+ throw new import_graphql.GraphQLError(
316
+ `Argument 'if' on Directive '${directive.name.value}' has an invalid value (${(0, import_graphql.valueFromASTUntyped)(
317
+ ifNode.value
318
+ )}). Expected type 'Boolean!'`,
319
+ (0, import_compat.getGraphQLErrorOptions)([ifNode])
320
+ );
321
+ }
322
+ }
323
+ function validateSkipIncludeVariableType(compilationContext, variable) {
324
+ const variableDefinition = compilationContext.operation.variableDefinitions?.find(
325
+ (it) => it.variable.name.value === variable.name.value
326
+ );
327
+ if (variableDefinition == null) {
328
+ throw new import_graphql.GraphQLError(
329
+ `Variable '${variable.name.value}' is not defined`,
330
+ (0, import_compat.getGraphQLErrorOptions)([variable])
331
+ );
332
+ }
333
+ if (!// The variable defintion is a Non-nullable Boolean type
334
+ (variableDefinition.type.kind === import_graphql.Kind.NON_NULL_TYPE && variableDefinition.type.type.kind === import_graphql.Kind.NAMED_TYPE && variableDefinition.type.type.name.value === "Boolean" || // or the variable definition is a nullable Boolean type with a default value
335
+ variableDefinition.type.kind === import_graphql.Kind.NAMED_TYPE && variableDefinition.type.name.value === "Boolean" && variableDefinition.defaultValue != null)) {
336
+ throw new import_graphql.GraphQLError(
337
+ `Variable '${variable.name.value}' of type '${typeNodeToString(
338
+ variableDefinition.type
339
+ )}' used in position expecting type 'Boolean!'`,
340
+ (0, import_compat.getGraphQLErrorOptions)([variableDefinition])
341
+ );
342
+ }
343
+ }
344
+ function typeNodeToString(type) {
345
+ switch (type.kind) {
346
+ case import_graphql.Kind.NAMED_TYPE:
347
+ return type.name.value;
348
+ case import_graphql.Kind.NON_NULL_TYPE:
349
+ return `${typeNodeToString(type.type)}!`;
350
+ case import_graphql.Kind.LIST_TYPE:
351
+ return `[${typeNodeToString(type.type)}]`;
352
+ }
353
+ }
354
+ function doesFragmentConditionMatch(compilationContext, fragment, type) {
355
+ const typeConditionNode = fragment.typeCondition;
356
+ if (!typeConditionNode) {
357
+ return true;
358
+ }
359
+ const conditionalType = (0, import_graphql.typeFromAST)(
360
+ compilationContext.schema,
361
+ typeConditionNode
362
+ );
363
+ if (conditionalType === type) {
364
+ return true;
365
+ }
366
+ if (!conditionalType) {
367
+ return false;
368
+ }
369
+ if ((0, import_graphql.isAbstractType)(conditionalType)) {
370
+ return compilationContext.schema.isSubType(conditionalType, type);
371
+ }
372
+ return false;
373
+ }
374
+ function getFieldEntryKey(node) {
375
+ return node.alias ? node.alias.value : node.name.value;
376
+ }
377
+ function collectSubfields(compilationContext, returnType, fieldNodes, parentResponsePath) {
378
+ let subFieldNodes = /* @__PURE__ */ Object.create(null);
379
+ const visitedFragmentNames = /* @__PURE__ */ Object.create(null);
380
+ for (const fieldNode of fieldNodes) {
381
+ const selectionSet = fieldNode.selectionSet;
382
+ if (selectionSet) {
383
+ subFieldNodes = collectFields(
384
+ compilationContext,
385
+ returnType,
386
+ selectionSet,
387
+ subFieldNodes,
388
+ visitedFragmentNames,
389
+ parentResponsePath
390
+ );
391
+ }
392
+ }
393
+ return subFieldNodes;
394
+ }
395
+ function getArgumentDefs(def, node) {
396
+ const values = {};
397
+ const missing = [];
398
+ const argDefs = def.args;
399
+ const argNodes = node.arguments || [];
400
+ const argNodeMap = keyMap(argNodes, (arg) => arg.name.value);
401
+ for (const argDef of argDefs) {
402
+ const name = argDef.name;
403
+ if ((0, import_compat.hasDefaultValue)(argDef)) {
404
+ values[name] = (0, import_compat.getDefaultValue)(argDef);
405
+ }
406
+ const argType = argDef.type;
407
+ const argumentNode = argNodeMap[name];
408
+ let hasVariables = false;
409
+ if (argumentNode && argumentNode.value.kind === import_graphql.Kind.VARIABLE) {
410
+ hasVariables = true;
411
+ missing.push({
412
+ valueNode: argumentNode.value,
413
+ path: addPath(void 0, name, "literal"),
414
+ argument: { definition: argDef, node: argumentNode }
415
+ });
416
+ } else if (argumentNode) {
417
+ const coercedValue = valueFromAST(argumentNode.value, argType);
418
+ if (coercedValue === void 0) {
419
+ throw new import_graphql.GraphQLError(
420
+ `Argument "${name}" of type "${argType}" has invalid value ${(0, import_graphql.print)(
421
+ argumentNode.value
422
+ )}.`,
423
+ (0, import_compat.getGraphQLErrorOptions)(argumentNode.value)
424
+ );
425
+ }
426
+ if (isASTValueWithVariables(coercedValue)) {
427
+ missing.push(
428
+ ...coercedValue.variables.map(({ valueNode, path }) => ({
429
+ valueNode,
430
+ path: addPath(path, name, "literal")
431
+ }))
432
+ );
433
+ }
434
+ values[name] = coercedValue.value;
435
+ }
436
+ if ((0, import_graphql.isNonNullType)(argType) && values[name] === void 0 && !hasVariables) {
437
+ throw new import_graphql.GraphQLError(
438
+ argumentNode ? `Argument "${name}" of non-null type "${argType}" must not be null.` : `Argument "${name}" of required type "${argType}" was not provided.`,
439
+ (0, import_compat.getGraphQLErrorOptions)(node)
440
+ );
441
+ }
442
+ }
443
+ return { values, missing };
444
+ }
445
+ function isASTValueWithVariables(x) {
446
+ return !!x.variables;
447
+ }
448
+ function valueFromAST(valueNode, type) {
449
+ if ((0, import_graphql.isNonNullType)(type)) {
450
+ if (valueNode.kind === import_graphql.Kind.NULL) {
451
+ return;
452
+ }
453
+ return valueFromAST(valueNode, type.ofType);
454
+ }
455
+ if (valueNode.kind === import_graphql.Kind.NULL) {
456
+ return {
457
+ value: null
458
+ };
459
+ }
460
+ if (valueNode.kind === import_graphql.Kind.VARIABLE) {
461
+ return { value: null, variables: [{ valueNode, path: void 0 }] };
462
+ }
463
+ if ((0, import_graphql.isListType)(type)) {
464
+ const itemType = type.ofType;
465
+ if (valueNode.kind === import_graphql.Kind.LIST) {
466
+ const coercedValues = [];
467
+ const variables = [];
468
+ const itemNodes = valueNode.values;
469
+ for (let i = 0; i < itemNodes.length; i++) {
470
+ const itemNode = itemNodes[i];
471
+ if (itemNode.kind === import_graphql.Kind.VARIABLE) {
472
+ coercedValues.push(null);
473
+ variables.push({
474
+ valueNode: itemNode,
475
+ path: addPath(void 0, i.toString(), "literal")
476
+ });
477
+ } else {
478
+ const itemValue = valueFromAST(itemNode, itemType);
479
+ if (!itemValue) {
480
+ return;
481
+ }
482
+ coercedValues.push(itemValue.value);
483
+ if (isASTValueWithVariables(itemValue)) {
484
+ variables.push(
485
+ ...itemValue.variables.map(({ valueNode: valueNode2, path }) => ({
486
+ valueNode: valueNode2,
487
+ path: addPath(path, i.toString(), "literal")
488
+ }))
489
+ );
490
+ }
491
+ }
492
+ }
493
+ return { value: coercedValues, variables };
494
+ }
495
+ const coercedValue = valueFromAST(valueNode, itemType);
496
+ if (coercedValue === void 0) {
497
+ return;
498
+ }
499
+ if (isASTValueWithVariables(coercedValue)) {
500
+ return {
501
+ value: [coercedValue.value],
502
+ variables: coercedValue.variables.map(({ valueNode: valueNode2, path }) => ({
503
+ valueNode: valueNode2,
504
+ path: addPath(path, "0", "literal")
505
+ }))
506
+ };
507
+ }
508
+ return { value: [coercedValue.value] };
509
+ }
510
+ if ((0, import_graphql.isInputObjectType)(type)) {
511
+ if (valueNode.kind !== import_graphql.Kind.OBJECT) {
512
+ return;
513
+ }
514
+ const coercedObj = /* @__PURE__ */ Object.create(null);
515
+ const variables = [];
516
+ const fieldNodes = keyMap(valueNode.fields, (field) => field.name.value);
517
+ const fields = Object.values(type.getFields());
518
+ for (const field of fields) {
519
+ if ((0, import_compat.hasDefaultValue)(field)) {
520
+ coercedObj[field.name] = (0, import_compat.getDefaultValue)(field);
521
+ }
522
+ const fieldNode = fieldNodes[field.name];
523
+ if (!fieldNode) {
524
+ continue;
525
+ }
526
+ const fieldValue = valueFromAST(fieldNode.value, field.type);
527
+ if (!fieldValue) {
528
+ return;
529
+ }
530
+ if (isASTValueWithVariables(fieldValue)) {
531
+ variables.push(
532
+ ...fieldValue.variables.map(({ valueNode: valueNode2, path }) => ({
533
+ valueNode: valueNode2,
534
+ path: addPath(path, field.name, "literal")
535
+ }))
536
+ );
537
+ }
538
+ coercedObj[field.name] = fieldValue.value;
539
+ }
540
+ return { value: coercedObj, variables };
541
+ }
542
+ if ((0, import_graphql.isEnumType)(type)) {
543
+ if (valueNode.kind !== import_graphql.Kind.ENUM) {
544
+ return;
545
+ }
546
+ const enumValue = type.getValue(valueNode.value);
547
+ if (!enumValue) {
548
+ return;
549
+ }
550
+ return { value: enumValue.value };
551
+ }
552
+ if ((0, import_graphql.isScalarType)(type)) {
553
+ let result;
554
+ try {
555
+ result = (0, import_compat.coerceInputLiteral)(type, valueNode);
556
+ } catch (error) {
557
+ return;
558
+ }
559
+ if (isInvalid(result)) {
560
+ return;
561
+ }
562
+ return { value: result };
563
+ }
564
+ throw new Error(`Unexpected input type: "${inspect(type)}".`);
565
+ }
566
+ function keyMap(list, keyFn) {
567
+ return list.reduce(
568
+ // eslint-disable-next-line no-sequences
569
+ (map, item) => (map[keyFn(item)] = item, map),
570
+ /* @__PURE__ */ Object.create(null)
571
+ );
572
+ }
573
+ function computeLocations(nodes) {
574
+ return nodes.reduce((list, node) => {
575
+ if (node.loc) {
576
+ list.push(getLocation(node.loc));
577
+ }
578
+ return list;
579
+ }, []);
580
+ }
581
+ function getLocation(loc) {
582
+ return {
583
+ line: loc.startToken.line,
584
+ column: loc.startToken.column
585
+ };
586
+ }
587
+ function addPath(responsePath, key, type = "literal") {
588
+ return { prev: responsePath, key, type };
589
+ }
590
+ function flattenPath(path) {
591
+ const flattened = [];
592
+ let curr = path;
593
+ while (curr) {
594
+ flattened.push({ key: curr.key, type: curr.type });
595
+ curr = curr.prev;
596
+ }
597
+ return flattened;
598
+ }
599
+ function serializeObjectPathForSkipInclude(path) {
600
+ let serialized = "";
601
+ let curr = path;
602
+ while (curr) {
603
+ if (curr.type === "literal") {
604
+ serialized = joinSkipIncludePath(curr.key, serialized);
605
+ }
606
+ curr = curr.prev;
607
+ }
608
+ return serialized;
609
+ }
610
+ function joinSkipIncludePath(a, b) {
611
+ if (a) {
612
+ if (b) {
613
+ return `${a}.${b}`;
614
+ }
615
+ return a;
616
+ }
617
+ return b;
618
+ }
619
+ function isInvalid(value) {
620
+ return value === void 0 || value !== value;
621
+ }
622
+ // Annotate the CommonJS export names for ESM import in node:
623
+ 0 && (module.exports = {
624
+ addPath,
625
+ collectFields,
626
+ collectSubfields,
627
+ computeLocations,
628
+ flattenPath,
629
+ getArgumentDefs,
630
+ joinSkipIncludePath,
631
+ resolveFieldDef,
632
+ serializeObjectPathForSkipInclude,
633
+ valueFromAST
634
+ });
635
+ //# sourceMappingURL=ast.js.map