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