@graphitation/supermassive 2.6.1 → 3.0.0-alpha.3
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/.eslintcache +1 -1
- package/CHANGELOG.md +17 -1
- package/lib/__testUtils__/execute.d.ts +13 -0
- package/lib/__testUtils__/execute.d.ts.map +1 -0
- package/lib/__testUtils__/execute.js +196 -0
- package/lib/__testUtils__/execute.js.map +7 -0
- package/lib/__testUtils__/execute.mjs +174 -0
- package/lib/__testUtils__/execute.mjs.map +7 -0
- package/lib/benchmarks/index.js +11 -20
- package/lib/benchmarks/index.js.map +3 -3
- package/lib/benchmarks/index.mjs +12 -23
- package/lib/benchmarks/index.mjs.map +2 -2
- package/lib/benchmarks/swapi-schema/index.d.ts +4 -2
- package/lib/benchmarks/swapi-schema/index.d.ts.map +1 -1
- package/lib/benchmarks/swapi-schema/index.js +8 -2
- package/lib/benchmarks/swapi-schema/index.js.map +2 -2
- package/lib/benchmarks/swapi-schema/index.mjs +8 -2
- package/lib/benchmarks/swapi-schema/index.mjs.map +2 -2
- package/lib/benchmarks/swapi-schema/makeExecutableSchema.d.ts +7 -0
- package/lib/benchmarks/swapi-schema/makeExecutableSchema.d.ts.map +1 -0
- package/lib/benchmarks/swapi-schema/makeExecutableSchema.js +916 -0
- package/lib/benchmarks/swapi-schema/makeExecutableSchema.js.map +7 -0
- package/lib/benchmarks/swapi-schema/makeExecutableSchema.mjs +903 -0
- package/lib/benchmarks/swapi-schema/makeExecutableSchema.mjs.map +7 -0
- package/lib/benchmarks/swapi-schema/resolvers.d.ts.map +1 -1
- package/lib/benchmarks/swapi-schema/resolvers.js +53 -17
- package/lib/benchmarks/swapi-schema/resolvers.js.map +2 -2
- package/lib/benchmarks/swapi-schema/resolvers.mjs +54 -18
- package/lib/benchmarks/swapi-schema/resolvers.mjs.map +2 -2
- package/lib/collectFields.d.ts +27 -10
- package/lib/collectFields.d.ts.map +1 -1
- package/lib/collectFields.js +146 -80
- package/lib/collectFields.js.map +3 -3
- package/lib/collectFields.mjs +143 -81
- package/lib/collectFields.mjs.map +2 -2
- package/lib/executeWithSchema.d.ts +1 -1
- package/lib/executeWithSchema.d.ts.map +1 -1
- package/lib/executeWithSchema.js +7 -13
- package/lib/executeWithSchema.js.map +2 -2
- package/lib/executeWithSchema.mjs +9 -20
- package/lib/executeWithSchema.mjs.map +2 -2
- package/lib/executeWithoutSchema.d.ts +53 -16
- package/lib/executeWithoutSchema.d.ts.map +1 -1
- package/lib/executeWithoutSchema.js +1076 -274
- package/lib/executeWithoutSchema.js.map +3 -3
- package/lib/executeWithoutSchema.mjs +1092 -281
- package/lib/executeWithoutSchema.mjs.map +3 -3
- package/lib/index.d.ts +3 -9
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -7
- package/lib/index.js.map +2 -2
- package/lib/index.mjs +3 -10
- package/lib/index.mjs.map +2 -2
- package/lib/jsutils/AccumulatorMap.d.ts +8 -0
- package/lib/jsutils/AccumulatorMap.d.ts.map +1 -0
- package/lib/jsutils/AccumulatorMap.js +36 -0
- package/lib/jsutils/AccumulatorMap.js.map +7 -0
- package/lib/jsutils/AccumulatorMap.mjs +17 -0
- package/lib/jsutils/AccumulatorMap.mjs.map +7 -0
- package/lib/jsutils/didYouMean.d.ts +1 -2
- package/lib/jsutils/didYouMean.d.ts.map +1 -1
- package/lib/jsutils/didYouMean.js.map +2 -2
- package/lib/jsutils/didYouMean.mjs.map +2 -2
- package/lib/jsutils/instanceOf.js.map +2 -2
- package/lib/jsutils/instanceOf.mjs.map +2 -2
- package/lib/schema/definition.d.ts +95 -0
- package/lib/schema/definition.d.ts.map +1 -0
- package/lib/schema/definition.js +77 -0
- package/lib/schema/definition.js.map +7 -0
- package/lib/schema/definition.mjs +58 -0
- package/lib/schema/definition.mjs.map +7 -0
- package/lib/schema/directives.d.ts +41 -0
- package/lib/schema/directives.d.ts.map +1 -0
- package/lib/schema/directives.js +82 -0
- package/lib/schema/directives.js.map +7 -0
- package/lib/schema/directives.mjs +65 -0
- package/lib/schema/directives.mjs.map +7 -0
- package/lib/schema/fragment.d.ts +41 -0
- package/lib/schema/fragment.d.ts.map +1 -0
- package/lib/schema/fragment.js +270 -0
- package/lib/schema/fragment.js.map +7 -0
- package/lib/schema/fragment.mjs +267 -0
- package/lib/schema/fragment.mjs.map +7 -0
- package/lib/schema/reference.d.ts +12 -0
- package/lib/schema/reference.d.ts.map +1 -0
- package/lib/schema/reference.js +137 -0
- package/lib/schema/reference.js.map +7 -0
- package/lib/schema/reference.mjs +118 -0
- package/lib/schema/reference.mjs.map +7 -0
- package/lib/schema/resolvers.d.ts +9 -0
- package/lib/schema/resolvers.d.ts.map +1 -0
- package/lib/schema/resolvers.js +47 -0
- package/lib/schema/resolvers.js.map +7 -0
- package/lib/schema/resolvers.mjs +35 -0
- package/lib/schema/resolvers.mjs.map +7 -0
- package/lib/subscribeWithSchema.d.ts +3 -2
- package/lib/subscribeWithSchema.d.ts.map +1 -1
- package/lib/subscribeWithSchema.js +7 -13
- package/lib/subscribeWithSchema.js.map +2 -2
- package/lib/subscribeWithSchema.mjs +9 -20
- package/lib/subscribeWithSchema.mjs.map +2 -2
- package/lib/subscribeWithoutSchema.d.ts +3 -35
- package/lib/subscribeWithoutSchema.d.ts.map +1 -1
- package/lib/subscribeWithoutSchema.js +1 -163
- package/lib/subscribeWithoutSchema.js.map +2 -2
- package/lib/subscribeWithoutSchema.mjs +2 -175
- package/lib/subscribeWithoutSchema.mjs.map +2 -2
- package/lib/types.d.ts +71 -29
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +14 -0
- package/lib/types.js.map +2 -2
- package/lib/types.mjs +11 -0
- package/lib/types.mjs.map +3 -3
- package/lib/utilities/addMinimalViableSchemaToRequestDocument.d.ts +9 -0
- package/lib/utilities/addMinimalViableSchemaToRequestDocument.d.ts.map +1 -0
- package/lib/utilities/addMinimalViableSchemaToRequestDocument.js +303 -0
- package/lib/utilities/addMinimalViableSchemaToRequestDocument.js.map +7 -0
- package/lib/utilities/addMinimalViableSchemaToRequestDocument.mjs +317 -0
- package/lib/utilities/addMinimalViableSchemaToRequestDocument.mjs.map +7 -0
- package/lib/utilities/annotateDocumentGraphQLTransform.d.ts +3 -0
- package/lib/utilities/annotateDocumentGraphQLTransform.d.ts.map +1 -0
- package/lib/utilities/annotateDocumentGraphQLTransform.js +34 -0
- package/lib/utilities/annotateDocumentGraphQLTransform.js.map +7 -0
- package/lib/utilities/annotateDocumentGraphQLTransform.mjs +17 -0
- package/lib/utilities/annotateDocumentGraphQLTransform.mjs.map +7 -0
- package/lib/utilities/coerceInputValue.d.ts +10 -0
- package/lib/utilities/coerceInputValue.d.ts.map +1 -0
- package/lib/utilities/coerceInputValue.js +181 -0
- package/lib/utilities/coerceInputValue.js.map +7 -0
- package/lib/utilities/coerceInputValue.mjs +167 -0
- package/lib/utilities/coerceInputValue.mjs.map +7 -0
- package/lib/utilities/decodeASTSchema.d.ts +7 -0
- package/lib/utilities/decodeASTSchema.d.ts.map +1 -0
- package/lib/utilities/decodeASTSchema.js +243 -0
- package/lib/utilities/decodeASTSchema.js.map +7 -0
- package/lib/utilities/decodeASTSchema.mjs +242 -0
- package/lib/utilities/decodeASTSchema.mjs.map +7 -0
- package/lib/utilities/encodeASTSchema.d.ts +4 -0
- package/lib/utilities/encodeASTSchema.d.ts.map +1 -0
- package/lib/utilities/encodeASTSchema.js +122 -0
- package/lib/utilities/encodeASTSchema.js.map +7 -0
- package/lib/utilities/encodeASTSchema.mjs +105 -0
- package/lib/utilities/encodeASTSchema.mjs.map +7 -0
- package/lib/utilities/getSchemaFragment.d.ts +4 -0
- package/lib/utilities/getSchemaFragment.d.ts.map +1 -0
- package/lib/utilities/getSchemaFragment.js +38 -0
- package/lib/utilities/getSchemaFragment.js.map +7 -0
- package/lib/utilities/getSchemaFragment.mjs +22 -0
- package/lib/utilities/getSchemaFragment.mjs.map +7 -0
- package/lib/utilities/makeReadableErrorPath.d.ts +3 -0
- package/lib/utilities/makeReadableErrorPath.d.ts.map +1 -0
- package/lib/utilities/makeReadableErrorPath.js +47 -0
- package/lib/utilities/makeReadableErrorPath.js.map +7 -0
- package/lib/utilities/makeReadableErrorPath.mjs +28 -0
- package/lib/utilities/makeReadableErrorPath.mjs.map +7 -0
- package/lib/utilities/mergeDefinitions.d.ts +8 -0
- package/lib/utilities/mergeDefinitions.d.ts.map +1 -0
- package/lib/utilities/mergeDefinitions.js +126 -0
- package/lib/utilities/mergeDefinitions.js.map +7 -0
- package/lib/utilities/mergeDefinitions.mjs +114 -0
- package/lib/utilities/mergeDefinitions.mjs.map +7 -0
- package/lib/utilities/mergeResolvers.d.ts +1 -1
- package/lib/utilities/mergeResolvers.d.ts.map +1 -1
- package/lib/utilities/mergeResolvers.js.map +2 -2
- package/lib/utilities/mergeResolvers.mjs.map +2 -2
- package/lib/utilities/typeNameFromAST.d.ts +1 -1
- package/lib/utilities/typeNameFromAST.d.ts.map +1 -1
- package/lib/utilities/typeNameFromAST.js.map +2 -2
- package/lib/utilities/typeNameFromAST.mjs.map +2 -2
- package/lib/utilities/valueFromAST.d.ts +27 -0
- package/lib/utilities/valueFromAST.d.ts.map +1 -0
- package/lib/utilities/valueFromAST.js +139 -0
- package/lib/utilities/valueFromAST.js.map +7 -0
- package/lib/utilities/valueFromAST.mjs +125 -0
- package/lib/utilities/valueFromAST.mjs.map +7 -0
- package/lib/utilities/valueFromASTUntyped.d.ts +21 -0
- package/lib/utilities/valueFromASTUntyped.d.ts.map +1 -0
- package/lib/utilities/valueFromASTUntyped.js +51 -0
- package/lib/utilities/valueFromASTUntyped.js.map +7 -0
- package/lib/utilities/valueFromASTUntyped.mjs +32 -0
- package/lib/utilities/valueFromASTUntyped.mjs.map +7 -0
- package/lib/values.d.ts +8 -13
- package/lib/values.d.ts.map +1 -1
- package/lib/values.js +83 -75
- package/lib/values.js.map +2 -2
- package/lib/values.mjs +85 -83
- package/lib/values.mjs.map +2 -2
- package/package.json +8 -9
- package/lib/definition.d.ts +0 -7
- package/lib/definition.d.ts.map +0 -1
- package/lib/definition.js +0 -59
- package/lib/definition.js.map +0 -7
- package/lib/definition.mjs +0 -40
- package/lib/definition.mjs.map +0 -7
- package/lib/directives.d.ts +0 -79
- package/lib/directives.d.ts.map +0 -1
- package/lib/directives.js +0 -160
- package/lib/directives.js.map +0 -7
- package/lib/directives.mjs +0 -146
- package/lib/directives.mjs.map +0 -7
- package/lib/extractImplicitTypesRuntime.d.ts +0 -4
- package/lib/extractImplicitTypesRuntime.d.ts.map +0 -1
- package/lib/extractImplicitTypesRuntime.js +0 -123
- package/lib/extractImplicitTypesRuntime.js.map +0 -7
- package/lib/extractImplicitTypesRuntime.mjs +0 -114
- package/lib/extractImplicitTypesRuntime.mjs.map +0 -7
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
|
|
21
|
+
// src/utilities/addMinimalViableSchemaToRequestDocument.ts
|
|
22
|
+
import {
|
|
23
|
+
GraphQLError,
|
|
24
|
+
isCompositeType,
|
|
25
|
+
isEnumType,
|
|
26
|
+
isInputObjectType,
|
|
27
|
+
isNonNullType,
|
|
28
|
+
isObjectType,
|
|
29
|
+
isScalarType,
|
|
30
|
+
isSpecifiedScalarType,
|
|
31
|
+
isUnionType,
|
|
32
|
+
Kind,
|
|
33
|
+
TypeInfo,
|
|
34
|
+
visit,
|
|
35
|
+
visitWithTypeInfo
|
|
36
|
+
} from "graphql";
|
|
37
|
+
import {
|
|
38
|
+
DirectiveKeys,
|
|
39
|
+
FieldKeys,
|
|
40
|
+
InputObjectKeys,
|
|
41
|
+
InputValueKeys,
|
|
42
|
+
InterfaceKeys,
|
|
43
|
+
ObjectKeys,
|
|
44
|
+
TypeKind
|
|
45
|
+
} from "../schema/definition.mjs";
|
|
46
|
+
import {
|
|
47
|
+
inspectTypeReference,
|
|
48
|
+
typeNameFromReference,
|
|
49
|
+
typeReferenceFromName
|
|
50
|
+
} from "../schema/reference.mjs";
|
|
51
|
+
import { invariant } from "../jsutils/invariant.mjs";
|
|
52
|
+
import {
|
|
53
|
+
isSpecifiedDirective,
|
|
54
|
+
SUPERMASSIVE_SCHEMA_DIRECTIVE_FRAGMENT_ARGUMENT_NAME,
|
|
55
|
+
SUPERMASSIVE_SCHEMA_DIRECTIVE_NAME
|
|
56
|
+
} from "../schema/directives.mjs";
|
|
57
|
+
import { makeReadableErrorPath } from "./makeReadableErrorPath.mjs";
|
|
58
|
+
function addMinimalViableSchemaToRequestDocument(schema, document, options) {
|
|
59
|
+
return __spreadProps(__spreadValues({}, document), {
|
|
60
|
+
definitions: document.definitions.map(
|
|
61
|
+
(node) => node.kind === Kind.OPERATION_DEFINITION || node.kind === Kind.FRAGMENT_DEFINITION ? addMinimalViableSchemaToExecutableDefinitionNode(
|
|
62
|
+
schema,
|
|
63
|
+
node,
|
|
64
|
+
options
|
|
65
|
+
) : node
|
|
66
|
+
)
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function addMinimalViableSchemaToExecutableDefinitionNode(schema, node, options) {
|
|
70
|
+
var _a, _b;
|
|
71
|
+
if ((_a = node.directives) == null ? void 0 : _a.some((directive2) => directive2.name.value === "schema")) {
|
|
72
|
+
return node;
|
|
73
|
+
}
|
|
74
|
+
const schemaFragment = extractMinimalViableSchemaForRequestDocument(
|
|
75
|
+
schema,
|
|
76
|
+
{ kind: Kind.DOCUMENT, definitions: [node] },
|
|
77
|
+
options
|
|
78
|
+
);
|
|
79
|
+
const directive = {
|
|
80
|
+
kind: Kind.DIRECTIVE,
|
|
81
|
+
name: nameNode(SUPERMASSIVE_SCHEMA_DIRECTIVE_NAME),
|
|
82
|
+
arguments: [
|
|
83
|
+
argNode(
|
|
84
|
+
SUPERMASSIVE_SCHEMA_DIRECTIVE_FRAGMENT_ARGUMENT_NAME,
|
|
85
|
+
schemaFragment
|
|
86
|
+
)
|
|
87
|
+
]
|
|
88
|
+
};
|
|
89
|
+
return __spreadProps(__spreadValues({}, node), {
|
|
90
|
+
directives: [...(_b = node.directives) != null ? _b : [], directive]
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
function nameNode(name) {
|
|
94
|
+
return { kind: Kind.NAME, value: name };
|
|
95
|
+
}
|
|
96
|
+
function argNode(name, value) {
|
|
97
|
+
return {
|
|
98
|
+
kind: Kind.ARGUMENT,
|
|
99
|
+
name: nameNode(name),
|
|
100
|
+
value: { kind: Kind.STRING, value: JSON.stringify(value) }
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function extractMinimalViableSchemaForRequestDocument(schema, document, options) {
|
|
104
|
+
const types = /* @__PURE__ */ Object.create(null);
|
|
105
|
+
const directives = [];
|
|
106
|
+
const typeInfo = new TypeInfo(schema);
|
|
107
|
+
visit(
|
|
108
|
+
document,
|
|
109
|
+
visitWithTypeInfo(typeInfo, {
|
|
110
|
+
Field(node, _key, _parent, _path, ancestors) {
|
|
111
|
+
const parentType = typeInfo.getParentType();
|
|
112
|
+
assertCompositeType(parentType, node, ancestors);
|
|
113
|
+
const typeDef = addCompositeType(types, parentType);
|
|
114
|
+
if (typeDef[0] === TypeKind.UNION || node.name.value === "__typename") {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const field = typeInfo.getFieldDef();
|
|
118
|
+
assertExistingField(field, node, ancestors);
|
|
119
|
+
assertAllArgumentsAreDefined(field, node, ancestors);
|
|
120
|
+
const fieldDef = addField(typeDef, field, node);
|
|
121
|
+
if (Array.isArray(fieldDef)) {
|
|
122
|
+
addReferencedOutputType(schema, types, fieldDef[FieldKeys.type]);
|
|
123
|
+
addReferencedInputTypes(schema, types, fieldDef[FieldKeys.arguments]);
|
|
124
|
+
} else {
|
|
125
|
+
addReferencedOutputType(schema, types, fieldDef);
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
Directive(node, _key, _parent, _path, ancestors) {
|
|
129
|
+
var _a;
|
|
130
|
+
if (isSpecifiedDirective(node.name.value) || ((_a = options == null ? void 0 : options.ignoredDirectives) == null ? void 0 : _a.includes(node.name.value))) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const directive = typeInfo.getDirective();
|
|
134
|
+
if (!directive) {
|
|
135
|
+
const errorPath = makeReadableErrorPath(ancestors);
|
|
136
|
+
throw new GraphQLError(
|
|
137
|
+
`Cannot find definition for directive: ${errorPath.join(".")} @${node.name.value}`,
|
|
138
|
+
{ nodes: node }
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
addDirective(directives, directive, node);
|
|
142
|
+
},
|
|
143
|
+
FragmentDefinition(node, _key, _parent, _path, ancestors) {
|
|
144
|
+
const type = typeInfo.getType();
|
|
145
|
+
assertCompositeType(type, node, ancestors);
|
|
146
|
+
addCompositeType(types, type);
|
|
147
|
+
},
|
|
148
|
+
InlineFragment(node, _key, _parent, _path, ancestors) {
|
|
149
|
+
if (node == null ? void 0 : node.typeCondition) {
|
|
150
|
+
const type = typeInfo.getType();
|
|
151
|
+
assertCompositeType(type, node, ancestors);
|
|
152
|
+
addCompositeType(types, type);
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
Argument() {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
})
|
|
159
|
+
);
|
|
160
|
+
return directives.length ? { types, directives } : { types };
|
|
161
|
+
}
|
|
162
|
+
function addReferencedOutputType(schema, types, typeRef) {
|
|
163
|
+
const name = typeNameFromReference(typeRef);
|
|
164
|
+
const schemaType = schema.getType(name);
|
|
165
|
+
if (!schemaType) {
|
|
166
|
+
throw new Error(`Type ${name} not found in schema`);
|
|
167
|
+
}
|
|
168
|
+
if (types[name] || isSpecifiedScalarType(schemaType)) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (isCompositeType(schemaType)) {
|
|
172
|
+
addCompositeType(types, schemaType);
|
|
173
|
+
} else if (isEnumType(schemaType)) {
|
|
174
|
+
types[name] = encodeEnumType(schemaType);
|
|
175
|
+
} else if (isScalarType(schemaType)) {
|
|
176
|
+
types[name] = encodeScalarType(schemaType);
|
|
177
|
+
} else {
|
|
178
|
+
invariant(false, "Got non-output type: " + inspectTypeReference(typeRef));
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function addReferencedInputTypes(schema, types, inputValues) {
|
|
182
|
+
for (const inputValueDef of Object.values(inputValues)) {
|
|
183
|
+
const typeRef = Array.isArray(inputValueDef) ? inputValueDef[InputValueKeys.type] : inputValueDef;
|
|
184
|
+
const name = typeNameFromReference(typeRef);
|
|
185
|
+
const schemaType = schema.getType(name);
|
|
186
|
+
if (!schemaType) {
|
|
187
|
+
throw new Error(`Type ${name} not found in schema`);
|
|
188
|
+
}
|
|
189
|
+
if (types[name] || isSpecifiedScalarType(schemaType)) {
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
if (isInputObjectType(schemaType)) {
|
|
193
|
+
const inputObjectDef = encodeInputObjectType(schemaType);
|
|
194
|
+
types[name] = inputObjectDef;
|
|
195
|
+
addReferencedInputTypes(
|
|
196
|
+
schema,
|
|
197
|
+
types,
|
|
198
|
+
inputObjectDef[InputObjectKeys.fields]
|
|
199
|
+
);
|
|
200
|
+
} else if (isEnumType(schemaType)) {
|
|
201
|
+
types[name] = encodeEnumType(schemaType);
|
|
202
|
+
} else if (isScalarType(schemaType)) {
|
|
203
|
+
types[name] = encodeScalarType(schemaType);
|
|
204
|
+
} else {
|
|
205
|
+
invariant(false, "Got non-input type: " + inspectTypeReference(typeRef));
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
function addCompositeType(types, type) {
|
|
210
|
+
if (types[type.name]) {
|
|
211
|
+
return types[type.name];
|
|
212
|
+
}
|
|
213
|
+
return types[type.name] = encodeCompositeType(type);
|
|
214
|
+
}
|
|
215
|
+
function addField(type, field, fieldNode) {
|
|
216
|
+
var _a;
|
|
217
|
+
const fields = type[0] === TypeKind.OBJECT ? type[ObjectKeys.fields] : type[InterfaceKeys.fields];
|
|
218
|
+
const existingFieldDef = fields[field.name];
|
|
219
|
+
const previouslyAddedArgs = Array.isArray(existingFieldDef) ? existingFieldDef[FieldKeys.arguments] : /* @__PURE__ */ Object.create(null);
|
|
220
|
+
const nodeArgs = new Set((_a = fieldNode.arguments) == null ? void 0 : _a.map((arg) => arg.name.value));
|
|
221
|
+
const argsFilter = (argDef) => Boolean(
|
|
222
|
+
previouslyAddedArgs[argDef.name] || isNonNullType(argDef.type) || argDef.defaultValue !== void 0 || nodeArgs.has(argDef.name)
|
|
223
|
+
);
|
|
224
|
+
return fields[field.name] = encodeFieldDef(field, argsFilter);
|
|
225
|
+
}
|
|
226
|
+
function addDirective(directives, directive, node) {
|
|
227
|
+
var _a;
|
|
228
|
+
const name = directive.name;
|
|
229
|
+
let tuple = directives.find((d) => d[DirectiveKeys.name] === name);
|
|
230
|
+
if (!tuple) {
|
|
231
|
+
tuple = [directive.name];
|
|
232
|
+
directives.push(tuple);
|
|
233
|
+
}
|
|
234
|
+
const previouslyAddedArgs = tuple[DirectiveKeys.arguments];
|
|
235
|
+
const nodeArgs = new Set((_a = node.arguments) == null ? void 0 : _a.map((arg) => arg.name.value));
|
|
236
|
+
const argsFilter = (argDef) => Boolean(
|
|
237
|
+
(previouslyAddedArgs == null ? void 0 : previouslyAddedArgs[argDef.name]) || isNonNullType(argDef.type) || argDef.defaultValue !== void 0 || nodeArgs.has(argDef.name)
|
|
238
|
+
);
|
|
239
|
+
const [hasArgs, argsRecord] = encodeArguments(directive.args, argsFilter);
|
|
240
|
+
if (hasArgs) {
|
|
241
|
+
tuple[DirectiveKeys.arguments] = argsRecord;
|
|
242
|
+
}
|
|
243
|
+
return tuple;
|
|
244
|
+
}
|
|
245
|
+
function encodeCompositeType(type) {
|
|
246
|
+
if (isUnionType(type)) {
|
|
247
|
+
return [TypeKind.UNION, type.getTypes().map((type2) => type2.name)];
|
|
248
|
+
}
|
|
249
|
+
const ifaces = type.getInterfaces().map((iface) => iface.name);
|
|
250
|
+
const typeKind = isObjectType(type) ? TypeKind.OBJECT : TypeKind.INTERFACE;
|
|
251
|
+
return ifaces.length ? [typeKind, {}, ifaces] : [typeKind, {}];
|
|
252
|
+
}
|
|
253
|
+
function encodeInputObjectType(type) {
|
|
254
|
+
const result = /* @__PURE__ */ Object.create(null);
|
|
255
|
+
for (const [fieldName, field] of Object.entries(type.getFields())) {
|
|
256
|
+
result[fieldName] = encodeInputField(field);
|
|
257
|
+
}
|
|
258
|
+
return [TypeKind.INPUT, result];
|
|
259
|
+
}
|
|
260
|
+
function encodeInputField(field) {
|
|
261
|
+
const typeReference = typeReferenceFromName(field.type.toString());
|
|
262
|
+
return field.defaultValue === void 0 ? typeReference : [typeReference, field.defaultValue];
|
|
263
|
+
}
|
|
264
|
+
function encodeFieldDef(field, argumentsFilter) {
|
|
265
|
+
const typeReference = typeReferenceFromName(field.type.toString());
|
|
266
|
+
const [hasArgs, argsRecord] = encodeArguments(field.args, argumentsFilter);
|
|
267
|
+
return !hasArgs ? typeReference : [typeReference, argsRecord];
|
|
268
|
+
}
|
|
269
|
+
function encodeArguments(args, argumentsFilter) {
|
|
270
|
+
let hasArgs = false;
|
|
271
|
+
const argsRecord = {};
|
|
272
|
+
for (const argDef of args) {
|
|
273
|
+
if (argumentsFilter && !argumentsFilter(argDef)) {
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
const typeReference = typeReferenceFromName(argDef.type.toString());
|
|
277
|
+
argsRecord[argDef.name] = argDef.defaultValue === void 0 ? typeReference : [typeReference, argDef.defaultValue];
|
|
278
|
+
hasArgs = true;
|
|
279
|
+
}
|
|
280
|
+
return [hasArgs, argsRecord];
|
|
281
|
+
}
|
|
282
|
+
function encodeEnumType(type) {
|
|
283
|
+
return [TypeKind.ENUM, type.getValues().map((v) => v.name)];
|
|
284
|
+
}
|
|
285
|
+
function encodeScalarType(_type) {
|
|
286
|
+
return [TypeKind.SCALAR];
|
|
287
|
+
}
|
|
288
|
+
function assertCompositeType(type, node, ancestors) {
|
|
289
|
+
if (!type || !isCompositeType(type)) {
|
|
290
|
+
const path = node.kind === Kind.FIELD ? makeReadableErrorPath(ancestors).join(".") + "." + node.name.value : makeReadableErrorPath(ancestors).join(".");
|
|
291
|
+
throw new GraphQLError(`Cannot find type for: ${path}`, {
|
|
292
|
+
nodes: node
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
function assertExistingField(field, node, ancestors) {
|
|
297
|
+
if (!field) {
|
|
298
|
+
const path = makeReadableErrorPath(ancestors).join(".") + "." + node.name.value;
|
|
299
|
+
throw new GraphQLError(`Cannot find field: ${path}`, { nodes: node });
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
function assertAllArgumentsAreDefined(field, node, ancestors) {
|
|
303
|
+
var _a;
|
|
304
|
+
const defArgs = new Set(field.args.map((arg) => arg.name));
|
|
305
|
+
for (const arg of (_a = node.arguments) != null ? _a : []) {
|
|
306
|
+
if (!defArgs.has(arg.name.value)) {
|
|
307
|
+
const path = makeReadableErrorPath(ancestors).join(".") + "." + node.name.value + `(${arg.name.value}: ...)`;
|
|
308
|
+
throw new GraphQLError(`Cannot find type for argument: ${path}`, {
|
|
309
|
+
nodes: arg
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
export {
|
|
315
|
+
addMinimalViableSchemaToRequestDocument,
|
|
316
|
+
extractMinimalViableSchemaForRequestDocument
|
|
317
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utilities/addMinimalViableSchemaToRequestDocument.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n ArgumentNode,\n ASTNode,\n DirectiveNode,\n DocumentNode,\n ExecutableDefinitionNode,\n FieldNode,\n GraphQLArgument,\n GraphQLCompositeType,\n GraphQLDirective,\n GraphQLEnumType,\n GraphQLError,\n GraphQLField,\n GraphQLInputObjectType,\n GraphQLInputField,\n GraphQLOutputType,\n GraphQLScalarType,\n GraphQLSchema,\n isCompositeType,\n isEnumType,\n isInputObjectType,\n isNonNullType,\n isObjectType,\n isScalarType,\n isSpecifiedScalarType,\n isUnionType,\n Kind,\n NameNode,\n TypeInfo,\n visit,\n visitWithTypeInfo,\n} from \"graphql\";\nimport {\n CompositeTypeTuple,\n DirectiveDefinitionTuple,\n DirectiveKeys,\n SchemaFragmentDefinitions,\n EnumTypeDefinitionTuple,\n FieldDefinition,\n FieldKeys,\n InputObjectKeys,\n InputObjectTypeDefinitionTuple,\n InputValueDefinition,\n InputValueDefinitionRecord,\n InputValueKeys,\n InterfaceKeys,\n InterfaceTypeDefinitionTuple,\n ObjectKeys,\n ObjectTypeDefinitionTuple,\n ScalarTypeDefinitionTuple,\n TypeDefinitionsRecord,\n TypeKind,\n TypeReference,\n} from \"../schema/definition\";\nimport {\n inspectTypeReference,\n typeNameFromReference,\n typeReferenceFromName,\n} from \"../schema/reference\";\nimport { invariant } from \"../jsutils/invariant\";\nimport { Maybe } from \"../jsutils/Maybe\";\nimport {\n isSpecifiedDirective,\n SUPERMASSIVE_SCHEMA_DIRECTIVE_FRAGMENT_ARGUMENT_NAME,\n SUPERMASSIVE_SCHEMA_DIRECTIVE_NAME,\n} from \"../schema/directives\";\nimport { makeReadableErrorPath } from \"./makeReadableErrorPath\";\n\nexport type AddMinimalViableSchemaToRequestDocumentOptions = {\n ignoredDirectives?: string[];\n includeImplementations?: boolean; // TODO\n};\n\nexport function addMinimalViableSchemaToRequestDocument(\n schema: GraphQLSchema,\n document: DocumentNode,\n options?: AddMinimalViableSchemaToRequestDocumentOptions,\n): DocumentNode {\n return {\n ...document,\n definitions: document.definitions.map((node) =>\n node.kind === Kind.OPERATION_DEFINITION ||\n node.kind === Kind.FRAGMENT_DEFINITION\n ? addMinimalViableSchemaToExecutableDefinitionNode(\n schema,\n node,\n options,\n )\n : node,\n ),\n };\n}\n\n/**\n * Adds directive with minimal viable schema to every individual executable node (operation, fragment)\n */\nfunction addMinimalViableSchemaToExecutableDefinitionNode<\n T extends ExecutableDefinitionNode,\n>(\n schema: GraphQLSchema,\n node: T,\n options?: AddMinimalViableSchemaToRequestDocumentOptions,\n): T {\n if (node.directives?.some((directive) => directive.name.value === \"schema\")) {\n return node;\n }\n const schemaFragment = extractMinimalViableSchemaForRequestDocument(\n schema,\n { kind: Kind.DOCUMENT, definitions: [node] },\n options,\n );\n const directive: DirectiveNode = {\n kind: Kind.DIRECTIVE,\n name: nameNode(SUPERMASSIVE_SCHEMA_DIRECTIVE_NAME),\n arguments: [\n argNode(\n SUPERMASSIVE_SCHEMA_DIRECTIVE_FRAGMENT_ARGUMENT_NAME,\n schemaFragment,\n ),\n ],\n };\n return {\n ...node,\n directives: [...(node.directives ?? []), directive],\n };\n}\n\nfunction nameNode(name: string): NameNode {\n return { kind: Kind.NAME, value: name };\n}\n\nfunction argNode(name: string, value: unknown): ArgumentNode {\n return {\n kind: Kind.ARGUMENT,\n name: nameNode(name),\n value: { kind: Kind.STRING, value: JSON.stringify(value) },\n };\n}\n\nexport function extractMinimalViableSchemaForRequestDocument(\n schema: GraphQLSchema,\n document: DocumentNode,\n options?: AddMinimalViableSchemaToRequestDocumentOptions,\n): SchemaFragmentDefinitions {\n const types: TypeDefinitionsRecord = Object.create(null);\n const directives: DirectiveDefinitionTuple[] = [];\n\n const typeInfo = new TypeInfo(schema);\n visit(\n document,\n visitWithTypeInfo(typeInfo, {\n Field(node, _key, _parent, _path, ancestors): void {\n const parentType = typeInfo.getParentType();\n assertCompositeType(parentType, node, ancestors);\n\n const typeDef = addCompositeType(types, parentType);\n if (typeDef[0] === TypeKind.UNION || node.name.value === \"__typename\") {\n return;\n }\n const field = typeInfo.getFieldDef();\n assertExistingField(field, node, ancestors);\n assertAllArgumentsAreDefined(field, node, ancestors);\n\n const fieldDef = addField(typeDef, field, node);\n if (Array.isArray(fieldDef)) {\n addReferencedOutputType(schema, types, fieldDef[FieldKeys.type]);\n addReferencedInputTypes(schema, types, fieldDef[FieldKeys.arguments]);\n } else {\n addReferencedOutputType(schema, types, fieldDef);\n }\n },\n Directive(node, _key, _parent, _path, ancestors) {\n if (\n isSpecifiedDirective(node.name.value) ||\n options?.ignoredDirectives?.includes(node.name.value)\n ) {\n return;\n }\n const directive = typeInfo.getDirective();\n if (!directive) {\n const errorPath = makeReadableErrorPath(ancestors);\n\n // This happens whenever a directive is requested that hasn't been defined in schema\n throw new GraphQLError(\n `Cannot find definition for directive: ${errorPath.join(\".\")} @${\n node.name.value\n }`,\n { nodes: node },\n );\n }\n addDirective(directives, directive, node);\n },\n FragmentDefinition(node, _key, _parent, _path, ancestors): void {\n const type = typeInfo.getType();\n assertCompositeType(type, node, ancestors);\n addCompositeType(types, type);\n },\n InlineFragment(node, _key, _parent, _path, ancestors): void {\n if (node?.typeCondition) {\n const type = typeInfo.getType();\n assertCompositeType(type, node, ancestors);\n addCompositeType(types, type);\n }\n },\n Argument() {\n // Perf: no need to visit arguments - they were handled by Field/Directive visitors\n return false;\n },\n }),\n );\n return directives.length ? { types, directives } : { types };\n}\n\nfunction addReferencedOutputType(\n schema: GraphQLSchema,\n types: TypeDefinitionsRecord,\n typeRef: TypeReference,\n) {\n const name = typeNameFromReference(typeRef);\n const schemaType = schema.getType(name);\n\n if (!schemaType) {\n throw new Error(`Type ${name} not found in schema`);\n }\n if (types[name] || isSpecifiedScalarType(schemaType)) {\n // Assuming already added\n return;\n }\n if (isCompositeType(schemaType)) {\n addCompositeType(types, schemaType);\n } else if (isEnumType(schemaType)) {\n types[name] = encodeEnumType(schemaType);\n } else if (isScalarType(schemaType)) {\n types[name] = encodeScalarType(schemaType);\n } else {\n invariant(false, \"Got non-output type: \" + inspectTypeReference(typeRef));\n }\n}\n\nfunction addReferencedInputTypes(\n schema: GraphQLSchema,\n types: TypeDefinitionsRecord,\n inputValues: InputValueDefinitionRecord,\n): void {\n for (const inputValueDef of Object.values(inputValues)) {\n const typeRef = Array.isArray(inputValueDef)\n ? inputValueDef[InputValueKeys.type]\n : inputValueDef;\n\n const name = typeNameFromReference(typeRef);\n const schemaType = schema.getType(name);\n\n if (!schemaType) {\n throw new Error(`Type ${name} not found in schema`);\n }\n if (types[name] || isSpecifiedScalarType(schemaType)) {\n // Assuming already fully added\n continue;\n }\n if (isInputObjectType(schemaType)) {\n const inputObjectDef = encodeInputObjectType(schemaType);\n types[name] = inputObjectDef;\n addReferencedInputTypes(\n schema,\n types,\n inputObjectDef[InputObjectKeys.fields],\n );\n } else if (isEnumType(schemaType)) {\n types[name] = encodeEnumType(schemaType);\n } else if (isScalarType(schemaType)) {\n types[name] = encodeScalarType(schemaType);\n } else {\n invariant(false, \"Got non-input type: \" + inspectTypeReference(typeRef));\n }\n }\n}\n\nfunction addCompositeType(\n types: TypeDefinitionsRecord,\n type: GraphQLCompositeType,\n): CompositeTypeTuple {\n if (types[type.name]) {\n // TODO: double check that the kind match?\n return types[type.name] as CompositeTypeTuple;\n }\n return (types[type.name] = encodeCompositeType(type));\n}\n\nfunction addField(\n type: ObjectTypeDefinitionTuple | InterfaceTypeDefinitionTuple,\n field: GraphQLField<unknown, unknown>,\n fieldNode: FieldNode,\n): FieldDefinition {\n const fields =\n type[0] === TypeKind.OBJECT\n ? type[ObjectKeys.fields]\n : type[InterfaceKeys.fields];\n\n const existingFieldDef: FieldDefinition = fields[field.name];\n const previouslyAddedArgs = Array.isArray(existingFieldDef)\n ? existingFieldDef[FieldKeys.arguments]\n : Object.create(null);\n\n const nodeArgs = new Set(fieldNode.arguments?.map((arg) => arg.name.value));\n\n const argsFilter = (argDef: GraphQLArgument) =>\n Boolean(\n previouslyAddedArgs[argDef.name] ||\n isNonNullType(argDef.type) ||\n argDef.defaultValue !== undefined ||\n nodeArgs.has(argDef.name),\n );\n\n return (fields[field.name] = encodeFieldDef(field, argsFilter));\n}\n\nfunction addDirective(\n directives: DirectiveDefinitionTuple[],\n directive: GraphQLDirective,\n node: DirectiveNode,\n) {\n const name = directive.name;\n let tuple = directives.find((d) => d[DirectiveKeys.name] === name);\n if (!tuple) {\n tuple = [directive.name];\n directives.push(tuple);\n }\n\n const previouslyAddedArgs = tuple[DirectiveKeys.arguments];\n const nodeArgs = new Set(node.arguments?.map((arg) => arg.name.value));\n\n const argsFilter = (argDef: GraphQLArgument) =>\n Boolean(\n previouslyAddedArgs?.[argDef.name] ||\n isNonNullType(argDef.type) ||\n argDef.defaultValue !== undefined ||\n nodeArgs.has(argDef.name),\n );\n const [hasArgs, argsRecord] = encodeArguments(directive.args, argsFilter);\n if (hasArgs) {\n tuple[DirectiveKeys.arguments] = argsRecord;\n }\n return tuple;\n}\n\nfunction encodeCompositeType(type: GraphQLCompositeType): CompositeTypeTuple {\n if (isUnionType(type)) {\n return [TypeKind.UNION, type.getTypes().map((type) => type.name)];\n }\n const ifaces = type.getInterfaces().map((iface) => iface.name);\n const typeKind = isObjectType(type) ? TypeKind.OBJECT : TypeKind.INTERFACE;\n return ifaces.length ? [typeKind, {}, ifaces] : [typeKind, {}];\n}\n\nfunction encodeInputObjectType(\n type: GraphQLInputObjectType,\n): InputObjectTypeDefinitionTuple {\n const result = Object.create(null);\n for (const [fieldName, field] of Object.entries(type.getFields())) {\n result[fieldName] = encodeInputField(field);\n }\n return [TypeKind.INPUT, result];\n}\n\nfunction encodeInputField(field: GraphQLInputField): InputValueDefinition {\n const typeReference = typeReferenceFromName(field.type.toString());\n return field.defaultValue === undefined\n ? typeReference\n : [typeReference, field.defaultValue];\n}\n\nfunction encodeFieldDef(\n field: GraphQLField<unknown, unknown>,\n argumentsFilter?: (arg: GraphQLArgument) => boolean,\n): FieldDefinition {\n const typeReference = typeReferenceFromName(field.type.toString());\n const [hasArgs, argsRecord] = encodeArguments(field.args, argumentsFilter);\n return !hasArgs ? typeReference : [typeReference, argsRecord];\n}\n\nfunction encodeArguments(\n args: ReadonlyArray<GraphQLArgument>,\n argumentsFilter?: (arg: GraphQLArgument) => boolean,\n): [boolean, InputValueDefinitionRecord] {\n let hasArgs = false;\n const argsRecord: InputValueDefinitionRecord = {};\n for (const argDef of args) {\n if (argumentsFilter && !argumentsFilter(argDef)) {\n continue;\n }\n const typeReference = typeReferenceFromName(argDef.type.toString());\n argsRecord[argDef.name] =\n argDef.defaultValue === undefined\n ? typeReference\n : [typeReference, argDef.defaultValue];\n hasArgs = true;\n }\n return [hasArgs, argsRecord];\n}\n\nfunction encodeEnumType(type: GraphQLEnumType): EnumTypeDefinitionTuple {\n return [TypeKind.ENUM, type.getValues().map((v) => v.name)];\n}\n\nfunction encodeScalarType(_type: GraphQLScalarType): ScalarTypeDefinitionTuple {\n return [TypeKind.SCALAR];\n}\n\nfunction assertCompositeType(\n type: Maybe<GraphQLOutputType>,\n node: ASTNode,\n ancestors: ReadonlyArray<readonly ASTNode[] | ASTNode>,\n): asserts type is GraphQLCompositeType {\n if (!type || !isCompositeType(type)) {\n const path =\n node.kind === Kind.FIELD\n ? makeReadableErrorPath(ancestors).join(\".\") + \".\" + node.name.value\n : makeReadableErrorPath(ancestors).join(\".\");\n throw new GraphQLError(`Cannot find type for: ${path}`, {\n nodes: node,\n });\n }\n}\n\nfunction assertExistingField(\n field: Maybe<GraphQLField<unknown, unknown>>,\n node: FieldNode,\n ancestors: ReadonlyArray<readonly ASTNode[] | ASTNode>,\n): asserts field is GraphQLField<unknown, unknown> {\n if (!field) {\n const path =\n makeReadableErrorPath(ancestors).join(\".\") + \".\" + node.name.value;\n throw new GraphQLError(`Cannot find field: ${path}`, { nodes: node });\n }\n}\n\nfunction assertAllArgumentsAreDefined(\n field: GraphQLField<unknown, unknown> | GraphQLDirective,\n node: FieldNode | DirectiveNode,\n ancestors: ReadonlyArray<readonly ASTNode[] | ASTNode>,\n) {\n const defArgs = new Set(field.args.map((arg) => arg.name));\n for (const arg of node.arguments ?? []) {\n if (!defArgs.has(arg.name.value)) {\n const path =\n makeReadableErrorPath(ancestors).join(\".\") +\n \".\" +\n node.name.value +\n `(${arg.name.value}: ...)`;\n throw new GraphQLError(`Cannot find type for argument: ${path}`, {\n nodes: arg,\n });\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA,EAWE;AAAA,EAOA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EAGE;AAAA,EAIA;AAAA,EACA;AAAA,EAIA;AAAA,EACA;AAAA,EAEA;AAAA,EAIA;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,iBAAiB;AAE1B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,6BAA6B;AAO/B,SAAS,wCACd,QACA,UACA,SACc;AACd,SAAO,iCACF,WADE;AAAA,IAEL,aAAa,SAAS,YAAY;AAAA,MAAI,CAAC,SACrC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W,QAAO,UAAK,cAAL,YAAkB,CAAC,GAAG;AACtC,QAAI,CAAC,QAAQ,IAAI,IAAI,KAAK,KAAK,GAAG;AAChC,YAAM,OACJ,sBAAsB,SAAS,EAAE,KAAK,GAAG,IACzC,MACA,KAAK,KAAK,QACV,IAAI,IAAI,KAAK;AACf,YAAM,IAAI,aAAa,kCAAkC,QAAQ;AAAA,QAC/D,OAAO;AAAA,MACT,CAAC;AAAA,IACH;AAAA,EACF;AACF;",
|
|
6
|
+
"names": ["directive", "type"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { FragmentDefinitionNode, GraphQLSchema, OperationDefinitionNode } from "graphql";
|
|
2
|
+
export declare const annotateDocumentGraphQLTransform: (schema: GraphQLSchema) => (node: FragmentDefinitionNode | OperationDefinitionNode) => import("graphql").DefinitionNode;
|
|
3
|
+
//# sourceMappingURL=annotateDocumentGraphQLTransform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"annotateDocumentGraphQLTransform.d.ts","sourceRoot":"","sources":["../../src/utilities/annotateDocumentGraphQLTransform.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,aAAa,EAEb,uBAAuB,EACxB,MAAM,SAAS,CAAC;AAGjB,eAAO,MAAM,gCAAgC,WAAY,aAAa,YACtD,sBAAsB,GAAG,uBAAuB,qCAO/D,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var annotateDocumentGraphQLTransform_exports = {};
|
|
20
|
+
__export(annotateDocumentGraphQLTransform_exports, {
|
|
21
|
+
annotateDocumentGraphQLTransform: () => annotateDocumentGraphQLTransform
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(annotateDocumentGraphQLTransform_exports);
|
|
24
|
+
var import_graphql = require("graphql");
|
|
25
|
+
var import_addMinimalViableSchemaToRequestDocument = require("./addMinimalViableSchemaToRequestDocument");
|
|
26
|
+
const annotateDocumentGraphQLTransform = (schema) => {
|
|
27
|
+
return (node) => {
|
|
28
|
+
const document = (0, import_addMinimalViableSchemaToRequestDocument.addMinimalViableSchemaToRequestDocument)(schema, {
|
|
29
|
+
kind: import_graphql.Kind.DOCUMENT,
|
|
30
|
+
definitions: [node]
|
|
31
|
+
});
|
|
32
|
+
return document == null ? void 0 : document.definitions[0];
|
|
33
|
+
};
|
|
34
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utilities/annotateDocumentGraphQLTransform.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n FragmentDefinitionNode,\n GraphQLSchema,\n Kind,\n OperationDefinitionNode,\n} from \"graphql\";\nimport { addMinimalViableSchemaToRequestDocument } from \"./addMinimalViableSchemaToRequestDocument\";\n\nexport const annotateDocumentGraphQLTransform = (schema: GraphQLSchema) => {\n return (node: FragmentDefinitionNode | OperationDefinitionNode) => {\n const document = addMinimalViableSchemaToRequestDocument(schema, {\n kind: Kind.DOCUMENT,\n definitions: [node],\n });\n return document?.definitions[0]; // FIXME\n };\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAKO;AACP,qDAAwD;AAEjD,MAAM,mCAAmC,CAAC,WAA0B;AACzE,SAAO,CAAC,SAA2D;AACjE,UAAM,eAAW,wFAAwC,QAAQ;AAAA,MAC/D,MAAM,oBAAK;AAAA,MACX,aAAa,CAAC,IAAI;AAAA,IACpB,CAAC;AACD,WAAO,qCAAU,YAAY;AAAA,EAC/B;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// src/utilities/annotateDocumentGraphQLTransform.ts
|
|
2
|
+
import {
|
|
3
|
+
Kind
|
|
4
|
+
} from "graphql";
|
|
5
|
+
import { addMinimalViableSchemaToRequestDocument } from "./addMinimalViableSchemaToRequestDocument.mjs";
|
|
6
|
+
var annotateDocumentGraphQLTransform = (schema) => {
|
|
7
|
+
return (node) => {
|
|
8
|
+
const document = addMinimalViableSchemaToRequestDocument(schema, {
|
|
9
|
+
kind: Kind.DOCUMENT,
|
|
10
|
+
definitions: [node]
|
|
11
|
+
});
|
|
12
|
+
return document == null ? void 0 : document.definitions[0];
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
annotateDocumentGraphQLTransform
|
|
17
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utilities/annotateDocumentGraphQLTransform.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n FragmentDefinitionNode,\n GraphQLSchema,\n Kind,\n OperationDefinitionNode,\n} from \"graphql\";\nimport { addMinimalViableSchemaToRequestDocument } from \"./addMinimalViableSchemaToRequestDocument\";\n\nexport const annotateDocumentGraphQLTransform = (schema: GraphQLSchema) => {\n return (node: FragmentDefinitionNode | OperationDefinitionNode) => {\n const document = addMinimalViableSchemaToRequestDocument(schema, {\n kind: Kind.DOCUMENT,\n definitions: [node],\n });\n return document?.definitions[0]; // FIXME\n };\n};\n"],
|
|
5
|
+
"mappings": ";AAAA;AAAA,EAGE;AAAA,OAEK;AACP,SAAS,+CAA+C;AAEjD,IAAM,mCAAmC,CAAC,WAA0B;AACzE,SAAO,CAAC,SAA2D;AACjE,UAAM,WAAW,wCAAwC,QAAQ;AAAA,MAC/D,MAAM,KAAK;AAAA,MACX,aAAa,CAAC,IAAI;AAAA,IACpB,CAAC;AACD,WAAO,qCAAU,YAAY;AAAA,EAC/B;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { GraphQLError } from "graphql";
|
|
2
|
+
import { TypeReference } from "../schema/definition";
|
|
3
|
+
import { SchemaFragment } from "../schema/fragment";
|
|
4
|
+
type OnErrorCB = (path: ReadonlyArray<string | number>, invalidValue: unknown, error: GraphQLError) => void;
|
|
5
|
+
/**
|
|
6
|
+
* Coerces a JavaScript value given a GraphQL Input Type.
|
|
7
|
+
*/
|
|
8
|
+
export declare function coerceInputValue(inputValue: unknown, typeRef: TypeReference, schemaTypes: SchemaFragment, onError?: OnErrorCB): unknown;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=coerceInputValue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coerceInputValue.d.ts","sourceRoot":"","sources":["../../src/utilities/coerceInputValue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAUvC,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAQpD,KAAK,SAAS,GAAG,CACf,IAAI,EAAE,aAAa,CAAC,MAAM,GAAG,MAAM,CAAC,EACpC,YAAY,EAAE,OAAO,EACrB,KAAK,EAAE,YAAY,KAChB,IAAI,CAAC;AAEV;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,OAAO,EACnB,OAAO,EAAE,aAAa,EACtB,WAAW,EAAE,cAAc,EAC3B,OAAO,GAAE,SAA0B,GAClC,OAAO,CAQT"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var coerceInputValue_exports = {};
|
|
20
|
+
__export(coerceInputValue_exports, {
|
|
21
|
+
coerceInputValue: () => coerceInputValue
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(coerceInputValue_exports);
|
|
24
|
+
var import_graphql = require("graphql");
|
|
25
|
+
var import_didYouMean = require("../jsutils/didYouMean");
|
|
26
|
+
var import_inspect = require("../jsutils/inspect");
|
|
27
|
+
var import_invariant = require("../jsutils/invariant");
|
|
28
|
+
var import_isIterableObject = require("../jsutils/isIterableObject");
|
|
29
|
+
var import_isObjectLike = require("../jsutils/isObjectLike");
|
|
30
|
+
var import_Path = require("../jsutils/Path");
|
|
31
|
+
var import_printPathArray = require("../jsutils/printPathArray");
|
|
32
|
+
var import_suggestionList = require("../jsutils/suggestionList");
|
|
33
|
+
var import_reference = require("../schema/reference");
|
|
34
|
+
function coerceInputValue(inputValue, typeRef, schemaTypes, onError = defaultOnError) {
|
|
35
|
+
return coerceInputValueImpl(
|
|
36
|
+
inputValue,
|
|
37
|
+
typeRef,
|
|
38
|
+
schemaTypes,
|
|
39
|
+
onError,
|
|
40
|
+
void 0
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
function defaultOnError(path, invalidValue, error) {
|
|
44
|
+
let errorPrefix = "Invalid value " + (0, import_inspect.inspect)(invalidValue);
|
|
45
|
+
if (path.length > 0) {
|
|
46
|
+
errorPrefix += ` at "value${(0, import_printPathArray.printPathArray)(path)}"`;
|
|
47
|
+
}
|
|
48
|
+
error.message = errorPrefix + ": " + error.message;
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
function coerceInputValueImpl(inputValue, typeRef, schemaTypes, onError, path) {
|
|
52
|
+
if ((0, import_reference.isNonNullType)(typeRef)) {
|
|
53
|
+
if (inputValue != null) {
|
|
54
|
+
return coerceInputValueImpl(
|
|
55
|
+
inputValue,
|
|
56
|
+
(0, import_reference.unwrap)(typeRef),
|
|
57
|
+
schemaTypes,
|
|
58
|
+
onError,
|
|
59
|
+
path
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
onError(
|
|
63
|
+
(0, import_Path.pathToArray)(path),
|
|
64
|
+
inputValue,
|
|
65
|
+
new import_graphql.GraphQLError(
|
|
66
|
+
`Expected non-nullable type "${(0, import_reference.inspectTypeReference)(
|
|
67
|
+
typeRef
|
|
68
|
+
)}" not to be null.`
|
|
69
|
+
)
|
|
70
|
+
);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (inputValue == null) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
if ((0, import_reference.isListType)(typeRef)) {
|
|
77
|
+
const itemType = (0, import_reference.unwrap)(typeRef);
|
|
78
|
+
if ((0, import_isIterableObject.isIterableObject)(inputValue)) {
|
|
79
|
+
return Array.from(inputValue, (itemValue, index) => {
|
|
80
|
+
const itemPath = (0, import_Path.addPath)(path, index, void 0);
|
|
81
|
+
return coerceInputValueImpl(
|
|
82
|
+
itemValue,
|
|
83
|
+
itemType,
|
|
84
|
+
schemaTypes,
|
|
85
|
+
onError,
|
|
86
|
+
itemPath
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
return [
|
|
91
|
+
coerceInputValueImpl(inputValue, itemType, schemaTypes, onError, path)
|
|
92
|
+
];
|
|
93
|
+
}
|
|
94
|
+
const inputObjectType = schemaTypes.getInputObjectType(typeRef);
|
|
95
|
+
if (inputObjectType) {
|
|
96
|
+
const typeName = (0, import_reference.inspectTypeReference)(typeRef);
|
|
97
|
+
if (!(0, import_isObjectLike.isObjectLike)(inputValue)) {
|
|
98
|
+
onError(
|
|
99
|
+
(0, import_Path.pathToArray)(path),
|
|
100
|
+
inputValue,
|
|
101
|
+
new import_graphql.GraphQLError(`Expected type "${typeRef}" to be an object.`)
|
|
102
|
+
);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const coercedValue = {};
|
|
106
|
+
const fieldDefs = schemaTypes.getInputObjectFields(inputObjectType);
|
|
107
|
+
for (const [fieldName, field] of Object.entries(fieldDefs)) {
|
|
108
|
+
const fieldValue = inputValue[fieldName];
|
|
109
|
+
const defaultValue = schemaTypes.getInputDefaultValue(field);
|
|
110
|
+
const fieldTypeRef = schemaTypes.getTypeReference(field);
|
|
111
|
+
if (fieldValue === void 0) {
|
|
112
|
+
if (defaultValue !== void 0) {
|
|
113
|
+
coercedValue[fieldName] = defaultValue;
|
|
114
|
+
} else if ((0, import_reference.isNonNullType)(fieldTypeRef)) {
|
|
115
|
+
const typeStr = (0, import_reference.inspectTypeReference)(fieldTypeRef);
|
|
116
|
+
onError(
|
|
117
|
+
(0, import_Path.pathToArray)(path),
|
|
118
|
+
inputValue,
|
|
119
|
+
new import_graphql.GraphQLError(
|
|
120
|
+
`Field "${fieldName}" of required type "${typeStr}" was not provided.`
|
|
121
|
+
)
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
coercedValue[fieldName] = coerceInputValueImpl(
|
|
127
|
+
fieldValue,
|
|
128
|
+
fieldTypeRef,
|
|
129
|
+
schemaTypes,
|
|
130
|
+
onError,
|
|
131
|
+
(0, import_Path.addPath)(path, fieldName, typeName)
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
for (const fieldName of Object.keys(inputValue)) {
|
|
135
|
+
if (fieldDefs[fieldName] == null) {
|
|
136
|
+
const suggestions = (0, import_suggestionList.suggestionList)(fieldName, Object.keys(fieldDefs));
|
|
137
|
+
onError(
|
|
138
|
+
(0, import_Path.pathToArray)(path),
|
|
139
|
+
inputValue,
|
|
140
|
+
new import_graphql.GraphQLError(
|
|
141
|
+
`Field "${fieldName}" is not defined by type "${typeName}".` + (0, import_didYouMean.didYouMean)(suggestions)
|
|
142
|
+
)
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return coercedValue;
|
|
147
|
+
}
|
|
148
|
+
const leafType = schemaTypes.getLeafTypeResolver(typeRef);
|
|
149
|
+
if (leafType) {
|
|
150
|
+
let parseResult;
|
|
151
|
+
try {
|
|
152
|
+
parseResult = leafType.parseValue(inputValue);
|
|
153
|
+
} catch (error) {
|
|
154
|
+
if (error instanceof import_graphql.GraphQLError) {
|
|
155
|
+
onError((0, import_Path.pathToArray)(path), inputValue, error);
|
|
156
|
+
} else {
|
|
157
|
+
const typeName = (0, import_reference.inspectTypeReference)(typeRef);
|
|
158
|
+
onError(
|
|
159
|
+
(0, import_Path.pathToArray)(path),
|
|
160
|
+
inputValue,
|
|
161
|
+
new import_graphql.GraphQLError(
|
|
162
|
+
`Expected type "${typeName}". ` + error.message,
|
|
163
|
+
{
|
|
164
|
+
originalError: error
|
|
165
|
+
}
|
|
166
|
+
)
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (parseResult === void 0) {
|
|
172
|
+
onError(
|
|
173
|
+
(0, import_Path.pathToArray)(path),
|
|
174
|
+
inputValue,
|
|
175
|
+
new import_graphql.GraphQLError(`Expected type "${(0, import_reference.inspectTypeReference)(typeRef)}".`)
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
return parseResult;
|
|
179
|
+
}
|
|
180
|
+
(0, import_invariant.invariant)(false, "Unexpected input type: " + (0, import_reference.inspectTypeReference)(typeRef));
|
|
181
|
+
}
|