@graphitation/supermassive 1.1.7 → 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 +10 -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,53 +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 model_exports = {};
|
|
19
|
-
__export(model_exports, {
|
|
20
|
-
MODEL_DIRECTIVE_NAME: () => MODEL_DIRECTIVE_NAME,
|
|
21
|
-
processModelDirective: () => processModelDirective
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(model_exports);
|
|
24
|
-
var import_graphql = require("graphql");
|
|
25
|
-
var import_utilities = require("../utilities");
|
|
26
|
-
const MODEL_DIRECTIVE_NAME = "model";
|
|
27
|
-
function processModelDirective(node, ancestors) {
|
|
28
|
-
const from = getArgumentValue(node.arguments, "from");
|
|
29
|
-
const tsType = getArgumentValue(node.arguments, "tsType");
|
|
30
|
-
if (from && from.kind !== "StringValue") {
|
|
31
|
-
throw new import_graphql.GraphQLError(`Directive @module requires "from" argument to exist and be a path to a typescript file.`, [from != null ? from : node]);
|
|
32
|
-
}
|
|
33
|
-
if ((tsType == null ? void 0 : tsType.kind) !== "StringValue") {
|
|
34
|
-
throw new import_graphql.GraphQLError(`Directive @model requires "tsType" argument to exist and be a name of the exported typescript type`, [tsType != null ? tsType : node]);
|
|
35
|
-
}
|
|
36
|
-
const typeDef = ancestors[ancestors.length - 1];
|
|
37
|
-
if (!typeDef || Array.isArray(typeDef) || typeDef.kind !== "ObjectTypeDefinition" && typeDef.kind !== "ScalarTypeDefinition") {
|
|
38
|
-
throw new import_graphql.GraphQLError("Directive @model must be defined on Object or Scalar type", [node]);
|
|
39
|
-
}
|
|
40
|
-
const typeName = typeDef.name.value;
|
|
41
|
-
return {
|
|
42
|
-
typeName,
|
|
43
|
-
modelName: `_${(0, import_utilities.addModelSuffix)(typeName)}`,
|
|
44
|
-
tsType: tsType.value,
|
|
45
|
-
importName: from ? (0, import_utilities.createVariableNameFromImport)(from.value) : null,
|
|
46
|
-
from: (from == null ? void 0 : from.value) || null,
|
|
47
|
-
directive: node
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
const getArgumentValue = (args = [], name) => {
|
|
51
|
-
var _a;
|
|
52
|
-
return (_a = args.find((arg) => arg.name.value === name)) == null ? void 0 : _a.value;
|
|
53
|
-
};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
// src/codegen/context/model.ts
|
|
2
|
-
import {
|
|
3
|
-
GraphQLError
|
|
4
|
-
} from "graphql";
|
|
5
|
-
import { createVariableNameFromImport, addModelSuffix } from "../utilities.mjs";
|
|
6
|
-
var MODEL_DIRECTIVE_NAME = "model";
|
|
7
|
-
function processModelDirective(node, ancestors) {
|
|
8
|
-
const from = getArgumentValue(node.arguments, "from");
|
|
9
|
-
const tsType = getArgumentValue(node.arguments, "tsType");
|
|
10
|
-
if (from && from.kind !== "StringValue") {
|
|
11
|
-
throw new GraphQLError(`Directive @module requires "from" argument to exist and be a path to a typescript file.`, [from != null ? from : node]);
|
|
12
|
-
}
|
|
13
|
-
if ((tsType == null ? void 0 : tsType.kind) !== "StringValue") {
|
|
14
|
-
throw new GraphQLError(`Directive @model requires "tsType" argument to exist and be a name of the exported typescript type`, [tsType != null ? tsType : node]);
|
|
15
|
-
}
|
|
16
|
-
const typeDef = ancestors[ancestors.length - 1];
|
|
17
|
-
if (!typeDef || Array.isArray(typeDef) || typeDef.kind !== "ObjectTypeDefinition" && typeDef.kind !== "ScalarTypeDefinition") {
|
|
18
|
-
throw new GraphQLError("Directive @model must be defined on Object or Scalar type", [node]);
|
|
19
|
-
}
|
|
20
|
-
const typeName = typeDef.name.value;
|
|
21
|
-
return {
|
|
22
|
-
typeName,
|
|
23
|
-
modelName: `_${addModelSuffix(typeName)}`,
|
|
24
|
-
tsType: tsType.value,
|
|
25
|
-
importName: from ? createVariableNameFromImport(from.value) : null,
|
|
26
|
-
from: (from == null ? void 0 : from.value) || null,
|
|
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
|
-
MODEL_DIRECTIVE_NAME,
|
|
36
|
-
processModelDirective
|
|
37
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../../../src/codegen/context/utilities.ts"],"names":[],"mappings":"AAEA,wBAAgB,uBAAuB,CACrC,WAAW,EAAE,MAAM,EAAE,EACrB,IAAI,EAAE,MAAM,EACZ,WAAW,CAAC,EAAE,MAAM,0CAmBrB"}
|
|
@@ -1,26 +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 utilities_exports = {};
|
|
19
|
-
__export(utilities_exports, {
|
|
20
|
-
createImportDeclaration: () => createImportDeclaration
|
|
21
|
-
});
|
|
22
|
-
module.exports = __toCommonJS(utilities_exports);
|
|
23
|
-
var import_typescript = require("typescript");
|
|
24
|
-
function createImportDeclaration(importNames, from, importAlias) {
|
|
25
|
-
return import_typescript.factory.createImportDeclaration(void 0, void 0, import_typescript.factory.createImportClause(true, void 0, import_typescript.factory.createNamedImports(importNames.map((importName) => import_typescript.factory.createImportSpecifier(importAlias ? import_typescript.factory.createIdentifier(importAlias) : void 0, import_typescript.factory.createIdentifier(importName))))), import_typescript.factory.createStringLiteral(from));
|
|
26
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
// src/codegen/context/utilities.ts
|
|
2
|
-
import { factory } from "typescript";
|
|
3
|
-
function createImportDeclaration(importNames, from, importAlias) {
|
|
4
|
-
return factory.createImportDeclaration(void 0, void 0, factory.createImportClause(true, void 0, factory.createNamedImports(importNames.map((importName) => factory.createImportSpecifier(importAlias ? factory.createIdentifier(importAlias) : void 0, factory.createIdentifier(importName))))), factory.createStringLiteral(from));
|
|
5
|
-
}
|
|
6
|
-
export {
|
|
7
|
-
createImportDeclaration
|
|
8
|
-
};
|
package/lib/codegen/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
import { DocumentNode } from "graphql";
|
|
3
|
-
export declare function generateTS(document: DocumentNode, contextImport?: string, contextName?: string): {
|
|
4
|
-
models: ts.SourceFile;
|
|
5
|
-
resolvers: ts.SourceFile;
|
|
6
|
-
};
|
|
7
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/codegen/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAKvC,wBAAgB,UAAU,CACxB,QAAQ,EAAE,YAAY,EACtB,aAAa,CAAC,EAAE,MAAM,EACtB,WAAW,CAAC,EAAE,MAAM,GACnB;IAAE,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC;IAAC,SAAS,EAAE,EAAE,CAAC,UAAU,CAAA;CAAE,CAkBrD"}
|
package/lib/codegen/index.js
DELETED
|
@@ -1,41 +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 codegen_exports = {};
|
|
19
|
-
__export(codegen_exports, {
|
|
20
|
-
generateTS: () => generateTS
|
|
21
|
-
});
|
|
22
|
-
module.exports = __toCommonJS(codegen_exports);
|
|
23
|
-
var import_context = require("./context/index");
|
|
24
|
-
var import_resolvers = require("./resolvers");
|
|
25
|
-
var import_models = require("./models");
|
|
26
|
-
function generateTS(document, contextImport, contextName) {
|
|
27
|
-
try {
|
|
28
|
-
let context = (0, import_context.extractContext)({
|
|
29
|
-
context: {
|
|
30
|
-
name: contextName,
|
|
31
|
-
from: contextImport || null
|
|
32
|
-
}
|
|
33
|
-
}, document);
|
|
34
|
-
let models = (0, import_models.generateModels)(context, document);
|
|
35
|
-
let resolvers = (0, import_resolvers.generateResolvers)(context, document);
|
|
36
|
-
return { models, resolvers };
|
|
37
|
-
} catch (e) {
|
|
38
|
-
console.error(e);
|
|
39
|
-
throw e;
|
|
40
|
-
}
|
|
41
|
-
}
|
package/lib/codegen/index.mjs
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
// src/codegen/index.ts
|
|
2
|
-
import { extractContext } from "./context/index.mjs";
|
|
3
|
-
import { generateResolvers } from "./resolvers.mjs";
|
|
4
|
-
import { generateModels } from "./models.mjs";
|
|
5
|
-
function generateTS(document, contextImport, contextName) {
|
|
6
|
-
try {
|
|
7
|
-
let context = extractContext({
|
|
8
|
-
context: {
|
|
9
|
-
name: contextName,
|
|
10
|
-
from: contextImport || null
|
|
11
|
-
}
|
|
12
|
-
}, document);
|
|
13
|
-
let models = generateModels(context, document);
|
|
14
|
-
let resolvers = generateResolvers(context, document);
|
|
15
|
-
return { models, resolvers };
|
|
16
|
-
} catch (e) {
|
|
17
|
-
console.error(e);
|
|
18
|
-
throw e;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
export {
|
|
22
|
-
generateTS
|
|
23
|
-
};
|
package/lib/codegen/models.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../src/codegen/models.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAO7C,wBAAgB,cAAc,CAC5B,OAAO,EAAE,gBAAgB,EACzB,QAAQ,EAAE,YAAY,GACrB,EAAE,CAAC,UAAU,CAEf"}
|
package/lib/codegen/models.js
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
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));
|
|
20
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
-
var models_exports = {};
|
|
22
|
-
__export(models_exports, {
|
|
23
|
-
generateModels: () => generateModels
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(models_exports);
|
|
26
|
-
var import_typescript = __toESM(require("typescript"));
|
|
27
|
-
var import_typedVisitor = require("./typedVisitor");
|
|
28
|
-
var import_utilities = require("./utilities");
|
|
29
|
-
function generateModels(context, document) {
|
|
30
|
-
return (0, import_typedVisitor.visit)(document, createModelsReducer(context));
|
|
31
|
-
}
|
|
32
|
-
function createModelsReducer(context) {
|
|
33
|
-
return {
|
|
34
|
-
Document: {
|
|
35
|
-
leave(node) {
|
|
36
|
-
const imports = context.getAllModelImportDeclarations();
|
|
37
|
-
const statements = node.definitions;
|
|
38
|
-
return import_typescript.factory.createSourceFile(imports.concat(context.getDefaultTypes(), statements.flat()), import_typescript.factory.createToken(import_typescript.default.SyntaxKind.EndOfFileToken), import_typescript.default.NodeFlags.None);
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
SchemaExtension: {
|
|
42
|
-
leave() {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
ObjectTypeExtension: {
|
|
47
|
-
leave() {
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
FieldDefinition: {
|
|
52
|
-
leave(node) {
|
|
53
|
-
return import_typescript.factory.createPropertySignature([import_typescript.factory.createModifier(import_typescript.default.SyntaxKind.ReadonlyKeyword)], import_typescript.factory.createIdentifier(node.name), void 0, node.type);
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
ObjectTypeDefinition: {
|
|
57
|
-
leave(node) {
|
|
58
|
-
const model = context.getDefinedModelType(node.name);
|
|
59
|
-
const interfaces = node.interfaces || [];
|
|
60
|
-
const extendTypes = [context.getBaseModelType()];
|
|
61
|
-
if (model) {
|
|
62
|
-
extendTypes.push(model);
|
|
63
|
-
}
|
|
64
|
-
if (["Query", "Mutation", "Subscription"].includes(node.name)) {
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
return import_typescript.factory.createInterfaceDeclaration(void 0, [import_typescript.factory.createModifier(import_typescript.default.SyntaxKind.ExportKeyword)], import_typescript.factory.createIdentifier((0, import_utilities.addModelSuffix)(node.name)), void 0, [
|
|
68
|
-
import_typescript.factory.createHeritageClause(import_typescript.default.SyntaxKind.ExtendsKeyword, [
|
|
69
|
-
...extendTypes.map((type) => import_typescript.factory.createExpressionWithTypeArguments(type.toExpression(), void 0)),
|
|
70
|
-
...interfaces.map((interfaceExpression) => import_typescript.factory.createExpressionWithTypeArguments(interfaceExpression, void 0))
|
|
71
|
-
])
|
|
72
|
-
], [
|
|
73
|
-
import_typescript.factory.createPropertySignature([import_typescript.factory.createModifier(import_typescript.default.SyntaxKind.ReadonlyKeyword)], "__typename", void 0, import_typescript.factory.createLiteralTypeNode(import_typescript.factory.createStringLiteral(node.name))),
|
|
74
|
-
...!model && node.fields || []
|
|
75
|
-
]);
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
InputObjectTypeDefinition: {
|
|
79
|
-
leave(node) {
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
InputValueDefinition: {
|
|
84
|
-
leave(node) {
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
EnumTypeDefinition: {
|
|
89
|
-
leave(node) {
|
|
90
|
-
return import_typescript.factory.createEnumDeclaration(void 0, [import_typescript.factory.createModifier(import_typescript.default.SyntaxKind.ExportKeyword)], (0, import_utilities.addModelSuffix)(node.name), node.values || []);
|
|
91
|
-
}
|
|
92
|
-
},
|
|
93
|
-
EnumValueDefinition: {
|
|
94
|
-
leave(node) {
|
|
95
|
-
return import_typescript.factory.createEnumMember(node.name, import_typescript.factory.createStringLiteral(node.name));
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
InterfaceTypeDefinition: {
|
|
99
|
-
leave(node) {
|
|
100
|
-
const extendTypes = [context.getBaseModelType()];
|
|
101
|
-
const interfaces = node.interfaces || [];
|
|
102
|
-
return import_typescript.factory.createInterfaceDeclaration(void 0, [import_typescript.factory.createModifier(import_typescript.default.SyntaxKind.ExportKeyword)], import_typescript.factory.createIdentifier((0, import_utilities.addModelSuffix)(node.name)), void 0, [
|
|
103
|
-
import_typescript.factory.createHeritageClause(import_typescript.default.SyntaxKind.ExtendsKeyword, [
|
|
104
|
-
...extendTypes.map((type) => import_typescript.factory.createExpressionWithTypeArguments(type.toExpression(), void 0)),
|
|
105
|
-
...interfaces.map((interfaceExpression) => import_typescript.factory.createExpressionWithTypeArguments(interfaceExpression, void 0))
|
|
106
|
-
])
|
|
107
|
-
], [
|
|
108
|
-
import_typescript.factory.createPropertySignature(void 0, "__typename", void 0, import_typescript.factory.createKeywordTypeNode(import_typescript.default.SyntaxKind.StringKeyword))
|
|
109
|
-
]);
|
|
110
|
-
}
|
|
111
|
-
},
|
|
112
|
-
UnionTypeDefinition: {
|
|
113
|
-
leave({ name, types }) {
|
|
114
|
-
return import_typescript.factory.createTypeAliasDeclaration(void 0, [import_typescript.factory.createModifier(import_typescript.default.SyntaxKind.ExportKeyword)], import_typescript.factory.createIdentifier((0, import_utilities.addModelSuffix)(name)), void 0, import_typescript.factory.createUnionTypeNode((types == null ? void 0 : types.map((type) => {
|
|
115
|
-
return (0, import_utilities.createNonNullableType)(type);
|
|
116
|
-
})) || []));
|
|
117
|
-
}
|
|
118
|
-
},
|
|
119
|
-
ScalarTypeDefinition: {
|
|
120
|
-
leave(node) {
|
|
121
|
-
return context.getScalarDeclaration(node.name) || null;
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
NamedType: {
|
|
125
|
-
leave(node, _a, _p, path) {
|
|
126
|
-
const isImplementedInterface = path[path.length - 2] === "interfaces";
|
|
127
|
-
if (isImplementedInterface) {
|
|
128
|
-
return import_typescript.factory.createIdentifier((0, import_utilities.addModelSuffix)(node.name));
|
|
129
|
-
}
|
|
130
|
-
return (0, import_utilities.createNullableType)(context.getModelType(node.name).toTypeReference());
|
|
131
|
-
}
|
|
132
|
-
},
|
|
133
|
-
ListType: {
|
|
134
|
-
leave({ type }) {
|
|
135
|
-
return (0, import_utilities.createNullableType)(import_typescript.factory.createTypeReferenceNode(import_typescript.factory.createIdentifier("ReadonlyArray"), [type]));
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
NonNullType: {
|
|
139
|
-
leave({ type }) {
|
|
140
|
-
return (0, import_utilities.createNonNullableType)(type);
|
|
141
|
-
}
|
|
142
|
-
},
|
|
143
|
-
Name: {
|
|
144
|
-
leave(node) {
|
|
145
|
-
return node.value;
|
|
146
|
-
}
|
|
147
|
-
},
|
|
148
|
-
DirectiveDefinition: {
|
|
149
|
-
leave() {
|
|
150
|
-
return null;
|
|
151
|
-
}
|
|
152
|
-
},
|
|
153
|
-
Directive: {
|
|
154
|
-
leave() {
|
|
155
|
-
return null;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
}
|
package/lib/codegen/models.mjs
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
// src/codegen/models.ts
|
|
2
|
-
import ts, { factory } from "typescript";
|
|
3
|
-
import { visit } from "./typedVisitor.mjs";
|
|
4
|
-
import {
|
|
5
|
-
createNullableType,
|
|
6
|
-
createNonNullableType,
|
|
7
|
-
addModelSuffix
|
|
8
|
-
} from "./utilities.mjs";
|
|
9
|
-
function generateModels(context, document) {
|
|
10
|
-
return visit(document, createModelsReducer(context));
|
|
11
|
-
}
|
|
12
|
-
function createModelsReducer(context) {
|
|
13
|
-
return {
|
|
14
|
-
Document: {
|
|
15
|
-
leave(node) {
|
|
16
|
-
const imports = context.getAllModelImportDeclarations();
|
|
17
|
-
const statements = node.definitions;
|
|
18
|
-
return factory.createSourceFile(imports.concat(context.getDefaultTypes(), statements.flat()), factory.createToken(ts.SyntaxKind.EndOfFileToken), ts.NodeFlags.None);
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
SchemaExtension: {
|
|
22
|
-
leave() {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
ObjectTypeExtension: {
|
|
27
|
-
leave() {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
FieldDefinition: {
|
|
32
|
-
leave(node) {
|
|
33
|
-
return factory.createPropertySignature([factory.createModifier(ts.SyntaxKind.ReadonlyKeyword)], factory.createIdentifier(node.name), void 0, node.type);
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
ObjectTypeDefinition: {
|
|
37
|
-
leave(node) {
|
|
38
|
-
const model = context.getDefinedModelType(node.name);
|
|
39
|
-
const interfaces = node.interfaces || [];
|
|
40
|
-
const extendTypes = [context.getBaseModelType()];
|
|
41
|
-
if (model) {
|
|
42
|
-
extendTypes.push(model);
|
|
43
|
-
}
|
|
44
|
-
if (["Query", "Mutation", "Subscription"].includes(node.name)) {
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
return factory.createInterfaceDeclaration(void 0, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier(addModelSuffix(node.name)), void 0, [
|
|
48
|
-
factory.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [
|
|
49
|
-
...extendTypes.map((type) => factory.createExpressionWithTypeArguments(type.toExpression(), void 0)),
|
|
50
|
-
...interfaces.map((interfaceExpression) => factory.createExpressionWithTypeArguments(interfaceExpression, void 0))
|
|
51
|
-
])
|
|
52
|
-
], [
|
|
53
|
-
factory.createPropertySignature([factory.createModifier(ts.SyntaxKind.ReadonlyKeyword)], "__typename", void 0, factory.createLiteralTypeNode(factory.createStringLiteral(node.name))),
|
|
54
|
-
...!model && node.fields || []
|
|
55
|
-
]);
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
InputObjectTypeDefinition: {
|
|
59
|
-
leave(node) {
|
|
60
|
-
return null;
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
InputValueDefinition: {
|
|
64
|
-
leave(node) {
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
EnumTypeDefinition: {
|
|
69
|
-
leave(node) {
|
|
70
|
-
return factory.createEnumDeclaration(void 0, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], addModelSuffix(node.name), node.values || []);
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
EnumValueDefinition: {
|
|
74
|
-
leave(node) {
|
|
75
|
-
return factory.createEnumMember(node.name, factory.createStringLiteral(node.name));
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
InterfaceTypeDefinition: {
|
|
79
|
-
leave(node) {
|
|
80
|
-
const extendTypes = [context.getBaseModelType()];
|
|
81
|
-
const interfaces = node.interfaces || [];
|
|
82
|
-
return factory.createInterfaceDeclaration(void 0, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier(addModelSuffix(node.name)), void 0, [
|
|
83
|
-
factory.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [
|
|
84
|
-
...extendTypes.map((type) => factory.createExpressionWithTypeArguments(type.toExpression(), void 0)),
|
|
85
|
-
...interfaces.map((interfaceExpression) => factory.createExpressionWithTypeArguments(interfaceExpression, void 0))
|
|
86
|
-
])
|
|
87
|
-
], [
|
|
88
|
-
factory.createPropertySignature(void 0, "__typename", void 0, factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword))
|
|
89
|
-
]);
|
|
90
|
-
}
|
|
91
|
-
},
|
|
92
|
-
UnionTypeDefinition: {
|
|
93
|
-
leave({ name, types }) {
|
|
94
|
-
return factory.createTypeAliasDeclaration(void 0, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier(addModelSuffix(name)), void 0, factory.createUnionTypeNode((types == null ? void 0 : types.map((type) => {
|
|
95
|
-
return createNonNullableType(type);
|
|
96
|
-
})) || []));
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
|
-
ScalarTypeDefinition: {
|
|
100
|
-
leave(node) {
|
|
101
|
-
return context.getScalarDeclaration(node.name) || null;
|
|
102
|
-
}
|
|
103
|
-
},
|
|
104
|
-
NamedType: {
|
|
105
|
-
leave(node, _a, _p, path) {
|
|
106
|
-
const isImplementedInterface = path[path.length - 2] === "interfaces";
|
|
107
|
-
if (isImplementedInterface) {
|
|
108
|
-
return factory.createIdentifier(addModelSuffix(node.name));
|
|
109
|
-
}
|
|
110
|
-
return createNullableType(context.getModelType(node.name).toTypeReference());
|
|
111
|
-
}
|
|
112
|
-
},
|
|
113
|
-
ListType: {
|
|
114
|
-
leave({ type }) {
|
|
115
|
-
return createNullableType(factory.createTypeReferenceNode(factory.createIdentifier("ReadonlyArray"), [type]));
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
NonNullType: {
|
|
119
|
-
leave({ type }) {
|
|
120
|
-
return createNonNullableType(type);
|
|
121
|
-
}
|
|
122
|
-
},
|
|
123
|
-
Name: {
|
|
124
|
-
leave(node) {
|
|
125
|
-
return node.value;
|
|
126
|
-
}
|
|
127
|
-
},
|
|
128
|
-
DirectiveDefinition: {
|
|
129
|
-
leave() {
|
|
130
|
-
return null;
|
|
131
|
-
}
|
|
132
|
-
},
|
|
133
|
-
Directive: {
|
|
134
|
-
leave() {
|
|
135
|
-
return null;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
export {
|
|
141
|
-
generateModels
|
|
142
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolvers.d.ts","sourceRoot":"","sources":["../../src/codegen/resolvers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,MAAM,YAAY,CAAC;AACzC,OAAO,EACL,YAAY,EAIb,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAO7C,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,gBAAgB,EACzB,QAAQ,EAAE,YAAY,GACrB,EAAE,CAAC,UAAU,CAEf"}
|