@graphitation/supermassive 1.1.6 → 2.0.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.md +18 -2
- package/lib/index.d.ts +1 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +0 -2
- package/lib/index.mjs +0 -2
- package/package.json +11 -19
- package/bin/supermassive.js +0 -5
- package/lib/bin/supermassive.d.ts +0 -3
- package/lib/bin/supermassive.d.ts.map +0 -1
- package/lib/bin/supermassive.js +0 -133
- package/lib/bin/supermassive.mjs +0 -113
- package/lib/codegen/context/expect.d.ts +0 -1
- package/lib/codegen/context/expect.d.ts.map +0 -1
- package/lib/codegen/context/expect.js +0 -0
- package/lib/codegen/context/expect.mjs +0 -0
- package/lib/codegen/context/import.d.ts +0 -5
- package/lib/codegen/context/import.d.ts.map +0 -1
- package/lib/codegen/context/import.js +0 -55
- package/lib/codegen/context/import.mjs +0 -37
- package/lib/codegen/context/index.d.ts +0 -52
- package/lib/codegen/context/index.d.ts.map +0 -1
- package/lib/codegen/context/index.js +0 -253
- package/lib/codegen/context/index.mjs +0 -242
- package/lib/codegen/context/model.d.ts +0 -5
- package/lib/codegen/context/model.d.ts.map +0 -1
- package/lib/codegen/context/model.js +0 -53
- package/lib/codegen/context/model.mjs +0 -37
- package/lib/codegen/context/utilities.d.ts +0 -2
- package/lib/codegen/context/utilities.d.ts.map +0 -1
- package/lib/codegen/context/utilities.js +0 -26
- package/lib/codegen/context/utilities.mjs +0 -8
- package/lib/codegen/index.d.ts +0 -7
- package/lib/codegen/index.d.ts.map +0 -1
- package/lib/codegen/index.js +0 -41
- package/lib/codegen/index.mjs +0 -23
- package/lib/codegen/models.d.ts +0 -5
- package/lib/codegen/models.d.ts.map +0 -1
- package/lib/codegen/models.js +0 -159
- package/lib/codegen/models.mjs +0 -142
- package/lib/codegen/resolvers.d.ts +0 -5
- package/lib/codegen/resolvers.d.ts.map +0 -1
- package/lib/codegen/resolvers.js +0 -157
- package/lib/codegen/resolvers.mjs +0 -144
- package/lib/codegen/typedVisitor.d.ts +0 -57
- package/lib/codegen/typedVisitor.d.ts.map +0 -1
- package/lib/codegen/typedVisitor.js +0 -26
- package/lib/codegen/typedVisitor.mjs +0 -8
- package/lib/codegen/types.d.ts +0 -18
- package/lib/codegen/types.d.ts.map +0 -1
- package/lib/codegen/types.js +0 -15
- package/lib/codegen/types.mjs +0 -0
- package/lib/codegen/utilities.d.ts +0 -50
- package/lib/codegen/utilities.d.ts.map +0 -1
- package/lib/codegen/utilities.js +0 -193
- package/lib/codegen/utilities.mjs +0 -175
- package/lib/extractors/extractImplicitTypesToTypescript.d.ts +0 -4
- package/lib/extractors/extractImplicitTypesToTypescript.d.ts.map +0 -1
- package/lib/extractors/extractImplicitTypesToTypescript.js +0 -217
- package/lib/extractors/extractImplicitTypesToTypescript.mjs +0 -198
- package/lib/extractors/index.d.ts +0 -2
- package/lib/extractors/index.d.ts.map +0 -1
- package/lib/extractors/index.js +0 -23
- package/lib/extractors/index.mjs +0 -5
- package/lib/transforms/transformerTestUtils.d.ts +0 -79
- package/lib/transforms/transformerTestUtils.d.ts.map +0 -1
- package/lib/transforms/transformerTestUtils.js +0 -174
- package/lib/transforms/transformerTestUtils.mjs +0 -156
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var import_exports = {};
|
|
19
|
-
__export(import_exports, {
|
|
20
|
-
IMPORT_DIRECTIVE_NAME: () => IMPORT_DIRECTIVE_NAME,
|
|
21
|
-
processImportDirective: () => processImportDirective
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(import_exports);
|
|
24
|
-
var import_graphql = require("graphql");
|
|
25
|
-
var import_utilities = require("../utilities");
|
|
26
|
-
const IMPORT_DIRECTIVE_NAME = "import";
|
|
27
|
-
function processImportDirective(node) {
|
|
28
|
-
const from = getArgumentValue(node.arguments, "from");
|
|
29
|
-
const defs = getArgumentValue(node.arguments, "defs");
|
|
30
|
-
if ((from == null ? void 0 : from.kind) !== "StringValue") {
|
|
31
|
-
throw new import_graphql.GraphQLError(`Directive @import requires "from" argument to exist and be a path to a GraphQL file.`, [from != null ? from : node]);
|
|
32
|
-
}
|
|
33
|
-
if ((defs == null ? void 0 : defs.kind) !== "ListValue") {
|
|
34
|
-
throw new import_graphql.GraphQLError(`Directive @import requires "defs" argument to exist and be a list of strings.`, [defs != null ? defs : node]);
|
|
35
|
-
}
|
|
36
|
-
const definitionNames = [];
|
|
37
|
-
defs.values.forEach((valueNode) => {
|
|
38
|
-
if (valueNode.kind !== "StringValue") {
|
|
39
|
-
throw new import_graphql.GraphQLError(`Directive @import requires "defs" argument to exist and be a list of strings (got ${valueNode.kind}).`, [valueNode]);
|
|
40
|
-
}
|
|
41
|
-
definitionNames.push(valueNode.value);
|
|
42
|
-
});
|
|
43
|
-
return {
|
|
44
|
-
from: from.value,
|
|
45
|
-
defs: definitionNames.map((typeName) => ({
|
|
46
|
-
typeName
|
|
47
|
-
})),
|
|
48
|
-
importName: (0, import_utilities.createVariableNameFromImport)(from.value),
|
|
49
|
-
directive: node
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
const getArgumentValue = (args = [], name) => {
|
|
53
|
-
var _a;
|
|
54
|
-
return (_a = args.find((arg) => arg.name.value === name)) == null ? void 0 : _a.value;
|
|
55
|
-
};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
// src/codegen/context/import.ts
|
|
2
|
-
import { GraphQLError } from "graphql";
|
|
3
|
-
import { createVariableNameFromImport } from "../utilities.mjs";
|
|
4
|
-
var IMPORT_DIRECTIVE_NAME = "import";
|
|
5
|
-
function processImportDirective(node) {
|
|
6
|
-
const from = getArgumentValue(node.arguments, "from");
|
|
7
|
-
const defs = getArgumentValue(node.arguments, "defs");
|
|
8
|
-
if ((from == null ? void 0 : from.kind) !== "StringValue") {
|
|
9
|
-
throw new GraphQLError(`Directive @import requires "from" argument to exist and be a path to a GraphQL file.`, [from != null ? from : node]);
|
|
10
|
-
}
|
|
11
|
-
if ((defs == null ? void 0 : defs.kind) !== "ListValue") {
|
|
12
|
-
throw new GraphQLError(`Directive @import requires "defs" argument to exist and be a list of strings.`, [defs != null ? defs : node]);
|
|
13
|
-
}
|
|
14
|
-
const definitionNames = [];
|
|
15
|
-
defs.values.forEach((valueNode) => {
|
|
16
|
-
if (valueNode.kind !== "StringValue") {
|
|
17
|
-
throw new GraphQLError(`Directive @import requires "defs" argument to exist and be a list of strings (got ${valueNode.kind}).`, [valueNode]);
|
|
18
|
-
}
|
|
19
|
-
definitionNames.push(valueNode.value);
|
|
20
|
-
});
|
|
21
|
-
return {
|
|
22
|
-
from: from.value,
|
|
23
|
-
defs: definitionNames.map((typeName) => ({
|
|
24
|
-
typeName
|
|
25
|
-
})),
|
|
26
|
-
importName: createVariableNameFromImport(from.value),
|
|
27
|
-
directive: node
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
var getArgumentValue = (args = [], name) => {
|
|
31
|
-
var _a;
|
|
32
|
-
return (_a = args.find((arg) => arg.name.value === name)) == null ? void 0 : _a.value;
|
|
33
|
-
};
|
|
34
|
-
export {
|
|
35
|
-
IMPORT_DIRECTIVE_NAME,
|
|
36
|
-
processImportDirective
|
|
37
|
-
};
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { DocumentNode, ASTNode } from "graphql";
|
|
2
|
-
import ts from "typescript";
|
|
3
|
-
import { DefinitionImport, DefinitionModel } from "../types";
|
|
4
|
-
export declare type TsCodegenContextOptions = {
|
|
5
|
-
moduleRoot: string;
|
|
6
|
-
moduleModelsPath: string;
|
|
7
|
-
moduleResolversPath: string;
|
|
8
|
-
baseModel: {
|
|
9
|
-
name: string;
|
|
10
|
-
from: string | null;
|
|
11
|
-
};
|
|
12
|
-
context: {
|
|
13
|
-
name?: string;
|
|
14
|
-
from: string | null;
|
|
15
|
-
};
|
|
16
|
-
resolveInfo: {
|
|
17
|
-
name: string;
|
|
18
|
-
from: string | null;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
export declare const BUILT_IN_SCALARS: Record<string, string>;
|
|
22
|
-
export declare class TsCodegenContext {
|
|
23
|
-
private options;
|
|
24
|
-
private imports;
|
|
25
|
-
private typeNameToImports;
|
|
26
|
-
private typeNameToModels;
|
|
27
|
-
private allModelNames;
|
|
28
|
-
private allPossibleModels;
|
|
29
|
-
constructor(options: TsCodegenContextOptions);
|
|
30
|
-
addImport(imp: DefinitionImport, node: ASTNode): void;
|
|
31
|
-
addPossibleModel(possibleModel: string): void;
|
|
32
|
-
addModel(model: DefinitionModel, node: ASTNode): void;
|
|
33
|
-
getAllImportDeclarations(): ts.ImportDeclaration[];
|
|
34
|
-
getAllModelImportDeclarations(): ts.ImportDeclaration[];
|
|
35
|
-
getScalarDeclaration(scalarName: string | null): ts.TypeAliasDeclaration | undefined;
|
|
36
|
-
getAllResolverImportDeclarations(): ts.ImportDeclaration[];
|
|
37
|
-
getBaseModelType(): TypeLocation;
|
|
38
|
-
getContextType(): TypeLocation;
|
|
39
|
-
getResolveInfoType(): TypeLocation;
|
|
40
|
-
getDefaultTypes(): ts.InterfaceDeclaration[];
|
|
41
|
-
getModelType(typeName: string, useScalars?: boolean): TypeLocation;
|
|
42
|
-
getDefinedModelType(typeName: string): TypeLocation | null;
|
|
43
|
-
}
|
|
44
|
-
export declare function extractContext(options: Partial<TsCodegenContextOptions>, document: DocumentNode): TsCodegenContext;
|
|
45
|
-
export declare class TypeLocation {
|
|
46
|
-
private from;
|
|
47
|
-
private name;
|
|
48
|
-
constructor(from: string | null, name: string);
|
|
49
|
-
toTypeReference(): ts.TypeReferenceNode;
|
|
50
|
-
toExpression(): ts.Expression;
|
|
51
|
-
}
|
|
52
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/codegen/context/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAKZ,OAAO,EACR,MAAM,SAAS,CAAC;AACjB,OAAO,EAIN,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAM7D,oBAAY,uBAAuB,GAAG;IACpC,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,EAAE,MAAM,CAAC;IACzB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,SAAS,EAAE;QACT,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;KACrB,CAAC;IACF,OAAO,EAAE;QACP,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;KACrB,CAAC;IACF,WAAW,EAAE;QACX,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;KACrB,CAAC;CACH,CAAC;AAIF,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAMnD,CAAC;AAsBF,qBAAa,gBAAgB;IAUf,OAAO,CAAC,OAAO;IAT3B,OAAO,CAAC,OAAO,CAAqB;IACpC,OAAO,CAAC,iBAAiB,CAGvB;IACF,OAAO,CAAC,gBAAgB,CAA+B;IACvD,OAAO,CAAC,aAAa,CAAc;IACnC,OAAO,CAAC,iBAAiB,CAAc;gBAEnB,OAAO,EAAE,uBAAuB;IAQpD,SAAS,CAAC,GAAG,EAAE,gBAAgB,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI;IAyBrD,gBAAgB,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI;IAI7C,QAAQ,CAAC,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI;IAcrD,wBAAwB,IAAI,EAAE,CAAC,iBAAiB,EAAE;IASlD,6BAA6B,IAAI,EAAE,CAAC,iBAAiB,EAAE;IAmBvD,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IA2B9C,gCAAgC,IAAI,EAAE,CAAC,iBAAiB,EAAE;IAmC1D,gBAAgB,IAAI,YAAY;IAIhC,cAAc,IAAI,YAAY;IAQ9B,kBAAkB,IAAI,YAAY;IAIlC,eAAe;IAyBf,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,UAAQ,GAAG,YAAY;IAoBhE,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI;CAQ3D;AAED,wBAAgB,cAAc,CAC5B,OAAO,EAAE,OAAO,CAAC,uBAAuB,CAAC,EACzC,QAAQ,EAAE,YAAY,GACrB,gBAAgB,CA6ClB;AAED,qBAAa,YAAY;IACX,OAAO,CAAC,IAAI;IAAiB,OAAO,CAAC,IAAI;gBAAjC,IAAI,EAAE,MAAM,GAAG,IAAI,EAAU,IAAI,EAAE,MAAM;IAE7D,eAAe,IAAI,EAAE,CAAC,iBAAiB;IAavC,YAAY,IAAI,EAAE,CAAC,UAAU;CAU9B"}
|
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
-
var __spreadValues = (a, b) => {
|
|
11
|
-
for (var prop in b || (b = {}))
|
|
12
|
-
if (__hasOwnProp.call(b, prop))
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
if (__getOwnPropSymbols)
|
|
15
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
-
if (__propIsEnum.call(b, prop))
|
|
17
|
-
__defNormalProp(a, prop, b[prop]);
|
|
18
|
-
}
|
|
19
|
-
return a;
|
|
20
|
-
};
|
|
21
|
-
var __export = (target, all) => {
|
|
22
|
-
for (var name in all)
|
|
23
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
24
|
-
};
|
|
25
|
-
var __copyProps = (to, from, except, desc) => {
|
|
26
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
27
|
-
for (let key of __getOwnPropNames(from))
|
|
28
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
29
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
30
|
-
}
|
|
31
|
-
return to;
|
|
32
|
-
};
|
|
33
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
34
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
35
|
-
var context_exports = {};
|
|
36
|
-
__export(context_exports, {
|
|
37
|
-
BUILT_IN_SCALARS: () => BUILT_IN_SCALARS,
|
|
38
|
-
TsCodegenContext: () => TsCodegenContext,
|
|
39
|
-
TypeLocation: () => TypeLocation,
|
|
40
|
-
extractContext: () => extractContext
|
|
41
|
-
});
|
|
42
|
-
module.exports = __toCommonJS(context_exports);
|
|
43
|
-
var import_graphql = require("graphql");
|
|
44
|
-
var import_typescript = __toESM(require("typescript"));
|
|
45
|
-
var import_utilities = require("./utilities");
|
|
46
|
-
var import_utilities2 = require("../utilities");
|
|
47
|
-
var import_import = require("./import");
|
|
48
|
-
var import_model = require("./model");
|
|
49
|
-
const DEFAULT_SCALAR_TYPE = "unknown";
|
|
50
|
-
const BUILT_IN_SCALARS = {
|
|
51
|
-
ID: "string",
|
|
52
|
-
Int: "number",
|
|
53
|
-
Float: "number",
|
|
54
|
-
String: "string",
|
|
55
|
-
Boolean: "boolean"
|
|
56
|
-
};
|
|
57
|
-
const TsCodegenContextDefault = {
|
|
58
|
-
moduleRoot: "",
|
|
59
|
-
moduleModelsPath: "./__generated__/models.interface.ts",
|
|
60
|
-
moduleResolversPath: "./__generated__/resolvers.interface.ts",
|
|
61
|
-
baseModel: {
|
|
62
|
-
name: "BaseModel",
|
|
63
|
-
from: null
|
|
64
|
-
},
|
|
65
|
-
context: {
|
|
66
|
-
name: "unknown",
|
|
67
|
-
from: null
|
|
68
|
-
},
|
|
69
|
-
resolveInfo: {
|
|
70
|
-
name: "ResolveInfo",
|
|
71
|
-
from: "@graphitation/supermassive"
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
class TsCodegenContext {
|
|
75
|
-
constructor(options) {
|
|
76
|
-
this.options = options;
|
|
77
|
-
this.imports = [];
|
|
78
|
-
this.typeNameToImports = /* @__PURE__ */ new Map();
|
|
79
|
-
this.typeNameToModels = /* @__PURE__ */ new Map();
|
|
80
|
-
this.allModelNames = /* @__PURE__ */ new Set();
|
|
81
|
-
this.allPossibleModels = /* @__PURE__ */ new Set();
|
|
82
|
-
}
|
|
83
|
-
addImport(imp, node) {
|
|
84
|
-
var _a;
|
|
85
|
-
for (const { typeName } of imp.defs) {
|
|
86
|
-
const { imp: existingImport } = this.typeNameToImports.get(typeName) || {};
|
|
87
|
-
if (existingImport) {
|
|
88
|
-
throw new import_graphql.GraphQLError(`Definition ${typeName} is imported multiple times: ${existingImport.from}`, [
|
|
89
|
-
(_a = getArgumentValue(existingImport.directive.arguments, "from")) != null ? _a : existingImport.directive,
|
|
90
|
-
imp.directive,
|
|
91
|
-
node
|
|
92
|
-
]);
|
|
93
|
-
}
|
|
94
|
-
this.typeNameToImports.set(typeName, {
|
|
95
|
-
modelName: (0, import_utilities2.addModelSuffix)(typeName),
|
|
96
|
-
imp
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
this.imports.push(imp);
|
|
100
|
-
}
|
|
101
|
-
addPossibleModel(possibleModel) {
|
|
102
|
-
this.allPossibleModels.add(possibleModel);
|
|
103
|
-
}
|
|
104
|
-
addModel(model, node) {
|
|
105
|
-
const existingModel = this.typeNameToModels.get(model.typeName);
|
|
106
|
-
if (existingModel) {
|
|
107
|
-
throw new import_graphql.GraphQLError(`Model for type ${model.typeName} is defined multiple times`, [existingModel.directive, node]);
|
|
108
|
-
}
|
|
109
|
-
this.typeNameToModels.set(model.typeName, model);
|
|
110
|
-
}
|
|
111
|
-
getAllImportDeclarations() {
|
|
112
|
-
return this.imports.map(({ defs, from }) => (0, import_utilities.createImportDeclaration)(defs.map(({ typeName }) => (0, import_utilities2.addModelSuffix)(typeName)), from));
|
|
113
|
-
}
|
|
114
|
-
getAllModelImportDeclarations() {
|
|
115
|
-
const imports = this.getAllImportDeclarations();
|
|
116
|
-
const models = Array.from(this.typeNameToModels.values()).map((model) => {
|
|
117
|
-
if (!model.from) {
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
return (0, import_utilities.createImportDeclaration)([model.modelName], model.from, model.tsType !== model.modelName ? model.tsType : void 0);
|
|
121
|
-
}).filter(Boolean);
|
|
122
|
-
return imports.concat(models);
|
|
123
|
-
}
|
|
124
|
-
getScalarDeclaration(scalarName) {
|
|
125
|
-
if (!scalarName || BUILT_IN_SCALARS.hasOwnProperty(scalarName)) {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
let model;
|
|
129
|
-
if (this.typeNameToModels.has(scalarName)) {
|
|
130
|
-
const { from, modelName, tsType } = this.typeNameToModels.get(scalarName);
|
|
131
|
-
model = from ? modelName : tsType;
|
|
132
|
-
} else {
|
|
133
|
-
model = DEFAULT_SCALAR_TYPE;
|
|
134
|
-
}
|
|
135
|
-
return import_typescript.factory.createTypeAliasDeclaration(void 0, [import_typescript.factory.createModifier(import_typescript.default.SyntaxKind.ExportKeyword)], import_typescript.factory.createIdentifier((0, import_utilities2.addModelSuffix)(scalarName)), void 0, import_typescript.factory.createTypeReferenceNode(import_typescript.factory.createIdentifier(model), void 0));
|
|
136
|
-
}
|
|
137
|
-
getAllResolverImportDeclarations() {
|
|
138
|
-
const imports = [];
|
|
139
|
-
imports.push((0, import_utilities.createImportDeclaration)(["PromiseOrValue"], "@graphitation/supermassive"));
|
|
140
|
-
if (this.options.resolveInfo.from) {
|
|
141
|
-
imports.push((0, import_utilities.createImportDeclaration)([this.options.resolveInfo.name], this.options.resolveInfo.from));
|
|
142
|
-
}
|
|
143
|
-
if (this.options.context.from && this.options.context.name) {
|
|
144
|
-
imports.push((0, import_utilities.createImportDeclaration)([this.options.context.name], this.options.context.from));
|
|
145
|
-
}
|
|
146
|
-
imports.push((0, import_utilities.createImportDeclaration)(Array.from(this.allModelNames), "./models.interface"));
|
|
147
|
-
imports.push(...this.getAllImportDeclarations());
|
|
148
|
-
return imports;
|
|
149
|
-
}
|
|
150
|
-
getBaseModelType() {
|
|
151
|
-
return new TypeLocation(null, this.options.baseModel.name);
|
|
152
|
-
}
|
|
153
|
-
getContextType() {
|
|
154
|
-
return new TypeLocation(null, this.options.context.name || TsCodegenContextDefault.context.name);
|
|
155
|
-
}
|
|
156
|
-
getResolveInfoType() {
|
|
157
|
-
return new TypeLocation(null, this.options.resolveInfo.name);
|
|
158
|
-
}
|
|
159
|
-
getDefaultTypes() {
|
|
160
|
-
return [
|
|
161
|
-
(0, import_typescript.addSyntheticLeadingComment)(import_typescript.factory.createInterfaceDeclaration(void 0, [import_typescript.factory.createModifier(import_typescript.default.SyntaxKind.ExportKeyword)], import_typescript.factory.createIdentifier("BaseModel"), void 0, void 0, [
|
|
162
|
-
import_typescript.factory.createPropertySignature(void 0, import_typescript.factory.createIdentifier("__typename"), void 0, import_typescript.factory.createKeywordTypeNode(import_typescript.default.SyntaxKind.StringKeyword))
|
|
163
|
-
]), import_typescript.SyntaxKind.SingleLineCommentTrivia, " Base type for all models. Enables automatic resolution of abstract GraphQL types (interfaces, unions)", true)
|
|
164
|
-
];
|
|
165
|
-
}
|
|
166
|
-
getModelType(typeName, useScalars = false) {
|
|
167
|
-
if (BUILT_IN_SCALARS.hasOwnProperty(typeName)) {
|
|
168
|
-
return new TypeLocation(null, BUILT_IN_SCALARS[typeName]);
|
|
169
|
-
} else if (this.typeNameToImports.has(typeName)) {
|
|
170
|
-
let { modelName } = this.typeNameToImports.get(typeName);
|
|
171
|
-
return new TypeLocation(null, modelName);
|
|
172
|
-
} else {
|
|
173
|
-
const modelName = this.allPossibleModels.has(typeName) ? (0, import_utilities2.addModelSuffix)(typeName) : typeName;
|
|
174
|
-
if (this.allPossibleModels.has(typeName)) {
|
|
175
|
-
this.allModelNames.add(modelName);
|
|
176
|
-
}
|
|
177
|
-
return new TypeLocation(null, modelName);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
getDefinedModelType(typeName) {
|
|
181
|
-
if (this.typeNameToModels.has(typeName)) {
|
|
182
|
-
let imp = this.typeNameToModels.get(typeName);
|
|
183
|
-
return new TypeLocation(null, imp.modelName);
|
|
184
|
-
} else {
|
|
185
|
-
return null;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
function extractContext(options, document) {
|
|
190
|
-
const fullOptions = __spreadValues(__spreadValues({}, TsCodegenContextDefault), options);
|
|
191
|
-
let context = new TsCodegenContext(fullOptions);
|
|
192
|
-
(0, import_graphql.visit)(document, {
|
|
193
|
-
Directive: {
|
|
194
|
-
enter(node, _key, _parent, _path, ancestors) {
|
|
195
|
-
if (node.name.value === import_import.IMPORT_DIRECTIVE_NAME) {
|
|
196
|
-
context.addImport((0, import_import.processImportDirective)(node), node);
|
|
197
|
-
} else if (node.name.value === import_model.MODEL_DIRECTIVE_NAME) {
|
|
198
|
-
context.addModel((0, import_model.processModelDirective)(node, ancestors), node);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
},
|
|
202
|
-
EnumTypeDefinition: {
|
|
203
|
-
enter(node) {
|
|
204
|
-
context.addPossibleModel(node.name.value);
|
|
205
|
-
}
|
|
206
|
-
},
|
|
207
|
-
ObjectTypeDefinition: {
|
|
208
|
-
enter(node) {
|
|
209
|
-
context.addPossibleModel(node.name.value);
|
|
210
|
-
}
|
|
211
|
-
},
|
|
212
|
-
UnionTypeDefinition: {
|
|
213
|
-
enter(node) {
|
|
214
|
-
context.addPossibleModel(node.name.value);
|
|
215
|
-
}
|
|
216
|
-
},
|
|
217
|
-
ScalarTypeDefinition: {
|
|
218
|
-
enter(node) {
|
|
219
|
-
context.addPossibleModel(node.name.value);
|
|
220
|
-
}
|
|
221
|
-
},
|
|
222
|
-
InterfaceTypeDefinition: {
|
|
223
|
-
enter(node) {
|
|
224
|
-
context.addPossibleModel(node.name.value);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
return context;
|
|
229
|
-
}
|
|
230
|
-
class TypeLocation {
|
|
231
|
-
constructor(from, name) {
|
|
232
|
-
this.from = from;
|
|
233
|
-
this.name = name;
|
|
234
|
-
}
|
|
235
|
-
toTypeReference() {
|
|
236
|
-
if (this.from != null) {
|
|
237
|
-
return import_typescript.factory.createTypeReferenceNode(import_typescript.factory.createQualifiedName(import_typescript.factory.createIdentifier(this.from), import_typescript.factory.createIdentifier(this.name)));
|
|
238
|
-
} else {
|
|
239
|
-
return import_typescript.factory.createTypeReferenceNode(this.name);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
toExpression() {
|
|
243
|
-
if (this.from != null) {
|
|
244
|
-
return import_typescript.factory.createPropertyAccessExpression(import_typescript.factory.createIdentifier(this.from), import_typescript.factory.createIdentifier(this.name));
|
|
245
|
-
} else {
|
|
246
|
-
return import_typescript.factory.createIdentifier(this.name);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
const getArgumentValue = (args = [], name) => {
|
|
251
|
-
var _a;
|
|
252
|
-
return (_a = args.find((arg) => arg.name.value === name)) == null ? void 0 : _a.value;
|
|
253
|
-
};
|
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
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 __spreadValues = (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
|
-
// src/codegen/context/index.ts
|
|
19
|
-
import {
|
|
20
|
-
GraphQLError,
|
|
21
|
-
visit
|
|
22
|
-
} from "graphql";
|
|
23
|
-
import ts, {
|
|
24
|
-
factory,
|
|
25
|
-
addSyntheticLeadingComment,
|
|
26
|
-
SyntaxKind
|
|
27
|
-
} from "typescript";
|
|
28
|
-
import { createImportDeclaration } from "./utilities.mjs";
|
|
29
|
-
import { addModelSuffix } from "../utilities.mjs";
|
|
30
|
-
import { IMPORT_DIRECTIVE_NAME, processImportDirective } from "./import.mjs";
|
|
31
|
-
import { MODEL_DIRECTIVE_NAME, processModelDirective } from "./model.mjs";
|
|
32
|
-
var DEFAULT_SCALAR_TYPE = "unknown";
|
|
33
|
-
var BUILT_IN_SCALARS = {
|
|
34
|
-
ID: "string",
|
|
35
|
-
Int: "number",
|
|
36
|
-
Float: "number",
|
|
37
|
-
String: "string",
|
|
38
|
-
Boolean: "boolean"
|
|
39
|
-
};
|
|
40
|
-
var TsCodegenContextDefault = {
|
|
41
|
-
moduleRoot: "",
|
|
42
|
-
moduleModelsPath: "./__generated__/models.interface.ts",
|
|
43
|
-
moduleResolversPath: "./__generated__/resolvers.interface.ts",
|
|
44
|
-
baseModel: {
|
|
45
|
-
name: "BaseModel",
|
|
46
|
-
from: null
|
|
47
|
-
},
|
|
48
|
-
context: {
|
|
49
|
-
name: "unknown",
|
|
50
|
-
from: null
|
|
51
|
-
},
|
|
52
|
-
resolveInfo: {
|
|
53
|
-
name: "ResolveInfo",
|
|
54
|
-
from: "@graphitation/supermassive"
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
var TsCodegenContext = class {
|
|
58
|
-
constructor(options) {
|
|
59
|
-
this.options = options;
|
|
60
|
-
this.imports = [];
|
|
61
|
-
this.typeNameToImports = /* @__PURE__ */ new Map();
|
|
62
|
-
this.typeNameToModels = /* @__PURE__ */ new Map();
|
|
63
|
-
this.allModelNames = /* @__PURE__ */ new Set();
|
|
64
|
-
this.allPossibleModels = /* @__PURE__ */ new Set();
|
|
65
|
-
}
|
|
66
|
-
addImport(imp, node) {
|
|
67
|
-
var _a;
|
|
68
|
-
for (const { typeName } of imp.defs) {
|
|
69
|
-
const { imp: existingImport } = this.typeNameToImports.get(typeName) || {};
|
|
70
|
-
if (existingImport) {
|
|
71
|
-
throw new GraphQLError(`Definition ${typeName} is imported multiple times: ${existingImport.from}`, [
|
|
72
|
-
(_a = getArgumentValue(existingImport.directive.arguments, "from")) != null ? _a : existingImport.directive,
|
|
73
|
-
imp.directive,
|
|
74
|
-
node
|
|
75
|
-
]);
|
|
76
|
-
}
|
|
77
|
-
this.typeNameToImports.set(typeName, {
|
|
78
|
-
modelName: addModelSuffix(typeName),
|
|
79
|
-
imp
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
this.imports.push(imp);
|
|
83
|
-
}
|
|
84
|
-
addPossibleModel(possibleModel) {
|
|
85
|
-
this.allPossibleModels.add(possibleModel);
|
|
86
|
-
}
|
|
87
|
-
addModel(model, node) {
|
|
88
|
-
const existingModel = this.typeNameToModels.get(model.typeName);
|
|
89
|
-
if (existingModel) {
|
|
90
|
-
throw new GraphQLError(`Model for type ${model.typeName} is defined multiple times`, [existingModel.directive, node]);
|
|
91
|
-
}
|
|
92
|
-
this.typeNameToModels.set(model.typeName, model);
|
|
93
|
-
}
|
|
94
|
-
getAllImportDeclarations() {
|
|
95
|
-
return this.imports.map(({ defs, from }) => createImportDeclaration(defs.map(({ typeName }) => addModelSuffix(typeName)), from));
|
|
96
|
-
}
|
|
97
|
-
getAllModelImportDeclarations() {
|
|
98
|
-
const imports = this.getAllImportDeclarations();
|
|
99
|
-
const models = Array.from(this.typeNameToModels.values()).map((model) => {
|
|
100
|
-
if (!model.from) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
return createImportDeclaration([model.modelName], model.from, model.tsType !== model.modelName ? model.tsType : void 0);
|
|
104
|
-
}).filter(Boolean);
|
|
105
|
-
return imports.concat(models);
|
|
106
|
-
}
|
|
107
|
-
getScalarDeclaration(scalarName) {
|
|
108
|
-
if (!scalarName || BUILT_IN_SCALARS.hasOwnProperty(scalarName)) {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
let model;
|
|
112
|
-
if (this.typeNameToModels.has(scalarName)) {
|
|
113
|
-
const { from, modelName, tsType } = this.typeNameToModels.get(scalarName);
|
|
114
|
-
model = from ? modelName : tsType;
|
|
115
|
-
} else {
|
|
116
|
-
model = DEFAULT_SCALAR_TYPE;
|
|
117
|
-
}
|
|
118
|
-
return factory.createTypeAliasDeclaration(void 0, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier(addModelSuffix(scalarName)), void 0, factory.createTypeReferenceNode(factory.createIdentifier(model), void 0));
|
|
119
|
-
}
|
|
120
|
-
getAllResolverImportDeclarations() {
|
|
121
|
-
const imports = [];
|
|
122
|
-
imports.push(createImportDeclaration(["PromiseOrValue"], "@graphitation/supermassive"));
|
|
123
|
-
if (this.options.resolveInfo.from) {
|
|
124
|
-
imports.push(createImportDeclaration([this.options.resolveInfo.name], this.options.resolveInfo.from));
|
|
125
|
-
}
|
|
126
|
-
if (this.options.context.from && this.options.context.name) {
|
|
127
|
-
imports.push(createImportDeclaration([this.options.context.name], this.options.context.from));
|
|
128
|
-
}
|
|
129
|
-
imports.push(createImportDeclaration(Array.from(this.allModelNames), "./models.interface"));
|
|
130
|
-
imports.push(...this.getAllImportDeclarations());
|
|
131
|
-
return imports;
|
|
132
|
-
}
|
|
133
|
-
getBaseModelType() {
|
|
134
|
-
return new TypeLocation(null, this.options.baseModel.name);
|
|
135
|
-
}
|
|
136
|
-
getContextType() {
|
|
137
|
-
return new TypeLocation(null, this.options.context.name || TsCodegenContextDefault.context.name);
|
|
138
|
-
}
|
|
139
|
-
getResolveInfoType() {
|
|
140
|
-
return new TypeLocation(null, this.options.resolveInfo.name);
|
|
141
|
-
}
|
|
142
|
-
getDefaultTypes() {
|
|
143
|
-
return [
|
|
144
|
-
addSyntheticLeadingComment(factory.createInterfaceDeclaration(void 0, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("BaseModel"), void 0, void 0, [
|
|
145
|
-
factory.createPropertySignature(void 0, factory.createIdentifier("__typename"), void 0, factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword))
|
|
146
|
-
]), SyntaxKind.SingleLineCommentTrivia, " Base type for all models. Enables automatic resolution of abstract GraphQL types (interfaces, unions)", true)
|
|
147
|
-
];
|
|
148
|
-
}
|
|
149
|
-
getModelType(typeName, useScalars = false) {
|
|
150
|
-
if (BUILT_IN_SCALARS.hasOwnProperty(typeName)) {
|
|
151
|
-
return new TypeLocation(null, BUILT_IN_SCALARS[typeName]);
|
|
152
|
-
} else if (this.typeNameToImports.has(typeName)) {
|
|
153
|
-
let { modelName } = this.typeNameToImports.get(typeName);
|
|
154
|
-
return new TypeLocation(null, modelName);
|
|
155
|
-
} else {
|
|
156
|
-
const modelName = this.allPossibleModels.has(typeName) ? addModelSuffix(typeName) : typeName;
|
|
157
|
-
if (this.allPossibleModels.has(typeName)) {
|
|
158
|
-
this.allModelNames.add(modelName);
|
|
159
|
-
}
|
|
160
|
-
return new TypeLocation(null, modelName);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
getDefinedModelType(typeName) {
|
|
164
|
-
if (this.typeNameToModels.has(typeName)) {
|
|
165
|
-
let imp = this.typeNameToModels.get(typeName);
|
|
166
|
-
return new TypeLocation(null, imp.modelName);
|
|
167
|
-
} else {
|
|
168
|
-
return null;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
function extractContext(options, document) {
|
|
173
|
-
const fullOptions = __spreadValues(__spreadValues({}, TsCodegenContextDefault), options);
|
|
174
|
-
let context = new TsCodegenContext(fullOptions);
|
|
175
|
-
visit(document, {
|
|
176
|
-
Directive: {
|
|
177
|
-
enter(node, _key, _parent, _path, ancestors) {
|
|
178
|
-
if (node.name.value === IMPORT_DIRECTIVE_NAME) {
|
|
179
|
-
context.addImport(processImportDirective(node), node);
|
|
180
|
-
} else if (node.name.value === MODEL_DIRECTIVE_NAME) {
|
|
181
|
-
context.addModel(processModelDirective(node, ancestors), node);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
},
|
|
185
|
-
EnumTypeDefinition: {
|
|
186
|
-
enter(node) {
|
|
187
|
-
context.addPossibleModel(node.name.value);
|
|
188
|
-
}
|
|
189
|
-
},
|
|
190
|
-
ObjectTypeDefinition: {
|
|
191
|
-
enter(node) {
|
|
192
|
-
context.addPossibleModel(node.name.value);
|
|
193
|
-
}
|
|
194
|
-
},
|
|
195
|
-
UnionTypeDefinition: {
|
|
196
|
-
enter(node) {
|
|
197
|
-
context.addPossibleModel(node.name.value);
|
|
198
|
-
}
|
|
199
|
-
},
|
|
200
|
-
ScalarTypeDefinition: {
|
|
201
|
-
enter(node) {
|
|
202
|
-
context.addPossibleModel(node.name.value);
|
|
203
|
-
}
|
|
204
|
-
},
|
|
205
|
-
InterfaceTypeDefinition: {
|
|
206
|
-
enter(node) {
|
|
207
|
-
context.addPossibleModel(node.name.value);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
return context;
|
|
212
|
-
}
|
|
213
|
-
var TypeLocation = class {
|
|
214
|
-
constructor(from, name) {
|
|
215
|
-
this.from = from;
|
|
216
|
-
this.name = name;
|
|
217
|
-
}
|
|
218
|
-
toTypeReference() {
|
|
219
|
-
if (this.from != null) {
|
|
220
|
-
return factory.createTypeReferenceNode(factory.createQualifiedName(factory.createIdentifier(this.from), factory.createIdentifier(this.name)));
|
|
221
|
-
} else {
|
|
222
|
-
return factory.createTypeReferenceNode(this.name);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
toExpression() {
|
|
226
|
-
if (this.from != null) {
|
|
227
|
-
return factory.createPropertyAccessExpression(factory.createIdentifier(this.from), factory.createIdentifier(this.name));
|
|
228
|
-
} else {
|
|
229
|
-
return factory.createIdentifier(this.name);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
};
|
|
233
|
-
var getArgumentValue = (args = [], name) => {
|
|
234
|
-
var _a;
|
|
235
|
-
return (_a = args.find((arg) => arg.name.value === name)) == null ? void 0 : _a.value;
|
|
236
|
-
};
|
|
237
|
-
export {
|
|
238
|
-
BUILT_IN_SCALARS,
|
|
239
|
-
TsCodegenContext,
|
|
240
|
-
TypeLocation,
|
|
241
|
-
extractContext
|
|
242
|
-
};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { ASTNode, DirectiveNode } from "graphql";
|
|
2
|
-
import { DefinitionModel } from "../types";
|
|
3
|
-
export declare const MODEL_DIRECTIVE_NAME = "model";
|
|
4
|
-
export declare function processModelDirective(node: DirectiveNode, ancestors: ReadonlyArray<ASTNode | ReadonlyArray<ASTNode>>): DefinitionModel;
|
|
5
|
-
//# sourceMappingURL=model.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/codegen/context/model.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,OAAO,EACP,aAAa,EAGd,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAG3C,eAAO,MAAM,oBAAoB,UAAU,CAAC;AAE5C,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,aAAa,EACnB,SAAS,EAAE,aAAa,CAAC,OAAO,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC,GACzD,eAAe,CAwCjB"}
|