@graphitation/supermassive 0.2.0 → 0.3.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/CHANGELOG.md +10 -2
- package/README.md +179 -5
- package/bin/supermassive.js +3 -1
- package/lib/ast/addTypesToRequestDocument.mjs +3 -1
- package/lib/benchmarks/index.mjs +16 -14
- package/lib/benchmarks/nice-benchmark.mjs +6 -3
- package/lib/benchmarks/swapi-schema/index.mjs +3 -2
- package/lib/benchmarks/swapi-schema/models.mjs +1 -0
- package/lib/benchmarks/swapi-schema/resolvers.mjs +23 -24
- package/lib/bin/supermassive.d.ts.map +1 -1
- package/lib/bin/supermassive.js +0 -0
- package/lib/bin/supermassive.mjs +3 -1
- package/lib/collectFields.mjs +1 -0
- package/lib/executeWithSchema.d.ts.map +1 -1
- package/lib/executeWithSchema.js +8 -8
- package/lib/executeWithSchema.mjs +6 -4
- package/lib/executeWithoutSchema.mjs +15 -17
- package/lib/extractImplicitTypesRuntime.mjs +1 -0
- package/lib/extractImplicitTypesToTypescript.mjs +2 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +0 -2
- package/lib/index.mjs +7 -8
- package/lib/jsutils/Path.mjs +1 -0
- package/lib/jsutils/devAssert.mjs +1 -0
- package/lib/jsutils/didYouMean.mjs +2 -1
- package/lib/jsutils/identityFunc.mjs +1 -0
- package/lib/jsutils/inspect.mjs +3 -2
- package/lib/jsutils/instanceOf.mjs +3 -2
- package/lib/jsutils/invariant.mjs +1 -0
- package/lib/jsutils/isAsyncIterable.mjs +1 -0
- package/lib/jsutils/isIterableObject.mjs +1 -0
- package/lib/jsutils/isObjectLike.mjs +1 -0
- package/lib/jsutils/isPromise.mjs +1 -0
- package/lib/jsutils/keyMap.mjs +1 -0
- package/lib/jsutils/keyValMap.mjs +1 -0
- package/lib/jsutils/mapValue.mjs +1 -0
- package/lib/jsutils/memoize3.mjs +1 -0
- package/lib/jsutils/naturalCompare.mjs +3 -2
- package/lib/jsutils/printPathArray.mjs +1 -0
- package/lib/jsutils/promiseForObject.mjs +1 -0
- package/lib/jsutils/promiseReduce.mjs +2 -1
- package/lib/jsutils/suggestionList.mjs +4 -3
- package/lib/jsutils/toObjMap.mjs +1 -0
- package/lib/transforms/annotateDocumentGraphQLTransform.mjs +3 -2
- package/lib/transforms/transformerTestUtils.mjs +14 -8
- package/lib/utilities/typeNameFromAST.mjs +1 -0
- package/lib/values.mjs +5 -4
- package/package.json +13 -3
- package/starwars.json +1 -0
- package/.eslintcache +0 -1
- package/graphitation-supermassive-0.1.3-1.tgz +0 -0
- package/graphitation-supermassive-0.1.3-2.tgz +0 -0
- package/graphitation-supermassive-0.1.3.tgz +0 -0
- package/lib/bin/typeDefsToImplicitResolvers.d.ts +0 -3
- package/lib/bin/typeDefsToImplicitResolvers.d.ts.map +0 -1
- package/lib/bin/typeDefsToImplicitResolvers.js +0 -82
- package/lib/bin/typeDefsToImplicitResolvers.mjs +0 -59
- package/lib/execute.d.ts +0 -128
- package/lib/execute.d.ts.map +0 -1
- package/lib/execute.js +0 -376
- package/lib/execute.mjs +0 -365
- package/lib/extractImplicitTypes.d.ts +0 -6
- package/lib/extractImplicitTypes.d.ts.map +0 -1
- package/lib/extractImplicitTypes.js +0 -246
- package/lib/extractImplicitTypes.mjs +0 -233
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
import ts, {factory} from "typescript";
|
|
2
|
-
import {
|
|
3
|
-
getDirectiveValues,
|
|
4
|
-
GraphQLDeprecatedDirective,
|
|
5
|
-
GraphQLEnumType,
|
|
6
|
-
GraphQLScalarType,
|
|
7
|
-
Kind,
|
|
8
|
-
GraphQLInputObjectType,
|
|
9
|
-
valueFromAST,
|
|
10
|
-
GraphQLNonNull,
|
|
11
|
-
GraphQLList
|
|
12
|
-
} from "graphql";
|
|
13
|
-
const SPECIFIED_SCALARS = {
|
|
14
|
-
ID: "GraphQLID",
|
|
15
|
-
String: "GraphQLString",
|
|
16
|
-
Int: "GraphQLInt",
|
|
17
|
-
Float: "GraphQLFloat",
|
|
18
|
-
Boolean: "GraphQLBoolean"
|
|
19
|
-
};
|
|
20
|
-
function extractImplicitTypesToTypescript(document) {
|
|
21
|
-
const definitions = [];
|
|
22
|
-
const imports = [
|
|
23
|
-
"GraphQLList",
|
|
24
|
-
"GraphQLNonNull",
|
|
25
|
-
"GraphQLID",
|
|
26
|
-
"GraphQLString",
|
|
27
|
-
"GraphQLInt",
|
|
28
|
-
"GraphQLFloat",
|
|
29
|
-
"GraphQLBoolean"
|
|
30
|
-
];
|
|
31
|
-
const identifiers = [];
|
|
32
|
-
for (let astNode of document.definitions) {
|
|
33
|
-
if (astNode.kind === Kind.SCALAR_TYPE_DEFINITION) {
|
|
34
|
-
definitions.push(createScalarType(astNode));
|
|
35
|
-
addToSetArray(imports, "GraphQLScalarType");
|
|
36
|
-
addToSetArray(identifiers, astNode.name.value);
|
|
37
|
-
} else if (astNode.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION) {
|
|
38
|
-
definitions.push(createInputObjectType(astNode));
|
|
39
|
-
addToSetArray(imports, "GraphQLInputObjectType");
|
|
40
|
-
addToSetArray(identifiers, astNode.name.value);
|
|
41
|
-
} else if (astNode.kind === Kind.ENUM_TYPE_DEFINITION) {
|
|
42
|
-
definitions.push(createEnumType(astNode));
|
|
43
|
-
addToSetArray(imports, "GraphQLEnumType");
|
|
44
|
-
addToSetArray(identifiers, astNode.name.value);
|
|
45
|
-
} else if (astNode.kind === Kind.UNION_TYPE_DEFINITION || astNode.kind === Kind.INTERFACE_TYPE_DEFINITION) {
|
|
46
|
-
definitions.push(createAbstractType(astNode));
|
|
47
|
-
addToSetArray(identifiers, astNode.name.value);
|
|
48
|
-
} else if (astNode.kind === Kind.OBJECT_TYPE_DEFINITION) {
|
|
49
|
-
definitions.push(createObjectType(astNode));
|
|
50
|
-
addToSetArray(identifiers, astNode.name.value);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
const importDefinition = factory.createImportDeclaration(void 0, void 0, factory.createImportClause(false, void 0, factory.createNamedImports(imports.map((imp) => factory.createImportSpecifier(void 0, factory.createIdentifier(imp))))), factory.createStringLiteral("graphql"));
|
|
54
|
-
const exportDefinition = factory.createVariableStatement([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([
|
|
55
|
-
factory.createVariableDeclaration(factory.createIdentifier("resolvers"), void 0, void 0, factory.createObjectLiteralExpression(identifiers.map((def) => factory.createShorthandPropertyAssignment(factory.createIdentifier(def), void 0))))
|
|
56
|
-
], ts.NodeFlags.Const));
|
|
57
|
-
return factory.createSourceFile([importDefinition, ...definitions, exportDefinition], factory.createToken(ts.SyntaxKind.EndOfFileToken), 0);
|
|
58
|
-
}
|
|
59
|
-
function createDeclaration(name, decl) {
|
|
60
|
-
return factory.createVariableStatement(void 0, factory.createVariableDeclarationList([
|
|
61
|
-
factory.createVariableDeclaration(factory.createIdentifier(name), void 0, void 0, decl)
|
|
62
|
-
], ts.NodeFlags.Const));
|
|
63
|
-
}
|
|
64
|
-
function createScalarType(astNode) {
|
|
65
|
-
var _a;
|
|
66
|
-
return createDeclaration(astNode.name.value, factory.createNewExpression(factory.createIdentifier("GraphQLScalarType"), void 0, [
|
|
67
|
-
factory.createObjectLiteralExpression([
|
|
68
|
-
factory.createPropertyAssignment(factory.createIdentifier("name"), factory.createStringLiteral(astNode.name.value)),
|
|
69
|
-
factory.createPropertyAssignment(factory.createIdentifier("description"), factory.createStringLiteral(((_a = astNode.description) == null ? void 0 : _a.value) || ""))
|
|
70
|
-
], true)
|
|
71
|
-
]));
|
|
72
|
-
}
|
|
73
|
-
function createInputObjectType(astNode) {
|
|
74
|
-
var _a;
|
|
75
|
-
return createDeclaration(astNode.name.value, factory.createNewExpression(factory.createIdentifier("GraphQLInputObjectType"), void 0, [
|
|
76
|
-
factory.createObjectLiteralExpression([
|
|
77
|
-
factory.createPropertyAssignment(factory.createIdentifier("name"), factory.createStringLiteral(astNode.name.value)),
|
|
78
|
-
factory.createPropertyAssignment(factory.createIdentifier("description"), factory.createStringLiteral(((_a = astNode.description) == null ? void 0 : _a.value) || "")),
|
|
79
|
-
factory.createPropertyAssignment(factory.createIdentifier("fields"), factory.createArrowFunction(void 0, void 0, [], void 0, factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), factory.createParenthesizedExpression(factory.createObjectLiteralExpression(createInputFields(astNode.fields || []), true))))
|
|
80
|
-
], true)
|
|
81
|
-
]));
|
|
82
|
-
}
|
|
83
|
-
function createInputFields(astNodes) {
|
|
84
|
-
return astNodes.map((astNode) => {
|
|
85
|
-
var _a;
|
|
86
|
-
const fields = [
|
|
87
|
-
factory.createPropertyAssignment(factory.createIdentifier("type"), createType(astNode.type)),
|
|
88
|
-
factory.createPropertyAssignment(factory.createIdentifier("description"), factory.createStringLiteral(((_a = astNode.description) == null ? void 0 : _a.value) || ""))
|
|
89
|
-
];
|
|
90
|
-
if (astNode.defaultValue) {
|
|
91
|
-
fields.push(factory.createPropertyAssignment(factory.createIdentifier("defaultValue"), createValue(astNode.defaultValue)));
|
|
92
|
-
}
|
|
93
|
-
return factory.createPropertyAssignment(factory.createIdentifier(astNode.name.value), factory.createObjectLiteralExpression(fields, true));
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
function createEnumType(astNode) {
|
|
97
|
-
var _a;
|
|
98
|
-
return createDeclaration(astNode.name.value, factory.createNewExpression(factory.createIdentifier("GraphQLEnumType"), void 0, [
|
|
99
|
-
factory.createObjectLiteralExpression([
|
|
100
|
-
factory.createPropertyAssignment(factory.createIdentifier("name"), factory.createStringLiteral(astNode.name.value)),
|
|
101
|
-
factory.createPropertyAssignment(factory.createIdentifier("description"), factory.createStringLiteral(((_a = astNode.description) == null ? void 0 : _a.value) || "")),
|
|
102
|
-
factory.createPropertyAssignment(factory.createIdentifier("values"), factory.createObjectLiteralExpression((astNode.values || []).map((valueNode) => {
|
|
103
|
-
var _a2;
|
|
104
|
-
return factory.createPropertyAssignment(factory.createIdentifier(valueNode.name.value), factory.createObjectLiteralExpression([
|
|
105
|
-
factory.createPropertyAssignment(factory.createIdentifier("description"), factory.createStringLiteral(((_a2 = valueNode.description) == null ? void 0 : _a2.value) || ""))
|
|
106
|
-
]));
|
|
107
|
-
})))
|
|
108
|
-
])
|
|
109
|
-
]));
|
|
110
|
-
}
|
|
111
|
-
function createAbstractType(astNode) {
|
|
112
|
-
return createDeclaration(astNode.name.value, factory.createObjectLiteralExpression([
|
|
113
|
-
factory.createPropertyAssignment(factory.createIdentifier("__resolveType"), factory.createIdentifier("undefined"))
|
|
114
|
-
]));
|
|
115
|
-
}
|
|
116
|
-
function createObjectType(astNode) {
|
|
117
|
-
return createDeclaration(astNode.name.value, factory.createObjectLiteralExpression());
|
|
118
|
-
}
|
|
119
|
-
function createType(astNode) {
|
|
120
|
-
if (astNode.kind === Kind.LIST_TYPE) {
|
|
121
|
-
return factory.createNewExpression(factory.createIdentifier("GraphQLList"), void 0, [createType(astNode.type)]);
|
|
122
|
-
} else if (astNode.kind === Kind.NON_NULL_TYPE) {
|
|
123
|
-
return factory.createNewExpression(factory.createIdentifier("GraphQLNonNull"), void 0, [createType(astNode.type)]);
|
|
124
|
-
} else {
|
|
125
|
-
if (SPECIFIED_SCALARS[astNode.name.value]) {
|
|
126
|
-
return factory.createIdentifier(SPECIFIED_SCALARS[astNode.name.value]);
|
|
127
|
-
} else {
|
|
128
|
-
return factory.createIdentifier(astNode.name.value);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
function createValue(astNode) {
|
|
133
|
-
if (astNode.kind === Kind.INT || astNode.kind === Kind.FLOAT) {
|
|
134
|
-
return factory.createNumericLiteral(astNode.value);
|
|
135
|
-
} else if (astNode.kind === Kind.BOOLEAN) {
|
|
136
|
-
return astNode.value ? factory.createTrue() : factory.createFalse();
|
|
137
|
-
} else if (astNode.kind === Kind.STRING || astNode.kind === Kind.ENUM) {
|
|
138
|
-
return factory.createStringLiteral(astNode.value);
|
|
139
|
-
} else if (astNode.kind === Kind.NULL) {
|
|
140
|
-
return factory.createNull();
|
|
141
|
-
} else if (astNode.kind === Kind.LIST) {
|
|
142
|
-
return factory.createArrayLiteralExpression(astNode.values.map((valueNode) => createValue(valueNode)));
|
|
143
|
-
} else if (astNode.kind === Kind.OBJECT) {
|
|
144
|
-
return factory.createObjectLiteralExpression(astNode.fields.map((fieldNode) => factory.createPropertyAssignment(fieldNode.name.value, createValue(fieldNode.value))));
|
|
145
|
-
} else {
|
|
146
|
-
throw new Error("Invalid value");
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
function addToSetArray(array, item) {
|
|
150
|
-
if (array.indexOf(item) === -1) {
|
|
151
|
-
array.push(item);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
function extractImplicitTypes(document, getTypeByName) {
|
|
155
|
-
var _a;
|
|
156
|
-
const result = Object.create(null);
|
|
157
|
-
for (let astNode of document.definitions) {
|
|
158
|
-
if (astNode.kind === Kind.SCALAR_TYPE_DEFINITION) {
|
|
159
|
-
const name = astNode.name.value;
|
|
160
|
-
result[name] = new GraphQLScalarType({
|
|
161
|
-
name,
|
|
162
|
-
description: (_a = astNode.description) == null ? void 0 : _a.value
|
|
163
|
-
});
|
|
164
|
-
} else if (astNode.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION) {
|
|
165
|
-
result[astNode.name.value] = makeInputObject(astNode, getTypeByName);
|
|
166
|
-
} else if (astNode.kind === Kind.ENUM_TYPE_DEFINITION) {
|
|
167
|
-
result[astNode.name.value] = makeEnum(astNode);
|
|
168
|
-
} else if (astNode.kind === Kind.UNION_TYPE_DEFINITION || astNode.kind === Kind.INTERFACE_TYPE_DEFINITION) {
|
|
169
|
-
result[astNode.name.value] = {__resolveType: void 0};
|
|
170
|
-
} else if (astNode.kind === Kind.OBJECT_TYPE_DEFINITION) {
|
|
171
|
-
result[astNode.name.value] = {};
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
return result;
|
|
175
|
-
}
|
|
176
|
-
function makeEnum(astNode) {
|
|
177
|
-
var _a, _b;
|
|
178
|
-
const enumValueMap = Object.create(null);
|
|
179
|
-
for (const value of astNode.values || []) {
|
|
180
|
-
enumValueMap[value.name.value] = {
|
|
181
|
-
description: (_a = value.description) == null ? void 0 : _a.value,
|
|
182
|
-
deprecationReason: getDeprecationReason(value),
|
|
183
|
-
astNode: value
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
return new GraphQLEnumType({
|
|
187
|
-
name: astNode.name.value,
|
|
188
|
-
description: (_b = astNode.description) == null ? void 0 : _b.value,
|
|
189
|
-
values: enumValueMap
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
function makeInputObject(astNode, getTypeByName) {
|
|
193
|
-
var _a;
|
|
194
|
-
const name = astNode.name.value;
|
|
195
|
-
return new GraphQLInputObjectType({
|
|
196
|
-
name,
|
|
197
|
-
description: (_a = astNode.description) == null ? void 0 : _a.value,
|
|
198
|
-
fields: () => buildInputFieldMap(astNode.fields || [], getTypeByName),
|
|
199
|
-
astNode
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
function buildInputFieldMap(fieldNodes, getTypeByName) {
|
|
203
|
-
var _a;
|
|
204
|
-
const inputFieldMap = Object.create(null);
|
|
205
|
-
for (const field of fieldNodes) {
|
|
206
|
-
const type = getWrappedType(field.type, getTypeByName);
|
|
207
|
-
inputFieldMap[field.name.value] = {
|
|
208
|
-
type,
|
|
209
|
-
description: (_a = field.description) == null ? void 0 : _a.value,
|
|
210
|
-
defaultValue: valueFromAST(field.defaultValue, type),
|
|
211
|
-
deprecationReason: getDeprecationReason(field),
|
|
212
|
-
astNode: field
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
return inputFieldMap;
|
|
216
|
-
}
|
|
217
|
-
function getWrappedType(type, getTypeByName) {
|
|
218
|
-
if (type.kind === Kind.LIST_TYPE) {
|
|
219
|
-
return new GraphQLList(getWrappedType(type.type, getTypeByName));
|
|
220
|
-
} else if (type.kind === Kind.NON_NULL_TYPE) {
|
|
221
|
-
return new GraphQLNonNull(getWrappedType(type.type, getTypeByName));
|
|
222
|
-
} else {
|
|
223
|
-
return getTypeByName(type.name.value);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
function getDeprecationReason(node) {
|
|
227
|
-
const deprecated = getDirectiveValues(GraphQLDeprecatedDirective, node);
|
|
228
|
-
return deprecated == null ? void 0 : deprecated.reason;
|
|
229
|
-
}
|
|
230
|
-
export {
|
|
231
|
-
extractImplicitTypes,
|
|
232
|
-
extractImplicitTypesToTypescript
|
|
233
|
-
};
|