@graphitation/supermassive 0.6.3 → 0.8.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/.eslintcache +1 -1
- package/CHANGELOG.json +61 -1
- package/CHANGELOG.md +34 -2
- package/lib/benchmarks/index.js +13 -0
- package/lib/benchmarks/index.mjs +19 -1
- package/lib/benchmarks/swapi-schema/__generated__/schema.d.ts +3 -0
- package/lib/benchmarks/swapi-schema/__generated__/schema.d.ts.map +1 -0
- package/lib/collectFields.d.ts.map +1 -1
- package/lib/collectFields.js +33 -5
- package/lib/collectFields.mjs +33 -5
- package/lib/definition.d.ts +3 -0
- package/lib/definition.d.ts.map +1 -1
- package/lib/definition.js +9 -1
- package/lib/definition.mjs +9 -1
- package/lib/executeWithSchema.d.ts.map +1 -1
- package/lib/executeWithSchema.js +2 -16
- package/lib/executeWithSchema.mjs +2 -19
- package/lib/executeWithoutSchema.d.ts.map +1 -1
- package/lib/executeWithoutSchema.js +31 -12
- package/lib/executeWithoutSchema.mjs +31 -12
- package/lib/extractImplicitTypesRuntime.d.ts.map +1 -1
- package/lib/extractImplicitTypesRuntime.js +24 -3
- package/lib/extractImplicitTypesRuntime.mjs +24 -3
- package/lib/extractImplicitTypesToTypescript.d.ts.map +1 -1
- package/lib/extractImplicitTypesToTypescript.js +66 -17
- package/lib/extractImplicitTypesToTypescript.mjs +66 -17
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/subscribeWithSchema.d.ts.map +1 -1
- package/lib/subscribeWithSchema.js +2 -16
- package/lib/subscribeWithSchema.mjs +2 -19
- package/lib/subscribeWithoutSchema.d.ts.map +1 -1
- package/lib/subscribeWithoutSchema.js +5 -1
- package/lib/subscribeWithoutSchema.mjs +5 -1
- package/lib/types.d.ts +15 -2
- package/lib/types.d.ts.map +1 -1
- package/lib/utilities/mergeResolvers.d.ts +3 -0
- package/lib/utilities/mergeResolvers.d.ts.map +1 -0
- package/lib/utilities/mergeResolvers.js +36 -0
- package/lib/utilities/mergeResolvers.mjs +32 -0
- package/package.json +2 -2
|
@@ -1,20 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
3
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
4
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
|
|
6
|
-
var __objSpread = (a, b) => {
|
|
7
|
-
for (var prop in b || (b = {}))
|
|
8
|
-
if (__hasOwnProp.call(b, prop))
|
|
9
|
-
__defNormalProp(a, prop, b[prop]);
|
|
10
|
-
if (__getOwnPropSymbols)
|
|
11
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
-
if (__propIsEnum.call(b, prop))
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
}
|
|
15
|
-
return a;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
1
|
// src/executeWithSchema.ts
|
|
19
2
|
import {isInputType, buildASTSchema} from "graphql";
|
|
20
3
|
import {
|
|
@@ -45,11 +28,11 @@ function executeWithSchema({
|
|
|
45
28
|
}
|
|
46
29
|
};
|
|
47
30
|
extractedResolvers = extractImplicitTypes(typeDefs, getTypeByName);
|
|
48
|
-
const fullResolvers = __objSpread(__objSpread({}, extractedResolvers), resolvers);
|
|
49
31
|
const document = addTypesToRequestDocument(schema, rawDocument);
|
|
50
32
|
return executeWithoutSchema({
|
|
51
33
|
document,
|
|
52
|
-
resolvers
|
|
34
|
+
resolvers,
|
|
35
|
+
schemaResolvers: extractedResolvers,
|
|
53
36
|
rootValue,
|
|
54
37
|
contextValue,
|
|
55
38
|
variableValues,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executeWithoutSchema.d.ts","sourceRoot":"","sources":["../src/executeWithoutSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,YAAY,EASb,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,YAAY,EACZ,SAAS,EACT,sBAAsB,EACtB,uBAAuB,EACvB,2BAA2B,EAC3B,QAAQ,EACT,MAAM,gBAAgB,CAAC;AAQxB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAG3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"executeWithoutSchema.d.ts","sourceRoot":"","sources":["../src/executeWithoutSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,YAAY,EASb,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,YAAY,EACZ,SAAS,EACT,sBAAsB,EACtB,uBAAuB,EACvB,2BAA2B,EAC3B,QAAQ,EACT,MAAM,gBAAgB,CAAC;AAQxB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAG3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAI/D,OAAO,EACL,0BAA0B,EAE1B,qBAAqB,EAGrB,WAAW,EAEX,SAAS,EACT,YAAY,EAEZ,eAAe,EAChB,MAAM,SAAS,CAAC;AAQjB;;;;;;;;;;;;;;;;;;GAkBG;AAEH;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,SAAS,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC,sBAAsB,CAAC,CAAC;IAC1C,SAAS,EAAE,OAAO,CAAC;IACnB,YAAY,EAAE,OAAO,CAAC;IACtB,SAAS,EAAE,uBAAuB,CAAC;IACnC,cAAc,EAAE;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;IAChD,aAAa,EAAE,qBAAqB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC/C,YAAY,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACrC,MAAM,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;CAC7B;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,0BAA0B,GAC/B,cAAc,CAAC,eAAe,CAAC,CA4CjC;AAoBD;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,YAAY,EACtB,iBAAiB,EAAE,KAAK,CAAC;IAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAAC,GACxD,IAAI,CAQN;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,YAAY,EACtB,SAAS,EAAE,OAAO,EAClB,YAAY,EAAE,OAAO,EACrB,iBAAiB,EAAE,KAAK,CAAC;IAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAAC,EACzD,aAAa,EAAE,KAAK,CAAC,MAAM,CAAC,EAC5B,aAAa,EAAE,KAAK,CAAC,qBAAqB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,EAC7D,YAAY,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,GACnD,KAAK,CAAC,YAAY,CAAC,GAAG,gBAAgB,CAyDxC;AAoPD;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,gBAAgB,EAC5B,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC,EAC5B,cAAc,EAAE,MAAM,EACtB,cAAc,EAAE,MAAM,EACtB,cAAc,EAAE,QAAQ,EACxB,IAAI,EAAE,IAAI,GACT,WAAW,CAeb;AA2XD;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,EAAE,YAAY,CAAC,OAAO,EAAE,OAAO,CAM9D,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,EAAE,qBAAqB,CACtD,OAAO,EACP,OAAO,CAUR,CAAC;AAGF,wBAAgB,wBAAwB,CACtC,SAAS,EAAE,uBAAuB,GAAG,2BAA2B,GAC/D,MAAM,CASR"}
|
|
@@ -41,11 +41,14 @@ var import_isPromise = __toModule(require("./jsutils/isPromise"));
|
|
|
41
41
|
var import_Path = __toModule(require("./jsutils/Path"));
|
|
42
42
|
var import_promiseForObject = __toModule(require("./jsutils/promiseForObject"));
|
|
43
43
|
var import_promiseReduce = __toModule(require("./jsutils/promiseReduce"));
|
|
44
|
+
var import_definition = __toModule(require("./definition"));
|
|
45
|
+
var import_mergeResolvers = __toModule(require("./utilities/mergeResolvers"));
|
|
44
46
|
var import_typeNameFromAST = __toModule(require("./utilities/typeNameFromAST"));
|
|
45
47
|
var import_values = __toModule(require("./values"));
|
|
46
48
|
function executeWithoutSchema(args) {
|
|
47
49
|
const {
|
|
48
50
|
resolvers,
|
|
51
|
+
schemaResolvers,
|
|
49
52
|
document,
|
|
50
53
|
rootValue,
|
|
51
54
|
contextValue,
|
|
@@ -54,8 +57,9 @@ function executeWithoutSchema(args) {
|
|
|
54
57
|
fieldResolver,
|
|
55
58
|
typeResolver
|
|
56
59
|
} = args;
|
|
60
|
+
const combinedResolvers = (0, import_mergeResolvers.mergeResolvers)(resolvers, schemaResolvers);
|
|
57
61
|
assertValidExecutionArguments(document, variableValues);
|
|
58
|
-
const exeContext = buildExecutionContext(
|
|
62
|
+
const exeContext = buildExecutionContext(combinedResolvers, document, rootValue, contextValue, variableValues, operationName, fieldResolver, typeResolver);
|
|
59
63
|
if (!("resolvers" in exeContext)) {
|
|
60
64
|
return {errors: exeContext};
|
|
61
65
|
} else {
|
|
@@ -270,7 +274,7 @@ function completeValue(exeContext, returnTypeNode, fieldNodes, info, path, resul
|
|
|
270
274
|
}
|
|
271
275
|
if (returnType instanceof import_graphql.GraphQLInputObjectType) {
|
|
272
276
|
}
|
|
273
|
-
if (
|
|
277
|
+
if ((0, import_definition.isUnionResolverType)(returnType) || (0, import_definition.isInterfaceResolverType)(returnType)) {
|
|
274
278
|
return completeAbstractValue(exeContext, returnType, fieldNodes, info, path, result);
|
|
275
279
|
}
|
|
276
280
|
if (typeof returnType === "object") {
|
|
@@ -325,17 +329,32 @@ function completeAbstractValue(exeContext, returnType, fieldNodes, info, path, r
|
|
|
325
329
|
return completeObjectValue(exeContext, ensureValidRuntimeType(runtimeTypeName, exeContext), fieldNodes, info, path, result);
|
|
326
330
|
}
|
|
327
331
|
function ensureValidRuntimeType(runtimeTypeName, exeContext) {
|
|
328
|
-
if (typeof runtimeTypeName
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
332
|
+
if (typeof runtimeTypeName !== "string") {
|
|
333
|
+
throw new import_graphql.GraphQLError(`Could not determine runtime type for abstract type ${runtimeTypeName}`);
|
|
334
|
+
}
|
|
335
|
+
const runtimeType = exeContext.resolvers[runtimeTypeName];
|
|
336
|
+
if (!runtimeType) {
|
|
337
|
+
throw new import_graphql.GraphQLError(`Type "${runtimeTypeName}" does not exist inside the schema.`);
|
|
338
|
+
} else if (runtimeType instanceof import_graphql.GraphQLScalarType || runtimeType instanceof import_graphql.GraphQLEnumType || runtimeType instanceof import_graphql.GraphQLInputObjectType || runtimeType.__resolveType) {
|
|
339
|
+
throw new import_graphql.GraphQLError(`Given runtime object "${getRuntimeTypeInstanceName(runtimeType)}" type is not a possible type for "${runtimeTypeName}".`);
|
|
340
|
+
} else {
|
|
341
|
+
return runtimeTypeName;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
function getRuntimeTypeInstanceName(runtimeType) {
|
|
345
|
+
if (runtimeType instanceof import_graphql.GraphQLScalarType) {
|
|
346
|
+
return "GraphQLScalarType";
|
|
347
|
+
} else if (runtimeType instanceof import_graphql.GraphQLEnumType) {
|
|
348
|
+
return "GraphQLEnumType";
|
|
349
|
+
} else if (runtimeType instanceof import_graphql.GraphQLInputObjectType) {
|
|
350
|
+
return "GraphQLInputObjectType";
|
|
351
|
+
} else if ("__types" in runtimeType) {
|
|
352
|
+
return "GraphQLUnionType";
|
|
353
|
+
} else if ("__implementedBy" in runtimeType) {
|
|
354
|
+
return "GraphQLInterfaceType";
|
|
355
|
+
} else {
|
|
356
|
+
return "Unknown";
|
|
337
357
|
}
|
|
338
|
-
throw new Error("TODO - Could not determine runtime type for abstract type");
|
|
339
358
|
}
|
|
340
359
|
function completeObjectValue(exeContext, returnTypeName, fieldNodes, info, path, result) {
|
|
341
360
|
const subFieldNodes = collectSubfields(exeContext, returnTypeName, fieldNodes);
|
|
@@ -18,6 +18,8 @@ import {isPromise} from "./jsutils/isPromise.mjs";
|
|
|
18
18
|
import {addPath, pathToArray} from "./jsutils/Path.mjs";
|
|
19
19
|
import {promiseForObject} from "./jsutils/promiseForObject.mjs";
|
|
20
20
|
import {promiseReduce} from "./jsutils/promiseReduce.mjs";
|
|
21
|
+
import {isUnionResolverType, isInterfaceResolverType} from "./definition.mjs";
|
|
22
|
+
import {mergeResolvers} from "./utilities/mergeResolvers.mjs";
|
|
21
23
|
import {typeNameFromAST} from "./utilities/typeNameFromAST.mjs";
|
|
22
24
|
import {
|
|
23
25
|
getArgumentValues,
|
|
@@ -27,6 +29,7 @@ import {
|
|
|
27
29
|
function executeWithoutSchema(args) {
|
|
28
30
|
const {
|
|
29
31
|
resolvers,
|
|
32
|
+
schemaResolvers,
|
|
30
33
|
document,
|
|
31
34
|
rootValue,
|
|
32
35
|
contextValue,
|
|
@@ -35,8 +38,9 @@ function executeWithoutSchema(args) {
|
|
|
35
38
|
fieldResolver,
|
|
36
39
|
typeResolver
|
|
37
40
|
} = args;
|
|
41
|
+
const combinedResolvers = mergeResolvers(resolvers, schemaResolvers);
|
|
38
42
|
assertValidExecutionArguments(document, variableValues);
|
|
39
|
-
const exeContext = buildExecutionContext(
|
|
43
|
+
const exeContext = buildExecutionContext(combinedResolvers, document, rootValue, contextValue, variableValues, operationName, fieldResolver, typeResolver);
|
|
40
44
|
if (!("resolvers" in exeContext)) {
|
|
41
45
|
return {errors: exeContext};
|
|
42
46
|
} else {
|
|
@@ -251,7 +255,7 @@ function completeValue(exeContext, returnTypeNode, fieldNodes, info, path, resul
|
|
|
251
255
|
}
|
|
252
256
|
if (returnType instanceof GraphQLInputObjectType) {
|
|
253
257
|
}
|
|
254
|
-
if (
|
|
258
|
+
if (isUnionResolverType(returnType) || isInterfaceResolverType(returnType)) {
|
|
255
259
|
return completeAbstractValue(exeContext, returnType, fieldNodes, info, path, result);
|
|
256
260
|
}
|
|
257
261
|
if (typeof returnType === "object") {
|
|
@@ -306,17 +310,32 @@ function completeAbstractValue(exeContext, returnType, fieldNodes, info, path, r
|
|
|
306
310
|
return completeObjectValue(exeContext, ensureValidRuntimeType(runtimeTypeName, exeContext), fieldNodes, info, path, result);
|
|
307
311
|
}
|
|
308
312
|
function ensureValidRuntimeType(runtimeTypeName, exeContext) {
|
|
309
|
-
if (typeof runtimeTypeName
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
313
|
+
if (typeof runtimeTypeName !== "string") {
|
|
314
|
+
throw new GraphQLError(`Could not determine runtime type for abstract type ${runtimeTypeName}`);
|
|
315
|
+
}
|
|
316
|
+
const runtimeType = exeContext.resolvers[runtimeTypeName];
|
|
317
|
+
if (!runtimeType) {
|
|
318
|
+
throw new GraphQLError(`Type "${runtimeTypeName}" does not exist inside the schema.`);
|
|
319
|
+
} else if (runtimeType instanceof GraphQLScalarType || runtimeType instanceof GraphQLEnumType || runtimeType instanceof GraphQLInputObjectType || runtimeType.__resolveType) {
|
|
320
|
+
throw new GraphQLError(`Given runtime object "${getRuntimeTypeInstanceName(runtimeType)}" type is not a possible type for "${runtimeTypeName}".`);
|
|
321
|
+
} else {
|
|
322
|
+
return runtimeTypeName;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
function getRuntimeTypeInstanceName(runtimeType) {
|
|
326
|
+
if (runtimeType instanceof GraphQLScalarType) {
|
|
327
|
+
return "GraphQLScalarType";
|
|
328
|
+
} else if (runtimeType instanceof GraphQLEnumType) {
|
|
329
|
+
return "GraphQLEnumType";
|
|
330
|
+
} else if (runtimeType instanceof GraphQLInputObjectType) {
|
|
331
|
+
return "GraphQLInputObjectType";
|
|
332
|
+
} else if ("__types" in runtimeType) {
|
|
333
|
+
return "GraphQLUnionType";
|
|
334
|
+
} else if ("__implementedBy" in runtimeType) {
|
|
335
|
+
return "GraphQLInterfaceType";
|
|
336
|
+
} else {
|
|
337
|
+
return "Unknown";
|
|
318
338
|
}
|
|
319
|
-
throw new Error("TODO - Could not determine runtime type for abstract type");
|
|
320
339
|
}
|
|
321
340
|
function completeObjectValue(exeContext, returnTypeName, fieldNodes, info, path, result) {
|
|
322
341
|
const subFieldNodes = collectSubfields(exeContext, returnTypeName, fieldNodes);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractImplicitTypesRuntime.d.ts","sourceRoot":"","sources":["../src/extractImplicitTypesRuntime.ts"],"names":[],"mappings":"AACA,OAAO,EACL,YAAY,
|
|
1
|
+
{"version":3,"file":"extractImplicitTypesRuntime.d.ts","sourceRoot":"","sources":["../src/extractImplicitTypesRuntime.ts"],"names":[],"mappings":"AACA,OAAO,EACL,YAAY,EAgBZ,gBAAgB,EAKjB,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,SAAS,EAIV,MAAM,SAAS,CAAC;AAEjB,wBAAgB,oBAAoB,CAAC,OAAO,GAAG,GAAG,EAAE,QAAQ,GAAG,GAAG,EAChE,QAAQ,EAAE,YAAY,EACtB,aAAa,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,gBAAgB,GAChD,SAAS,CAAC,OAAO,EAAE,QAAQ,CAAC,CA6C9B"}
|
|
@@ -26,8 +26,9 @@ __export(exports, {
|
|
|
26
26
|
});
|
|
27
27
|
var import_graphql = __toModule(require("graphql"));
|
|
28
28
|
function extractImplicitTypes(document, getTypeByName) {
|
|
29
|
-
var _a;
|
|
29
|
+
var _a, _b, _c;
|
|
30
30
|
const result = Object.create(null);
|
|
31
|
+
const implementedBy = {};
|
|
31
32
|
for (let astNode of document.definitions) {
|
|
32
33
|
if (astNode.kind === import_graphql.Kind.SCALAR_TYPE_DEFINITION) {
|
|
33
34
|
const name = astNode.name.value;
|
|
@@ -39,9 +40,29 @@ function extractImplicitTypes(document, getTypeByName) {
|
|
|
39
40
|
result[astNode.name.value] = makeInputObject(astNode, getTypeByName);
|
|
40
41
|
} else if (astNode.kind === import_graphql.Kind.ENUM_TYPE_DEFINITION) {
|
|
41
42
|
result[astNode.name.value] = makeEnum(astNode);
|
|
42
|
-
} else if (astNode.kind === import_graphql.Kind.
|
|
43
|
-
|
|
43
|
+
} else if (astNode.kind === import_graphql.Kind.INTERFACE_TYPE_DEFINITION) {
|
|
44
|
+
if (!implementedBy[astNode.name.value]) {
|
|
45
|
+
implementedBy[astNode.name.value] = [];
|
|
46
|
+
}
|
|
47
|
+
result[astNode.name.value] = {
|
|
48
|
+
__resolveType: void 0,
|
|
49
|
+
__implementedBy: implementedBy[astNode.name.value]
|
|
50
|
+
};
|
|
51
|
+
} else if (astNode.kind === import_graphql.Kind.UNION_TYPE_DEFINITION) {
|
|
52
|
+
const types = (_b = astNode.types) == null ? void 0 : _b.map((typeNode) => {
|
|
53
|
+
return typeNode.name.value;
|
|
54
|
+
});
|
|
55
|
+
result[astNode.name.value] = {
|
|
56
|
+
__resolveType: void 0,
|
|
57
|
+
__types: types || []
|
|
58
|
+
};
|
|
44
59
|
} else if (astNode.kind === import_graphql.Kind.OBJECT_TYPE_DEFINITION) {
|
|
60
|
+
(_c = astNode.interfaces) == null ? void 0 : _c.forEach((node) => {
|
|
61
|
+
if (!implementedBy[node.name.value]) {
|
|
62
|
+
implementedBy[node.name.value] = [];
|
|
63
|
+
}
|
|
64
|
+
implementedBy[node.name.value].push(astNode.name.value);
|
|
65
|
+
});
|
|
45
66
|
result[astNode.name.value] = {};
|
|
46
67
|
}
|
|
47
68
|
}
|
|
@@ -11,8 +11,9 @@ import {
|
|
|
11
11
|
GraphQLList
|
|
12
12
|
} from "graphql";
|
|
13
13
|
function extractImplicitTypes(document, getTypeByName) {
|
|
14
|
-
var _a;
|
|
14
|
+
var _a, _b, _c;
|
|
15
15
|
const result = Object.create(null);
|
|
16
|
+
const implementedBy = {};
|
|
16
17
|
for (let astNode of document.definitions) {
|
|
17
18
|
if (astNode.kind === Kind.SCALAR_TYPE_DEFINITION) {
|
|
18
19
|
const name = astNode.name.value;
|
|
@@ -24,9 +25,29 @@ function extractImplicitTypes(document, getTypeByName) {
|
|
|
24
25
|
result[astNode.name.value] = makeInputObject(astNode, getTypeByName);
|
|
25
26
|
} else if (astNode.kind === Kind.ENUM_TYPE_DEFINITION) {
|
|
26
27
|
result[astNode.name.value] = makeEnum(astNode);
|
|
27
|
-
} else if (astNode.kind === Kind.
|
|
28
|
-
|
|
28
|
+
} else if (astNode.kind === Kind.INTERFACE_TYPE_DEFINITION) {
|
|
29
|
+
if (!implementedBy[astNode.name.value]) {
|
|
30
|
+
implementedBy[astNode.name.value] = [];
|
|
31
|
+
}
|
|
32
|
+
result[astNode.name.value] = {
|
|
33
|
+
__resolveType: void 0,
|
|
34
|
+
__implementedBy: implementedBy[astNode.name.value]
|
|
35
|
+
};
|
|
36
|
+
} else if (astNode.kind === Kind.UNION_TYPE_DEFINITION) {
|
|
37
|
+
const types = (_b = astNode.types) == null ? void 0 : _b.map((typeNode) => {
|
|
38
|
+
return typeNode.name.value;
|
|
39
|
+
});
|
|
40
|
+
result[astNode.name.value] = {
|
|
41
|
+
__resolveType: void 0,
|
|
42
|
+
__types: types || []
|
|
43
|
+
};
|
|
29
44
|
} else if (astNode.kind === Kind.OBJECT_TYPE_DEFINITION) {
|
|
45
|
+
(_c = astNode.interfaces) == null ? void 0 : _c.forEach((node) => {
|
|
46
|
+
if (!implementedBy[node.name.value]) {
|
|
47
|
+
implementedBy[node.name.value] = [];
|
|
48
|
+
}
|
|
49
|
+
implementedBy[node.name.value].push(astNode.name.value);
|
|
50
|
+
});
|
|
30
51
|
result[astNode.name.value] = {};
|
|
31
52
|
}
|
|
32
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractImplicitTypesToTypescript.d.ts","sourceRoot":"","sources":["../src/extractImplicitTypesToTypescript.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,MAAM,YAAY,CAAC;AACzC,OAAO,EACL,YAAY,
|
|
1
|
+
{"version":3,"file":"extractImplicitTypesToTypescript.d.ts","sourceRoot":"","sources":["../src/extractImplicitTypesToTypescript.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,MAAM,YAAY,CAAC;AACzC,OAAO,EACL,YAAY,EAab,MAAM,SAAS,CAAC;AAmBjB,wBAAgB,gCAAgC,CAC9C,QAAQ,EAAE,YAAY,GACrB,EAAE,CAAC,UAAU,CA8Jf"}
|
|
@@ -33,9 +33,18 @@ const SPECIFIED_SCALARS = {
|
|
|
33
33
|
Float: "GraphQLFloat",
|
|
34
34
|
Boolean: "GraphQLBoolean"
|
|
35
35
|
};
|
|
36
|
+
const SUPERMASSIVE_TYPES = {
|
|
37
|
+
INTERFACE_TYPE_RESOLVER: "InterfaceTypeResolver",
|
|
38
|
+
UNION_TYPE_RESOLVER: "UnionTypeResolver",
|
|
39
|
+
OBJECT_TYPE_RESOLVER: "ObjectTypeResolver",
|
|
40
|
+
ENUM_TYPE_RESOLVER: "EnumTypeResolver",
|
|
41
|
+
SCALAR_TYPE_RESOLVER: "ScalarTypeResolver",
|
|
42
|
+
INPUT_OBJECT_TYPE_RESOLVER: "InputObjectTypeResolver"
|
|
43
|
+
};
|
|
36
44
|
function extractImplicitTypesToTypescript(document) {
|
|
45
|
+
var _a, _b;
|
|
37
46
|
const definitions = [];
|
|
38
|
-
const
|
|
47
|
+
const graphQLImports = [
|
|
39
48
|
"GraphQLList",
|
|
40
49
|
"GraphQLNonNull",
|
|
41
50
|
"GraphQLID",
|
|
@@ -44,37 +53,70 @@ function extractImplicitTypesToTypescript(document) {
|
|
|
44
53
|
"GraphQLFloat",
|
|
45
54
|
"GraphQLBoolean"
|
|
46
55
|
];
|
|
56
|
+
const supermassiveImports = ["Resolvers"];
|
|
47
57
|
const identifiers = [];
|
|
58
|
+
const implementedBy = {};
|
|
59
|
+
const interfaceAstNodes = [];
|
|
48
60
|
for (let astNode of document.definitions) {
|
|
49
61
|
if (astNode.kind === import_graphql.Kind.SCALAR_TYPE_DEFINITION) {
|
|
50
62
|
definitions.push(createScalarType(astNode));
|
|
51
|
-
addToSetArray(
|
|
63
|
+
addToSetArray(graphQLImports, "GraphQLScalarType");
|
|
64
|
+
addToSetArray(supermassiveImports, SUPERMASSIVE_TYPES.SCALAR_TYPE_RESOLVER);
|
|
52
65
|
addToSetArray(identifiers, astNode.name.value);
|
|
53
66
|
} else if (astNode.kind === import_graphql.Kind.INPUT_OBJECT_TYPE_DEFINITION) {
|
|
54
67
|
definitions.push(createInputObjectType(astNode));
|
|
55
|
-
addToSetArray(
|
|
68
|
+
addToSetArray(graphQLImports, "GraphQLInputObjectType");
|
|
69
|
+
addToSetArray(supermassiveImports, SUPERMASSIVE_TYPES.INPUT_OBJECT_TYPE_RESOLVER);
|
|
56
70
|
addToSetArray(identifiers, astNode.name.value);
|
|
57
71
|
} else if (astNode.kind === import_graphql.Kind.ENUM_TYPE_DEFINITION) {
|
|
58
72
|
definitions.push(createEnumType(astNode));
|
|
59
|
-
addToSetArray(
|
|
73
|
+
addToSetArray(graphQLImports, "GraphQLEnumType");
|
|
74
|
+
addToSetArray(supermassiveImports, SUPERMASSIVE_TYPES.ENUM_TYPE_RESOLVER);
|
|
75
|
+
addToSetArray(identifiers, astNode.name.value);
|
|
76
|
+
} else if (astNode.kind === import_graphql.Kind.INTERFACE_TYPE_DEFINITION) {
|
|
77
|
+
interfaceAstNodes.push(astNode);
|
|
78
|
+
addToSetArray(supermassiveImports, SUPERMASSIVE_TYPES.INTERFACE_TYPE_RESOLVER);
|
|
60
79
|
addToSetArray(identifiers, astNode.name.value);
|
|
61
|
-
} else if (astNode.kind === import_graphql.Kind.UNION_TYPE_DEFINITION
|
|
62
|
-
|
|
80
|
+
} else if (astNode.kind === import_graphql.Kind.UNION_TYPE_DEFINITION) {
|
|
81
|
+
const types = (_a = astNode.types) == null ? void 0 : _a.map((typeNode) => {
|
|
82
|
+
return typeNode.name.value;
|
|
83
|
+
});
|
|
84
|
+
definitions.push(createUnionType(astNode, types || []));
|
|
85
|
+
addToSetArray(supermassiveImports, SUPERMASSIVE_TYPES.UNION_TYPE_RESOLVER);
|
|
63
86
|
addToSetArray(identifiers, astNode.name.value);
|
|
64
87
|
} else if (astNode.kind === import_graphql.Kind.OBJECT_TYPE_DEFINITION) {
|
|
88
|
+
(_b = astNode.interfaces) == null ? void 0 : _b.forEach((node) => {
|
|
89
|
+
if (!implementedBy[node.name.value]) {
|
|
90
|
+
implementedBy[node.name.value] = [];
|
|
91
|
+
}
|
|
92
|
+
implementedBy[node.name.value].push(astNode.name.value);
|
|
93
|
+
});
|
|
65
94
|
definitions.push(createObjectType(astNode));
|
|
95
|
+
addToSetArray(supermassiveImports, SUPERMASSIVE_TYPES.OBJECT_TYPE_RESOLVER);
|
|
66
96
|
addToSetArray(identifiers, astNode.name.value);
|
|
67
97
|
}
|
|
68
98
|
}
|
|
69
|
-
|
|
99
|
+
interfaceAstNodes.forEach((astNode) => {
|
|
100
|
+
if (!implementedBy[astNode.name.value]) {
|
|
101
|
+
implementedBy[astNode.name.value] = [];
|
|
102
|
+
}
|
|
103
|
+
definitions.push(createInterfaceType(astNode, implementedBy[astNode.name.value]));
|
|
104
|
+
});
|
|
105
|
+
const graphQLImportDefinition = import_typescript.factory.createImportDeclaration(void 0, void 0, import_typescript.factory.createImportClause(false, void 0, import_typescript.factory.createNamedImports(graphQLImports.map((imp) => import_typescript.factory.createImportSpecifier(void 0, import_typescript.factory.createIdentifier(imp))))), import_typescript.factory.createStringLiteral("graphql"));
|
|
106
|
+
const supermassiveImportDefinition = import_typescript.factory.createImportDeclaration(void 0, void 0, import_typescript.factory.createImportClause(false, void 0, import_typescript.factory.createNamedImports(supermassiveImports.map((imp) => import_typescript.factory.createImportSpecifier(void 0, import_typescript.factory.createIdentifier(imp))))), import_typescript.factory.createStringLiteral("@graphitation/supermassive"));
|
|
70
107
|
const exportDefinition = import_typescript.factory.createVariableStatement([import_typescript.factory.createModifier(import_typescript.default.SyntaxKind.ExportKeyword)], import_typescript.factory.createVariableDeclarationList([
|
|
71
|
-
import_typescript.factory.createVariableDeclaration(import_typescript.factory.createIdentifier("resolvers"), void 0, void 0, import_typescript.factory.createObjectLiteralExpression(identifiers.map((def) => import_typescript.factory.createShorthandPropertyAssignment(import_typescript.factory.createIdentifier(def), void 0))))
|
|
108
|
+
import_typescript.factory.createVariableDeclaration(import_typescript.factory.createIdentifier("resolvers"), void 0, import_typescript.factory.createTypeReferenceNode(import_typescript.factory.createIdentifier("Resolvers"), void 0), import_typescript.factory.createObjectLiteralExpression(identifiers.map((def) => import_typescript.factory.createShorthandPropertyAssignment(import_typescript.factory.createIdentifier(def), void 0))))
|
|
72
109
|
], import_typescript.default.NodeFlags.Const));
|
|
73
|
-
return import_typescript.factory.createSourceFile([
|
|
110
|
+
return import_typescript.factory.createSourceFile([
|
|
111
|
+
graphQLImportDefinition,
|
|
112
|
+
supermassiveImportDefinition,
|
|
113
|
+
...definitions,
|
|
114
|
+
exportDefinition
|
|
115
|
+
], import_typescript.factory.createToken(import_typescript.default.SyntaxKind.EndOfFileToken), 0);
|
|
74
116
|
}
|
|
75
|
-
function createDeclaration(name, decl) {
|
|
117
|
+
function createDeclaration(name, decl, typeReferenceNode) {
|
|
76
118
|
return import_typescript.factory.createVariableStatement(void 0, import_typescript.factory.createVariableDeclarationList([
|
|
77
|
-
import_typescript.factory.createVariableDeclaration(import_typescript.factory.createIdentifier(name), void 0,
|
|
119
|
+
import_typescript.factory.createVariableDeclaration(import_typescript.factory.createIdentifier(name), void 0, typeReferenceNode, decl)
|
|
78
120
|
], import_typescript.default.NodeFlags.Const));
|
|
79
121
|
}
|
|
80
122
|
function createScalarType(astNode) {
|
|
@@ -84,7 +126,7 @@ function createScalarType(astNode) {
|
|
|
84
126
|
import_typescript.factory.createPropertyAssignment(import_typescript.factory.createIdentifier("name"), import_typescript.factory.createStringLiteral(astNode.name.value)),
|
|
85
127
|
import_typescript.factory.createPropertyAssignment(import_typescript.factory.createIdentifier("description"), import_typescript.factory.createStringLiteral(((_a = astNode.description) == null ? void 0 : _a.value) || ""))
|
|
86
128
|
], true)
|
|
87
|
-
]));
|
|
129
|
+
]), import_typescript.factory.createTypeReferenceNode(import_typescript.factory.createIdentifier(SUPERMASSIVE_TYPES.SCALAR_TYPE_RESOLVER), void 0));
|
|
88
130
|
}
|
|
89
131
|
function createInputObjectType(astNode) {
|
|
90
132
|
var _a;
|
|
@@ -94,7 +136,7 @@ function createInputObjectType(astNode) {
|
|
|
94
136
|
import_typescript.factory.createPropertyAssignment(import_typescript.factory.createIdentifier("description"), import_typescript.factory.createStringLiteral(((_a = astNode.description) == null ? void 0 : _a.value) || "")),
|
|
95
137
|
import_typescript.factory.createPropertyAssignment(import_typescript.factory.createIdentifier("fields"), import_typescript.factory.createArrowFunction(void 0, void 0, [], void 0, import_typescript.factory.createToken(import_typescript.default.SyntaxKind.EqualsGreaterThanToken), import_typescript.factory.createParenthesizedExpression(import_typescript.factory.createObjectLiteralExpression(createInputFields(astNode.fields || []), true))))
|
|
96
138
|
], true)
|
|
97
|
-
]));
|
|
139
|
+
]), import_typescript.factory.createTypeReferenceNode(import_typescript.factory.createIdentifier(SUPERMASSIVE_TYPES.INPUT_OBJECT_TYPE_RESOLVER), void 0));
|
|
98
140
|
}
|
|
99
141
|
function createInputFields(astNodes) {
|
|
100
142
|
return astNodes.map((astNode) => {
|
|
@@ -122,15 +164,22 @@ function createEnumType(astNode) {
|
|
|
122
164
|
]));
|
|
123
165
|
})))
|
|
124
166
|
])
|
|
125
|
-
]));
|
|
167
|
+
]), import_typescript.factory.createTypeReferenceNode(import_typescript.factory.createIdentifier(SUPERMASSIVE_TYPES.ENUM_TYPE_RESOLVER), void 0));
|
|
168
|
+
}
|
|
169
|
+
function createUnionType(astNode, types) {
|
|
170
|
+
return createDeclaration(astNode.name.value, import_typescript.factory.createObjectLiteralExpression([
|
|
171
|
+
import_typescript.factory.createPropertyAssignment(import_typescript.factory.createIdentifier("__types"), import_typescript.factory.createArrayLiteralExpression(types.map((value) => import_typescript.factory.createStringLiteral(value)))),
|
|
172
|
+
import_typescript.factory.createPropertyAssignment(import_typescript.factory.createIdentifier("__resolveType"), import_typescript.factory.createIdentifier("undefined"))
|
|
173
|
+
]), import_typescript.factory.createTypeReferenceNode(import_typescript.factory.createIdentifier(SUPERMASSIVE_TYPES.UNION_TYPE_RESOLVER), void 0));
|
|
126
174
|
}
|
|
127
|
-
function
|
|
175
|
+
function createInterfaceType(astNode, implementedBy) {
|
|
128
176
|
return createDeclaration(astNode.name.value, import_typescript.factory.createObjectLiteralExpression([
|
|
177
|
+
import_typescript.factory.createPropertyAssignment(import_typescript.factory.createIdentifier("__implementedBy"), import_typescript.factory.createArrayLiteralExpression(implementedBy.map((value) => import_typescript.factory.createStringLiteral(value)))),
|
|
129
178
|
import_typescript.factory.createPropertyAssignment(import_typescript.factory.createIdentifier("__resolveType"), import_typescript.factory.createIdentifier("undefined"))
|
|
130
|
-
]));
|
|
179
|
+
]), import_typescript.factory.createTypeReferenceNode(import_typescript.factory.createIdentifier(SUPERMASSIVE_TYPES.INTERFACE_TYPE_RESOLVER), void 0));
|
|
131
180
|
}
|
|
132
181
|
function createObjectType(astNode) {
|
|
133
|
-
return createDeclaration(astNode.name.value, import_typescript.factory.createObjectLiteralExpression());
|
|
182
|
+
return createDeclaration(astNode.name.value, import_typescript.factory.createObjectLiteralExpression(), import_typescript.factory.createTypeReferenceNode(import_typescript.factory.createIdentifier(SUPERMASSIVE_TYPES.OBJECT_TYPE_RESOLVER), void 0));
|
|
134
183
|
}
|
|
135
184
|
function createType(astNode) {
|
|
136
185
|
if (astNode.kind === import_graphql.Kind.LIST_TYPE) {
|
|
@@ -10,9 +10,18 @@ var SPECIFIED_SCALARS = {
|
|
|
10
10
|
Float: "GraphQLFloat",
|
|
11
11
|
Boolean: "GraphQLBoolean"
|
|
12
12
|
};
|
|
13
|
+
var SUPERMASSIVE_TYPES = {
|
|
14
|
+
INTERFACE_TYPE_RESOLVER: "InterfaceTypeResolver",
|
|
15
|
+
UNION_TYPE_RESOLVER: "UnionTypeResolver",
|
|
16
|
+
OBJECT_TYPE_RESOLVER: "ObjectTypeResolver",
|
|
17
|
+
ENUM_TYPE_RESOLVER: "EnumTypeResolver",
|
|
18
|
+
SCALAR_TYPE_RESOLVER: "ScalarTypeResolver",
|
|
19
|
+
INPUT_OBJECT_TYPE_RESOLVER: "InputObjectTypeResolver"
|
|
20
|
+
};
|
|
13
21
|
function extractImplicitTypesToTypescript(document) {
|
|
22
|
+
var _a, _b;
|
|
14
23
|
const definitions = [];
|
|
15
|
-
const
|
|
24
|
+
const graphQLImports = [
|
|
16
25
|
"GraphQLList",
|
|
17
26
|
"GraphQLNonNull",
|
|
18
27
|
"GraphQLID",
|
|
@@ -21,37 +30,70 @@ function extractImplicitTypesToTypescript(document) {
|
|
|
21
30
|
"GraphQLFloat",
|
|
22
31
|
"GraphQLBoolean"
|
|
23
32
|
];
|
|
33
|
+
const supermassiveImports = ["Resolvers"];
|
|
24
34
|
const identifiers = [];
|
|
35
|
+
const implementedBy = {};
|
|
36
|
+
const interfaceAstNodes = [];
|
|
25
37
|
for (let astNode of document.definitions) {
|
|
26
38
|
if (astNode.kind === Kind.SCALAR_TYPE_DEFINITION) {
|
|
27
39
|
definitions.push(createScalarType(astNode));
|
|
28
|
-
addToSetArray(
|
|
40
|
+
addToSetArray(graphQLImports, "GraphQLScalarType");
|
|
41
|
+
addToSetArray(supermassiveImports, SUPERMASSIVE_TYPES.SCALAR_TYPE_RESOLVER);
|
|
29
42
|
addToSetArray(identifiers, astNode.name.value);
|
|
30
43
|
} else if (astNode.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION) {
|
|
31
44
|
definitions.push(createInputObjectType(astNode));
|
|
32
|
-
addToSetArray(
|
|
45
|
+
addToSetArray(graphQLImports, "GraphQLInputObjectType");
|
|
46
|
+
addToSetArray(supermassiveImports, SUPERMASSIVE_TYPES.INPUT_OBJECT_TYPE_RESOLVER);
|
|
33
47
|
addToSetArray(identifiers, astNode.name.value);
|
|
34
48
|
} else if (astNode.kind === Kind.ENUM_TYPE_DEFINITION) {
|
|
35
49
|
definitions.push(createEnumType(astNode));
|
|
36
|
-
addToSetArray(
|
|
50
|
+
addToSetArray(graphQLImports, "GraphQLEnumType");
|
|
51
|
+
addToSetArray(supermassiveImports, SUPERMASSIVE_TYPES.ENUM_TYPE_RESOLVER);
|
|
52
|
+
addToSetArray(identifiers, astNode.name.value);
|
|
53
|
+
} else if (astNode.kind === Kind.INTERFACE_TYPE_DEFINITION) {
|
|
54
|
+
interfaceAstNodes.push(astNode);
|
|
55
|
+
addToSetArray(supermassiveImports, SUPERMASSIVE_TYPES.INTERFACE_TYPE_RESOLVER);
|
|
37
56
|
addToSetArray(identifiers, astNode.name.value);
|
|
38
|
-
} else if (astNode.kind === Kind.UNION_TYPE_DEFINITION
|
|
39
|
-
|
|
57
|
+
} else if (astNode.kind === Kind.UNION_TYPE_DEFINITION) {
|
|
58
|
+
const types = (_a = astNode.types) == null ? void 0 : _a.map((typeNode) => {
|
|
59
|
+
return typeNode.name.value;
|
|
60
|
+
});
|
|
61
|
+
definitions.push(createUnionType(astNode, types || []));
|
|
62
|
+
addToSetArray(supermassiveImports, SUPERMASSIVE_TYPES.UNION_TYPE_RESOLVER);
|
|
40
63
|
addToSetArray(identifiers, astNode.name.value);
|
|
41
64
|
} else if (astNode.kind === Kind.OBJECT_TYPE_DEFINITION) {
|
|
65
|
+
(_b = astNode.interfaces) == null ? void 0 : _b.forEach((node) => {
|
|
66
|
+
if (!implementedBy[node.name.value]) {
|
|
67
|
+
implementedBy[node.name.value] = [];
|
|
68
|
+
}
|
|
69
|
+
implementedBy[node.name.value].push(astNode.name.value);
|
|
70
|
+
});
|
|
42
71
|
definitions.push(createObjectType(astNode));
|
|
72
|
+
addToSetArray(supermassiveImports, SUPERMASSIVE_TYPES.OBJECT_TYPE_RESOLVER);
|
|
43
73
|
addToSetArray(identifiers, astNode.name.value);
|
|
44
74
|
}
|
|
45
75
|
}
|
|
46
|
-
|
|
76
|
+
interfaceAstNodes.forEach((astNode) => {
|
|
77
|
+
if (!implementedBy[astNode.name.value]) {
|
|
78
|
+
implementedBy[astNode.name.value] = [];
|
|
79
|
+
}
|
|
80
|
+
definitions.push(createInterfaceType(astNode, implementedBy[astNode.name.value]));
|
|
81
|
+
});
|
|
82
|
+
const graphQLImportDefinition = factory.createImportDeclaration(void 0, void 0, factory.createImportClause(false, void 0, factory.createNamedImports(graphQLImports.map((imp) => factory.createImportSpecifier(void 0, factory.createIdentifier(imp))))), factory.createStringLiteral("graphql"));
|
|
83
|
+
const supermassiveImportDefinition = factory.createImportDeclaration(void 0, void 0, factory.createImportClause(false, void 0, factory.createNamedImports(supermassiveImports.map((imp) => factory.createImportSpecifier(void 0, factory.createIdentifier(imp))))), factory.createStringLiteral("@graphitation/supermassive"));
|
|
47
84
|
const exportDefinition = factory.createVariableStatement([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([
|
|
48
|
-
factory.createVariableDeclaration(factory.createIdentifier("resolvers"), void 0, void 0, factory.createObjectLiteralExpression(identifiers.map((def) => factory.createShorthandPropertyAssignment(factory.createIdentifier(def), void 0))))
|
|
85
|
+
factory.createVariableDeclaration(factory.createIdentifier("resolvers"), void 0, factory.createTypeReferenceNode(factory.createIdentifier("Resolvers"), void 0), factory.createObjectLiteralExpression(identifiers.map((def) => factory.createShorthandPropertyAssignment(factory.createIdentifier(def), void 0))))
|
|
49
86
|
], ts.NodeFlags.Const));
|
|
50
|
-
return factory.createSourceFile([
|
|
87
|
+
return factory.createSourceFile([
|
|
88
|
+
graphQLImportDefinition,
|
|
89
|
+
supermassiveImportDefinition,
|
|
90
|
+
...definitions,
|
|
91
|
+
exportDefinition
|
|
92
|
+
], factory.createToken(ts.SyntaxKind.EndOfFileToken), 0);
|
|
51
93
|
}
|
|
52
|
-
function createDeclaration(name, decl) {
|
|
94
|
+
function createDeclaration(name, decl, typeReferenceNode) {
|
|
53
95
|
return factory.createVariableStatement(void 0, factory.createVariableDeclarationList([
|
|
54
|
-
factory.createVariableDeclaration(factory.createIdentifier(name), void 0,
|
|
96
|
+
factory.createVariableDeclaration(factory.createIdentifier(name), void 0, typeReferenceNode, decl)
|
|
55
97
|
], ts.NodeFlags.Const));
|
|
56
98
|
}
|
|
57
99
|
function createScalarType(astNode) {
|
|
@@ -61,7 +103,7 @@ function createScalarType(astNode) {
|
|
|
61
103
|
factory.createPropertyAssignment(factory.createIdentifier("name"), factory.createStringLiteral(astNode.name.value)),
|
|
62
104
|
factory.createPropertyAssignment(factory.createIdentifier("description"), factory.createStringLiteral(((_a = astNode.description) == null ? void 0 : _a.value) || ""))
|
|
63
105
|
], true)
|
|
64
|
-
]));
|
|
106
|
+
]), factory.createTypeReferenceNode(factory.createIdentifier(SUPERMASSIVE_TYPES.SCALAR_TYPE_RESOLVER), void 0));
|
|
65
107
|
}
|
|
66
108
|
function createInputObjectType(astNode) {
|
|
67
109
|
var _a;
|
|
@@ -71,7 +113,7 @@ function createInputObjectType(astNode) {
|
|
|
71
113
|
factory.createPropertyAssignment(factory.createIdentifier("description"), factory.createStringLiteral(((_a = astNode.description) == null ? void 0 : _a.value) || "")),
|
|
72
114
|
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))))
|
|
73
115
|
], true)
|
|
74
|
-
]));
|
|
116
|
+
]), factory.createTypeReferenceNode(factory.createIdentifier(SUPERMASSIVE_TYPES.INPUT_OBJECT_TYPE_RESOLVER), void 0));
|
|
75
117
|
}
|
|
76
118
|
function createInputFields(astNodes) {
|
|
77
119
|
return astNodes.map((astNode) => {
|
|
@@ -99,15 +141,22 @@ function createEnumType(astNode) {
|
|
|
99
141
|
]));
|
|
100
142
|
})))
|
|
101
143
|
])
|
|
102
|
-
]));
|
|
144
|
+
]), factory.createTypeReferenceNode(factory.createIdentifier(SUPERMASSIVE_TYPES.ENUM_TYPE_RESOLVER), void 0));
|
|
145
|
+
}
|
|
146
|
+
function createUnionType(astNode, types) {
|
|
147
|
+
return createDeclaration(astNode.name.value, factory.createObjectLiteralExpression([
|
|
148
|
+
factory.createPropertyAssignment(factory.createIdentifier("__types"), factory.createArrayLiteralExpression(types.map((value) => factory.createStringLiteral(value)))),
|
|
149
|
+
factory.createPropertyAssignment(factory.createIdentifier("__resolveType"), factory.createIdentifier("undefined"))
|
|
150
|
+
]), factory.createTypeReferenceNode(factory.createIdentifier(SUPERMASSIVE_TYPES.UNION_TYPE_RESOLVER), void 0));
|
|
103
151
|
}
|
|
104
|
-
function
|
|
152
|
+
function createInterfaceType(astNode, implementedBy) {
|
|
105
153
|
return createDeclaration(astNode.name.value, factory.createObjectLiteralExpression([
|
|
154
|
+
factory.createPropertyAssignment(factory.createIdentifier("__implementedBy"), factory.createArrayLiteralExpression(implementedBy.map((value) => factory.createStringLiteral(value)))),
|
|
106
155
|
factory.createPropertyAssignment(factory.createIdentifier("__resolveType"), factory.createIdentifier("undefined"))
|
|
107
|
-
]));
|
|
156
|
+
]), factory.createTypeReferenceNode(factory.createIdentifier(SUPERMASSIVE_TYPES.INTERFACE_TYPE_RESOLVER), void 0));
|
|
108
157
|
}
|
|
109
158
|
function createObjectType(astNode) {
|
|
110
|
-
return createDeclaration(astNode.name.value, factory.createObjectLiteralExpression());
|
|
159
|
+
return createDeclaration(astNode.name.value, factory.createObjectLiteralExpression(), factory.createTypeReferenceNode(factory.createIdentifier(SUPERMASSIVE_TYPES.OBJECT_TYPE_RESOLVER), void 0));
|
|
111
160
|
}
|
|
112
161
|
function createType(astNode) {
|
|
113
162
|
if (astNode.kind === Kind.LIST_TYPE) {
|
package/lib/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { executeWithoutSchema } from "./executeWithoutSchema";
|
|
|
2
2
|
export { executeWithSchema } from "./executeWithSchema";
|
|
3
3
|
export { subscribeWithSchema } from "./subscribeWithSchema";
|
|
4
4
|
export { subscribeWithoutSchema } from "./subscribeWithoutSchema";
|
|
5
|
-
export type { Resolvers } from "./types";
|
|
5
|
+
export type { ObjectTypeResolver, InterfaceTypeResolver, UnionTypeResolver, ScalarTypeResolver, EnumTypeResolver, InputObjectTypeResolver, Resolvers, } from "./types";
|
|
6
6
|
export { addTypesToRequestDocument } from "./ast/addTypesToRequestDocument";
|
|
7
7
|
export { extractImplicitTypes } from "./extractImplicitTypesRuntime";
|
|
8
8
|
export { specifiedScalars } from "./values";
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,YAAY,EACV,kBAAkB,EAClB,qBAAqB,EACrB,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,uBAAuB,EACvB,SAAS,GACV,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAE5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAErE,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C,OAAO,EAAE,gCAAgC,EAAE,MAAM,+CAA+C,CAAC;AAEjG,YAAY,EACV,QAAQ,EACR,YAAY,EACZ,uBAAuB,EACvB,sBAAsB,EACtB,YAAY,EACZ,gBAAgB,EAChB,SAAS,EACT,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,EACtB,YAAY,EACZ,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,aAAa,EACb,eAAe,EACf,eAAe,EACf,aAAa,EACb,aAAa,EACb,YAAY,EACZ,eAAe,EACf,oBAAoB,EACpB,2BAA2B,EAC3B,wBAAwB,EACxB,wBAAwB,EACxB,mBAAmB,EACnB,wBAAwB,EACxB,2BAA2B,EAC3B,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACvB,6BAA6B,EAC7B,uBAAuB,EACvB,mBAAmB,EACnB,uBAAuB,EACvB,uBAAuB,EACvB,0BAA0B,EAC1B,sBAAsB,EACtB,qBAAqB,EACrB,4BAA4B,GAC7B,MAAM,gBAAgB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscribeWithSchema.d.ts","sourceRoot":"","sources":["../src/subscribeWithSchema.ts"],"names":[],"mappings":"AAQA,OAAO,EAAa,eAAe,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAE9E,wBAAgB,mBAAmB,CAAC,EAClC,QAAQ,EACR,SAAS,EACT,QAAQ,EAAE,WAAW,EACrB,SAAS,EACT,YAAY,EACZ,cAAc,EACd,aAAa,EACb,aAAa,EACb,YAAY,GACb,EAAE,uBAAuB,GAAG,OAAO,CAClC,cAAc,CAAC,eAAe,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,eAAe,CAC9D,
|
|
1
|
+
{"version":3,"file":"subscribeWithSchema.d.ts","sourceRoot":"","sources":["../src/subscribeWithSchema.ts"],"names":[],"mappings":"AAQA,OAAO,EAAa,eAAe,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAE9E,wBAAgB,mBAAmB,CAAC,EAClC,QAAQ,EACR,SAAS,EACT,QAAQ,EAAE,WAAW,EACrB,SAAS,EACT,YAAY,EACZ,cAAc,EACd,aAAa,EACb,aAAa,EACb,YAAY,GACb,EAAE,uBAAuB,GAAG,OAAO,CAClC,cAAc,CAAC,eAAe,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,eAAe,CAC9D,CA0BA"}
|