@baeta/plugin-graphql 0.0.1
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/dist/codegen.d.ts +6 -0
- package/dist/codegen.js +116 -0
- package/dist/codegen.mjs +89 -0
- package/dist/config.d.ts +10 -0
- package/dist/config.js +16 -0
- package/dist/config.mjs +0 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +41 -0
- package/dist/index.mjs +19 -0
- package/dist/modules/builder.d.ts +17 -0
- package/dist/modules/builder.js +439 -0
- package/dist/modules/builder.mjs +429 -0
- package/dist/modules/config.d.ts +11 -0
- package/dist/modules/config.js +16 -0
- package/dist/modules/config.mjs +0 -0
- package/dist/modules/index.d.ts +6 -0
- package/dist/modules/index.js +148 -0
- package/dist/modules/index.mjs +132 -0
- package/dist/modules/utils.d.ts +28 -0
- package/dist/modules/utils.js +209 -0
- package/dist/modules/utils.mjs +168 -0
- package/dist/resolvers/config.d.ts +16 -0
- package/dist/resolvers/config.js +16 -0
- package/dist/resolvers/config.mjs +0 -0
- package/dist/resolvers/index.d.ts +10 -0
- package/dist/resolvers/index.js +309 -0
- package/dist/resolvers/index.mjs +289 -0
- package/dist/resolvers/visitor.d.ts +29 -0
- package/dist/resolvers/visitor.js +139 -0
- package/dist/resolvers/visitor.mjs +111 -0
- package/dist/utils/cache.d.ts +3 -0
- package/dist/utils/cache.js +40 -0
- package/dist/utils/cache.mjs +16 -0
- package/dist/utils/hash.d.ts +6 -0
- package/dist/utils/hash.js +38 -0
- package/dist/utils/hash.mjs +13 -0
- package/dist/utils/load.d.ts +9 -0
- package/dist/utils/load.js +62 -0
- package/dist/utils/load.mjs +40 -0
- package/dist/utils/path.d.ts +3 -0
- package/dist/utils/path.js +37 -0
- package/dist/utils/path.mjs +7 -0
- package/package.json +65 -0
package/dist/codegen.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var codegen_exports = {};
|
|
26
|
+
__export(codegen_exports, {
|
|
27
|
+
generate: () => generate
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(codegen_exports);
|
|
30
|
+
var import_core = require("@graphql-codegen/core");
|
|
31
|
+
var import_plugin_helpers = require("@graphql-codegen/plugin-helpers");
|
|
32
|
+
var modules = __toESM(require("./modules"));
|
|
33
|
+
var typescriptPlugin = __toESM(require("@graphql-codegen/typescript"));
|
|
34
|
+
var typescriptResolversPlugin = __toESM(require("./resolvers"));
|
|
35
|
+
var import_path = __toESM(require("path"));
|
|
36
|
+
var import_cache = require("./utils/cache");
|
|
37
|
+
var import_load2 = require("./utils/load");
|
|
38
|
+
var import_plugin = require("@baeta/plugin");
|
|
39
|
+
async function generate(options) {
|
|
40
|
+
const root = process.cwd();
|
|
41
|
+
const modulesDir = import_path.default.relative(root, options.modulesDir || "modules");
|
|
42
|
+
const rootConfig = {
|
|
43
|
+
schemas: (0, import_plugin_helpers.normalizeInstanceOrArray)(options.schemas),
|
|
44
|
+
modulesDir,
|
|
45
|
+
baseTypesPath: import_path.default.relative(
|
|
46
|
+
modulesDir,
|
|
47
|
+
options.baseTypesPath || "./__generated__/types.ts"
|
|
48
|
+
),
|
|
49
|
+
contextType: options.contextType,
|
|
50
|
+
moduleDefinitionName: options.moduleDefinitionName || "typedef.ts",
|
|
51
|
+
scalars: options.scalars,
|
|
52
|
+
plugins: (0, import_plugin_helpers.normalizeConfig)(["typescript", "typescript-resolvers"]),
|
|
53
|
+
pluginMap: {
|
|
54
|
+
typescript: typescriptPlugin,
|
|
55
|
+
"typescript-resolvers": typescriptResolversPlugin
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const cache = (0, import_cache.createCache)();
|
|
59
|
+
const schemaPointerMap = {};
|
|
60
|
+
for (const ptr of rootConfig.schemas) {
|
|
61
|
+
if (typeof ptr === "string") {
|
|
62
|
+
schemaPointerMap[ptr] = {};
|
|
63
|
+
} else if (typeof ptr === "object") {
|
|
64
|
+
Object.assign(schemaPointerMap, ptr);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const hash = JSON.stringify(schemaPointerMap);
|
|
68
|
+
const result = await cache("schema", hash, async () => {
|
|
69
|
+
return (0, import_load2.loadSchema)(schemaPointerMap, root);
|
|
70
|
+
});
|
|
71
|
+
const outputs = await modules.preset.buildGeneratesSection({
|
|
72
|
+
baseOutputDir: modulesDir,
|
|
73
|
+
presetConfig: {
|
|
74
|
+
baseTypesPath: rootConfig.baseTypesPath,
|
|
75
|
+
filename: rootConfig.moduleDefinitionName,
|
|
76
|
+
encapsulateModuleTypes: "none"
|
|
77
|
+
},
|
|
78
|
+
schema: result.outputSchema,
|
|
79
|
+
schemaAst: result.outputSchemaAst,
|
|
80
|
+
documents: [],
|
|
81
|
+
pluginMap: rootConfig.pluginMap,
|
|
82
|
+
plugins: rootConfig.plugins,
|
|
83
|
+
config: {
|
|
84
|
+
useIndexSignature: true,
|
|
85
|
+
inputMaybeValue: "T | undefined",
|
|
86
|
+
mapperTypeSuffix: "Prisma",
|
|
87
|
+
contextType: rootConfig.contextType,
|
|
88
|
+
customResolverFn: "@baeta/core#Resolver",
|
|
89
|
+
customSubscriptionResolver: "@baeta/core#SubscriptionResolver",
|
|
90
|
+
useTypeImports: true,
|
|
91
|
+
makeResolverTypeCallable: true,
|
|
92
|
+
includeDirectives: true,
|
|
93
|
+
resolverTypeWrapperSignature: "T",
|
|
94
|
+
scalars: {
|
|
95
|
+
BigInt: "number",
|
|
96
|
+
Bytes: "Buffer",
|
|
97
|
+
DateTime: "Date",
|
|
98
|
+
Decimal: "number",
|
|
99
|
+
Json: "{}",
|
|
100
|
+
...rootConfig.scalars
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
const promises = outputs.map(async (output) => {
|
|
105
|
+
const result2 = await (0, import_core.codegen)({
|
|
106
|
+
...output,
|
|
107
|
+
cache
|
|
108
|
+
});
|
|
109
|
+
return new import_plugin.File(output.filename, result2, "graphql");
|
|
110
|
+
});
|
|
111
|
+
return Promise.all(promises);
|
|
112
|
+
}
|
|
113
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
114
|
+
0 && (module.exports = {
|
|
115
|
+
generate
|
|
116
|
+
});
|
package/dist/codegen.mjs
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { codegen as gqlCodegen } from "@graphql-codegen/core";
|
|
2
|
+
import {
|
|
3
|
+
normalizeConfig,
|
|
4
|
+
normalizeInstanceOrArray
|
|
5
|
+
} from "@graphql-codegen/plugin-helpers";
|
|
6
|
+
import * as modules from "./modules";
|
|
7
|
+
import * as typescriptPlugin from "@graphql-codegen/typescript";
|
|
8
|
+
import * as typescriptResolversPlugin from "./resolvers";
|
|
9
|
+
import path from "path";
|
|
10
|
+
import { createCache } from "./utils/cache";
|
|
11
|
+
import { loadSchema } from "./utils/load";
|
|
12
|
+
import { File } from "@baeta/plugin";
|
|
13
|
+
async function generate(options) {
|
|
14
|
+
const root = process.cwd();
|
|
15
|
+
const modulesDir = path.relative(root, options.modulesDir || "modules");
|
|
16
|
+
const rootConfig = {
|
|
17
|
+
schemas: normalizeInstanceOrArray(options.schemas),
|
|
18
|
+
modulesDir,
|
|
19
|
+
baseTypesPath: path.relative(
|
|
20
|
+
modulesDir,
|
|
21
|
+
options.baseTypesPath || "./__generated__/types.ts"
|
|
22
|
+
),
|
|
23
|
+
contextType: options.contextType,
|
|
24
|
+
moduleDefinitionName: options.moduleDefinitionName || "typedef.ts",
|
|
25
|
+
scalars: options.scalars,
|
|
26
|
+
plugins: normalizeConfig(["typescript", "typescript-resolvers"]),
|
|
27
|
+
pluginMap: {
|
|
28
|
+
typescript: typescriptPlugin,
|
|
29
|
+
"typescript-resolvers": typescriptResolversPlugin
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const cache = createCache();
|
|
33
|
+
const schemaPointerMap = {};
|
|
34
|
+
for (const ptr of rootConfig.schemas) {
|
|
35
|
+
if (typeof ptr === "string") {
|
|
36
|
+
schemaPointerMap[ptr] = {};
|
|
37
|
+
} else if (typeof ptr === "object") {
|
|
38
|
+
Object.assign(schemaPointerMap, ptr);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const hash = JSON.stringify(schemaPointerMap);
|
|
42
|
+
const result = await cache("schema", hash, async () => {
|
|
43
|
+
return loadSchema(schemaPointerMap, root);
|
|
44
|
+
});
|
|
45
|
+
const outputs = await modules.preset.buildGeneratesSection({
|
|
46
|
+
baseOutputDir: modulesDir,
|
|
47
|
+
presetConfig: {
|
|
48
|
+
baseTypesPath: rootConfig.baseTypesPath,
|
|
49
|
+
filename: rootConfig.moduleDefinitionName,
|
|
50
|
+
encapsulateModuleTypes: "none"
|
|
51
|
+
},
|
|
52
|
+
schema: result.outputSchema,
|
|
53
|
+
schemaAst: result.outputSchemaAst,
|
|
54
|
+
documents: [],
|
|
55
|
+
pluginMap: rootConfig.pluginMap,
|
|
56
|
+
plugins: rootConfig.plugins,
|
|
57
|
+
config: {
|
|
58
|
+
useIndexSignature: true,
|
|
59
|
+
inputMaybeValue: "T | undefined",
|
|
60
|
+
mapperTypeSuffix: "Prisma",
|
|
61
|
+
contextType: rootConfig.contextType,
|
|
62
|
+
customResolverFn: "@baeta/core#Resolver",
|
|
63
|
+
customSubscriptionResolver: "@baeta/core#SubscriptionResolver",
|
|
64
|
+
useTypeImports: true,
|
|
65
|
+
makeResolverTypeCallable: true,
|
|
66
|
+
includeDirectives: true,
|
|
67
|
+
resolverTypeWrapperSignature: "T",
|
|
68
|
+
scalars: {
|
|
69
|
+
BigInt: "number",
|
|
70
|
+
Bytes: "Buffer",
|
|
71
|
+
DateTime: "Date",
|
|
72
|
+
Decimal: "number",
|
|
73
|
+
Json: "{}",
|
|
74
|
+
...rootConfig.scalars
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
const promises = outputs.map(async (output) => {
|
|
79
|
+
const result2 = await gqlCodegen({
|
|
80
|
+
...output,
|
|
81
|
+
cache
|
|
82
|
+
});
|
|
83
|
+
return new File(output.filename, result2, "graphql");
|
|
84
|
+
});
|
|
85
|
+
return Promise.all(promises);
|
|
86
|
+
}
|
|
87
|
+
export {
|
|
88
|
+
generate
|
|
89
|
+
};
|
package/dist/config.d.ts
ADDED
package/dist/config.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var config_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(config_exports);
|
package/dist/config.mjs
ADDED
|
File without changes
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as _baeta_plugin from '@baeta/plugin';
|
|
2
|
+
import { GraphqlPluginConfig } from './config.js';
|
|
3
|
+
export { GraphqlPluginConfig } from './config.js';
|
|
4
|
+
|
|
5
|
+
declare const _default: (config: GraphqlPluginConfig) => _baeta_plugin.GeneratorPluginV1WithConfig<unknown, {}>;
|
|
6
|
+
|
|
7
|
+
export { _default as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var graphql_exports = {};
|
|
20
|
+
__export(graphql_exports, {
|
|
21
|
+
default: () => graphql_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(graphql_exports);
|
|
24
|
+
var import_plugin = require("@baeta/plugin");
|
|
25
|
+
var import_codegen = require("./codegen");
|
|
26
|
+
var graphql_default = (0, import_plugin.createPluginFactoryV1)({
|
|
27
|
+
name: "graphql",
|
|
28
|
+
watch: (baetaConfig, pluginConfig) => {
|
|
29
|
+
return {
|
|
30
|
+
include: pluginConfig.schemas,
|
|
31
|
+
ignore: []
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
generate: async (params) => {
|
|
35
|
+
const files = await (0, import_codegen.generate)(params.config);
|
|
36
|
+
params.ctx.fileManager.add(...files);
|
|
37
|
+
return params.next();
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
+
0 && (module.exports = {});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createPluginFactoryV1 } from "@baeta/plugin";
|
|
2
|
+
import { generate } from "./codegen";
|
|
3
|
+
var graphql_default = createPluginFactoryV1({
|
|
4
|
+
name: "graphql",
|
|
5
|
+
watch: (baetaConfig, pluginConfig) => {
|
|
6
|
+
return {
|
|
7
|
+
include: pluginConfig.schemas,
|
|
8
|
+
ignore: []
|
|
9
|
+
};
|
|
10
|
+
},
|
|
11
|
+
generate: async (params) => {
|
|
12
|
+
const files = await generate(params.config);
|
|
13
|
+
params.ctx.fileManager.add(...files);
|
|
14
|
+
return params.next();
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
export {
|
|
18
|
+
graphql_default as default
|
|
19
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { DocumentNode, GraphQLSchema } from 'graphql';
|
|
2
|
+
import { ModulesConfig } from './config.js';
|
|
3
|
+
import { BaseVisitor } from '@graphql-codegen/visitor-plugin-common';
|
|
4
|
+
|
|
5
|
+
declare function buildModule(name: string, doc: DocumentNode, { importNamespace, importPath, encapsulate, requireRootResolvers, shouldDeclare, rootTypes, schema, baseVisitor, }: {
|
|
6
|
+
importNamespace: string;
|
|
7
|
+
importPath: string;
|
|
8
|
+
encapsulate: ModulesConfig["encapsulateModuleTypes"];
|
|
9
|
+
requireRootResolvers: ModulesConfig["requireRootResolvers"];
|
|
10
|
+
shouldDeclare: boolean;
|
|
11
|
+
rootTypes: string[];
|
|
12
|
+
baseVisitor: BaseVisitor;
|
|
13
|
+
schema?: GraphQLSchema;
|
|
14
|
+
useGraphQLModules: boolean;
|
|
15
|
+
}): string;
|
|
16
|
+
|
|
17
|
+
export { buildModule };
|