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