graphql-jit 0.8.9 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -0
- package/dist/cjs/ast.d.ts +89 -0
- package/dist/cjs/ast.js +766 -0
- package/dist/cjs/ast.js.map +1 -0
- package/dist/cjs/compat.d.ts +70 -0
- package/dist/cjs/compat.js +144 -0
- package/dist/cjs/compat.js.map +1 -0
- package/dist/cjs/debug.d.ts +29 -0
- package/dist/cjs/debug.js +46 -0
- package/dist/cjs/debug.js.map +1 -0
- package/dist/cjs/error.d.ts +7 -0
- package/dist/cjs/error.js +58 -0
- package/dist/cjs/error.js.map +1 -0
- package/dist/cjs/execution.d.ts +154 -0
- package/dist/cjs/execution.js +1240 -0
- package/dist/cjs/execution.js.map +1 -0
- package/dist/cjs/generate.d.ts +4 -0
- package/dist/cjs/generate.js +13 -0
- package/dist/cjs/generate.js.map +1 -0
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.js +10 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/inspect.d.ts +5 -0
- package/dist/cjs/inspect.js +110 -0
- package/dist/cjs/inspect.js.map +1 -0
- package/dist/cjs/json.d.ts +9 -0
- package/dist/cjs/json.js +144 -0
- package/dist/cjs/json.js.map +1 -0
- package/dist/cjs/memoize.d.ts +5 -0
- package/dist/cjs/memoize.js +28 -0
- package/dist/cjs/memoize.js.map +1 -0
- package/dist/cjs/non-null.d.ts +9 -0
- package/dist/cjs/non-null.js +205 -0
- package/dist/cjs/non-null.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/{resolve-info.d.ts → cjs/resolve-info.d.ts} +10 -12
- package/dist/cjs/resolve-info.js +232 -0
- package/dist/cjs/resolve-info.js.map +1 -0
- package/dist/cjs/runtime.d.ts +14 -0
- package/dist/cjs/runtime.js +92 -0
- package/dist/cjs/runtime.js.map +1 -0
- package/dist/cjs/types.d.ts +1 -0
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/variables.d.ts +20 -0
- package/dist/cjs/variables.js +357 -0
- package/dist/cjs/variables.js.map +1 -0
- package/dist/esm/ast.d.ts +89 -0
- package/dist/esm/ast.js +751 -0
- package/dist/esm/ast.js.map +1 -0
- package/dist/esm/compat.d.ts +70 -0
- package/dist/esm/compat.js +102 -0
- package/dist/esm/compat.js.map +1 -0
- package/dist/esm/debug.d.ts +29 -0
- package/dist/esm/debug.js +40 -0
- package/dist/esm/debug.js.map +1 -0
- package/dist/esm/error.d.ts +7 -0
- package/dist/esm/error.js +55 -0
- package/dist/esm/error.js.map +1 -0
- package/dist/esm/execution.d.ts +154 -0
- package/dist/esm/execution.js +1227 -0
- package/dist/esm/execution.js.map +1 -0
- package/dist/esm/generate.d.ts +4 -0
- package/dist/esm/generate.js +10 -0
- package/dist/esm/generate.js.map +1 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/inspect.d.ts +5 -0
- package/dist/esm/inspect.js +106 -0
- package/dist/esm/inspect.js.map +1 -0
- package/dist/esm/json.d.ts +9 -0
- package/dist/esm/json.js +141 -0
- package/dist/esm/json.js.map +1 -0
- package/dist/esm/memoize.d.ts +5 -0
- package/dist/esm/memoize.js +20 -0
- package/dist/esm/memoize.js.map +1 -0
- package/dist/esm/non-null.d.ts +9 -0
- package/dist/esm/non-null.js +199 -0
- package/dist/esm/non-null.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/{resolve-info.d.mts → esm/resolve-info.d.ts} +10 -12
- package/dist/esm/resolve-info.js +224 -0
- package/dist/esm/resolve-info.js.map +1 -0
- package/dist/esm/runtime.d.ts +14 -0
- package/dist/esm/runtime.js +89 -0
- package/dist/esm/runtime.js.map +1 -0
- package/dist/esm/types.d.ts +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/variables.d.ts +20 -0
- package/dist/esm/variables.js +350 -0
- package/dist/esm/variables.js.map +1 -0
- package/package.json +39 -35
- package/dist/ast.d.mts +0 -7
- package/dist/ast.d.ts +0 -7
- package/dist/ast.js +0 -635
- package/dist/ast.js.map +0 -1
- package/dist/ast.mjs +0 -612
- package/dist/ast.mjs.map +0 -1
- package/dist/compat.d.mts +0 -7
- package/dist/compat.d.ts +0 -7
- package/dist/compat.js +0 -113
- package/dist/compat.js.map +0 -1
- package/dist/compat.mjs +0 -75
- package/dist/compat.mjs.map +0 -1
- package/dist/error.d.mts +0 -11
- package/dist/error.d.ts +0 -11
- package/dist/error.js +0 -79
- package/dist/error.js.map +0 -1
- package/dist/error.mjs +0 -57
- package/dist/error.mjs.map +0 -1
- package/dist/execution.d.mts +0 -7
- package/dist/execution.d.ts +0 -7
- package/dist/execution.js +0 -1262
- package/dist/execution.js.map +0 -1
- package/dist/execution.mjs +0 -1248
- package/dist/execution.mjs.map +0 -1
- package/dist/generate.d.mts +0 -6
- package/dist/generate.d.ts +0 -6
- package/dist/generate.js +0 -37
- package/dist/generate.js.map +0 -1
- package/dist/generate.mjs +0 -13
- package/dist/generate.mjs.map +0 -1
- package/dist/index-CeluTkd4.d.mts +0 -329
- package/dist/index-mKv2zpdA.d.ts +0 -329
- package/dist/index.d.mts +0 -7
- package/dist/index.d.ts +0 -7
- package/dist/index.js +0 -36
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -15
- package/dist/index.mjs.map +0 -1
- package/dist/inspect.d.mts +0 -7
- package/dist/inspect.d.ts +0 -7
- package/dist/inspect.js +0 -121
- package/dist/inspect.js.map +0 -1
- package/dist/inspect.mjs +0 -97
- package/dist/inspect.mjs.map +0 -1
- package/dist/json.d.mts +0 -18
- package/dist/json.d.ts +0 -18
- package/dist/json.js +0 -181
- package/dist/json.js.map +0 -1
- package/dist/json.mjs +0 -164
- package/dist/json.mjs.map +0 -1
- package/dist/memoize.d.mts +0 -6
- package/dist/memoize.d.ts +0 -6
- package/dist/memoize.js +0 -67
- package/dist/memoize.js.map +0 -1
- package/dist/memoize.mjs +0 -31
- package/dist/memoize.mjs.map +0 -1
- package/dist/non-null.d.mts +0 -7
- package/dist/non-null.d.ts +0 -7
- package/dist/non-null.js +0 -196
- package/dist/non-null.js.map +0 -1
- package/dist/non-null.mjs +0 -167
- package/dist/non-null.mjs.map +0 -1
- package/dist/resolve-info.js +0 -245
- package/dist/resolve-info.js.map +0 -1
- package/dist/resolve-info.mjs +0 -219
- package/dist/resolve-info.mjs.map +0 -1
- package/dist/runtime.d.mts +0 -7
- package/dist/runtime.d.ts +0 -7
- package/dist/runtime.js +0 -115
- package/dist/runtime.js.map +0 -1
- package/dist/runtime.mjs +0 -91
- package/dist/runtime.mjs.map +0 -1
- package/dist/types.d.mts +0 -3
- package/dist/types.d.ts +0 -3
- package/dist/types.js +0 -17
- package/dist/types.js.map +0 -1
- package/dist/types.mjs +0 -1
- package/dist/types.mjs.map +0 -1
- package/dist/variables.d.mts +0 -17
- package/dist/variables.d.ts +0 -17
- package/dist/variables.js +0 -412
- package/dist/variables.js.map +0 -1
- package/dist/variables.mjs +0 -391
- package/dist/variables.mjs.map +0 -1
package/dist/ast.js
DELETED
|
@@ -1,635 +0,0 @@
|
|
|
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
|