@baeta/plugin-graphql 0.0.2 → 0.0.4
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/index.cjs +1283 -0
- package/index.d.ts +14 -0
- package/index.js +1281 -0
- package/package.json +17 -17
- package/dist/codegen.d.ts +0 -6
- package/dist/codegen.js +0 -116
- package/dist/codegen.mjs +0 -89
- package/dist/config.d.ts +0 -10
- package/dist/config.js +0 -16
- package/dist/config.mjs +0 -0
- package/dist/index.d.ts +0 -7
- package/dist/index.js +0 -41
- package/dist/index.mjs +0 -19
- package/dist/modules/builder.d.ts +0 -17
- package/dist/modules/builder.js +0 -439
- package/dist/modules/builder.mjs +0 -429
- package/dist/modules/config.d.ts +0 -11
- package/dist/modules/config.js +0 -16
- package/dist/modules/config.mjs +0 -0
- package/dist/modules/index.d.ts +0 -6
- package/dist/modules/index.js +0 -148
- package/dist/modules/index.mjs +0 -132
- package/dist/modules/utils.d.ts +0 -28
- package/dist/modules/utils.js +0 -209
- package/dist/modules/utils.mjs +0 -168
- package/dist/resolvers/config.d.ts +0 -16
- package/dist/resolvers/config.js +0 -16
- package/dist/resolvers/config.mjs +0 -0
- package/dist/resolvers/index.d.ts +0 -10
- package/dist/resolvers/index.js +0 -309
- package/dist/resolvers/index.mjs +0 -289
- package/dist/resolvers/visitor.d.ts +0 -29
- package/dist/resolvers/visitor.js +0 -139
- package/dist/resolvers/visitor.mjs +0 -111
- package/dist/utils/cache.d.ts +0 -3
- package/dist/utils/cache.js +0 -40
- package/dist/utils/cache.mjs +0 -16
- package/dist/utils/hash.d.ts +0 -6
- package/dist/utils/hash.js +0 -38
- package/dist/utils/hash.mjs +0 -13
- package/dist/utils/load.d.ts +0 -9
- package/dist/utils/load.js +0 -62
- package/dist/utils/load.mjs +0 -40
- package/dist/utils/path.d.ts +0 -3
- package/dist/utils/path.js +0 -37
- package/dist/utils/path.mjs +0 -7
package/dist/modules/index.mjs
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { concatAST, isScalarType } from "graphql";
|
|
2
|
-
import { resolve, relative, join } from "path";
|
|
3
|
-
import {
|
|
4
|
-
groupSourcesByModule,
|
|
5
|
-
stripFilename,
|
|
6
|
-
normalize,
|
|
7
|
-
isGraphQLPrimitive
|
|
8
|
-
} from "./utils";
|
|
9
|
-
import { buildModule } from "./builder";
|
|
10
|
-
import {
|
|
11
|
-
BaseVisitor,
|
|
12
|
-
getConfigValue
|
|
13
|
-
} from "@graphql-codegen/visitor-plugin-common";
|
|
14
|
-
const preset = {
|
|
15
|
-
buildGeneratesSection: (options) => {
|
|
16
|
-
const { baseOutputDir } = options;
|
|
17
|
-
const { baseTypesPath, encapsulateModuleTypes } = options.presetConfig;
|
|
18
|
-
const requireRootResolvers = getConfigValue(
|
|
19
|
-
options == null ? void 0 : options.presetConfig.requireRootResolvers,
|
|
20
|
-
false
|
|
21
|
-
);
|
|
22
|
-
const cwd = resolve(options.presetConfig.cwd || process.cwd());
|
|
23
|
-
const importTypesNamespace = options.presetConfig.importTypesNamespace || "Types";
|
|
24
|
-
if (!baseTypesPath) {
|
|
25
|
-
throw new Error(
|
|
26
|
-
`Preset "graphql-modules" requires you to specify "baseTypesPath" configuration and point it to your base types file (generated by "typescript" plugin)!`
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
if (!options.schemaAst || !options.schemaAst.extensions.sources) {
|
|
30
|
-
throw new Error(`Preset "graphql-modules" requires to use GraphQL SDL`);
|
|
31
|
-
}
|
|
32
|
-
const extensions = options.schemaAst.extensions;
|
|
33
|
-
const sourcesByModuleMap = groupSourcesByModule(
|
|
34
|
-
extensions.extendedSources,
|
|
35
|
-
baseOutputDir
|
|
36
|
-
);
|
|
37
|
-
const modules = Object.keys(sourcesByModuleMap);
|
|
38
|
-
const baseVisitor = new BaseVisitor(options.config, {});
|
|
39
|
-
const baseOutput = {
|
|
40
|
-
filename: resolve(cwd, baseOutputDir, baseTypesPath),
|
|
41
|
-
schema: options.schema,
|
|
42
|
-
documents: options.documents,
|
|
43
|
-
plugins: [
|
|
44
|
-
...options.plugins,
|
|
45
|
-
{
|
|
46
|
-
"modules-exported-scalars": {}
|
|
47
|
-
}
|
|
48
|
-
],
|
|
49
|
-
pluginMap: {
|
|
50
|
-
...options.pluginMap,
|
|
51
|
-
"modules-exported-scalars": {
|
|
52
|
-
plugin: (schema) => {
|
|
53
|
-
const typeMap = schema.getTypeMap();
|
|
54
|
-
return Object.keys(typeMap).map((t) => {
|
|
55
|
-
if (t && typeMap[t] && isScalarType(typeMap[t]) && !isGraphQLPrimitive(t)) {
|
|
56
|
-
const convertedName = baseVisitor.convertName(t);
|
|
57
|
-
return `export type ${convertedName} = Scalars["${t}"];`;
|
|
58
|
-
}
|
|
59
|
-
return null;
|
|
60
|
-
}).filter(Boolean).join("\n");
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
config: {
|
|
65
|
-
...options.config,
|
|
66
|
-
enumsAsTypes: true
|
|
67
|
-
},
|
|
68
|
-
schemaAst: options.schemaAst
|
|
69
|
-
};
|
|
70
|
-
const baseTypesFilename = baseTypesPath.replace(/\.(js|ts|d.ts)$/, "");
|
|
71
|
-
const baseTypesDir = stripFilename(baseOutput.filename);
|
|
72
|
-
const outputs = modules.map((moduleName) => {
|
|
73
|
-
const filename = resolve(
|
|
74
|
-
cwd,
|
|
75
|
-
baseOutputDir,
|
|
76
|
-
moduleName,
|
|
77
|
-
options.presetConfig.filename
|
|
78
|
-
);
|
|
79
|
-
const dirpath = stripFilename(filename);
|
|
80
|
-
const relativePath = relative(dirpath, baseTypesDir);
|
|
81
|
-
const importPath = options.presetConfig.importBaseTypesFrom || normalize(join(relativePath, baseTypesFilename));
|
|
82
|
-
const sources = sourcesByModuleMap[moduleName];
|
|
83
|
-
const documents = sources.map(
|
|
84
|
-
(source) => source.document
|
|
85
|
-
);
|
|
86
|
-
const moduleDocument = concatAST(documents);
|
|
87
|
-
const shouldDeclare = filename.endsWith(".d.ts");
|
|
88
|
-
return {
|
|
89
|
-
filename,
|
|
90
|
-
schema: options.schema,
|
|
91
|
-
documents: [],
|
|
92
|
-
plugins: [
|
|
93
|
-
...options.plugins.filter((p) => typeof p === "object" && !!p.add),
|
|
94
|
-
{
|
|
95
|
-
"graphql-modules-plugin": {}
|
|
96
|
-
}
|
|
97
|
-
],
|
|
98
|
-
pluginMap: {
|
|
99
|
-
...options.pluginMap,
|
|
100
|
-
"graphql-modules-plugin": {
|
|
101
|
-
plugin: (schema) => {
|
|
102
|
-
var _a, _b, _c;
|
|
103
|
-
return buildModule(moduleName, moduleDocument, {
|
|
104
|
-
importNamespace: importTypesNamespace,
|
|
105
|
-
importPath,
|
|
106
|
-
encapsulate: encapsulateModuleTypes || "namespace",
|
|
107
|
-
requireRootResolvers,
|
|
108
|
-
shouldDeclare,
|
|
109
|
-
schema,
|
|
110
|
-
baseVisitor,
|
|
111
|
-
useGraphQLModules: false,
|
|
112
|
-
rootTypes: [
|
|
113
|
-
((_a = schema.getQueryType()) == null ? void 0 : _a.name) || "",
|
|
114
|
-
((_b = schema.getMutationType()) == null ? void 0 : _b.name) || "",
|
|
115
|
-
((_c = schema.getSubscriptionType()) == null ? void 0 : _c.name) || ""
|
|
116
|
-
].filter(Boolean)
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
},
|
|
121
|
-
config: options.config,
|
|
122
|
-
schemaAst: options.schemaAst
|
|
123
|
-
};
|
|
124
|
-
});
|
|
125
|
-
return [baseOutput].concat(outputs);
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
var modules_default = preset;
|
|
129
|
-
export {
|
|
130
|
-
modules_default as default,
|
|
131
|
-
preset
|
|
132
|
-
};
|
package/dist/modules/utils.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { DocumentNode, TypeNode, NamedTypeNode } from 'graphql';
|
|
2
|
-
import { Source } from '@graphql-tools/utils';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Searches every node to collect used types
|
|
6
|
-
*/
|
|
7
|
-
declare function collectUsedTypes(doc: DocumentNode): string[];
|
|
8
|
-
declare function resolveTypeNode(node: TypeNode): NamedTypeNode;
|
|
9
|
-
declare function isGraphQLPrimitive(name: string): boolean;
|
|
10
|
-
declare function unique<T>(val: T, i: number, all: T[]): boolean;
|
|
11
|
-
declare function withQuotes(val: string): string;
|
|
12
|
-
declare function indent(size: number): (val: string) => string;
|
|
13
|
-
declare function buildBlock({ name, lines, }: {
|
|
14
|
-
name: string;
|
|
15
|
-
lines: string[];
|
|
16
|
-
}): string;
|
|
17
|
-
declare function groupSourcesByModule(sources: Source[], basePath: string): Record<string, Source[]>;
|
|
18
|
-
declare function stripFilename(path: string): string;
|
|
19
|
-
declare function normalize(path: string): string;
|
|
20
|
-
/**
|
|
21
|
-
* Pushes an item to a list only if the list doesn't include the item
|
|
22
|
-
*/
|
|
23
|
-
declare function pushUnique<T>(list: T[], item: T): void;
|
|
24
|
-
declare function concatByKey<T extends Record<string, any[]>, K extends keyof T>(left: T, right: T, key: K): T[K][number][];
|
|
25
|
-
declare function uniqueByKey<T extends Record<string, any[]>, K extends keyof T>(left: T, right: T, key: K): any[];
|
|
26
|
-
declare function createObject<K extends string, T>(keys: K[], valueFn: (key: K) => T): Record<K, T>;
|
|
27
|
-
|
|
28
|
-
export { buildBlock, collectUsedTypes, concatByKey, createObject, groupSourcesByModule, indent, isGraphQLPrimitive, normalize, pushUnique, resolveTypeNode, stripFilename, unique, uniqueByKey, withQuotes };
|
package/dist/modules/utils.js
DELETED
|
@@ -1,209 +0,0 @@
|
|
|
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 utils_exports = {};
|
|
26
|
-
__export(utils_exports, {
|
|
27
|
-
buildBlock: () => buildBlock,
|
|
28
|
-
collectUsedTypes: () => collectUsedTypes,
|
|
29
|
-
concatByKey: () => concatByKey,
|
|
30
|
-
createObject: () => createObject,
|
|
31
|
-
groupSourcesByModule: () => groupSourcesByModule,
|
|
32
|
-
indent: () => indent,
|
|
33
|
-
isGraphQLPrimitive: () => isGraphQLPrimitive,
|
|
34
|
-
normalize: () => normalize,
|
|
35
|
-
pushUnique: () => pushUnique,
|
|
36
|
-
resolveTypeNode: () => resolveTypeNode,
|
|
37
|
-
stripFilename: () => stripFilename,
|
|
38
|
-
unique: () => unique,
|
|
39
|
-
uniqueByKey: () => uniqueByKey,
|
|
40
|
-
withQuotes: () => withQuotes
|
|
41
|
-
});
|
|
42
|
-
module.exports = __toCommonJS(utils_exports);
|
|
43
|
-
var import_graphql = require("graphql");
|
|
44
|
-
var import_parse_filepath = __toESM(require("parse-filepath"));
|
|
45
|
-
const sep = "/";
|
|
46
|
-
function collectUsedTypes(doc) {
|
|
47
|
-
const used = [];
|
|
48
|
-
doc.definitions.forEach(findRelated);
|
|
49
|
-
function markAsUsed(type) {
|
|
50
|
-
pushUnique(used, type);
|
|
51
|
-
}
|
|
52
|
-
function findRelated(node) {
|
|
53
|
-
if (node.kind === import_graphql.Kind.OBJECT_TYPE_DEFINITION || node.kind === import_graphql.Kind.OBJECT_TYPE_EXTENSION) {
|
|
54
|
-
markAsUsed(node.name.value);
|
|
55
|
-
if (node.fields) {
|
|
56
|
-
node.fields.forEach(findRelated);
|
|
57
|
-
}
|
|
58
|
-
if (node.interfaces) {
|
|
59
|
-
node.interfaces.forEach(findRelated);
|
|
60
|
-
}
|
|
61
|
-
} else if (node.kind === import_graphql.Kind.INPUT_OBJECT_TYPE_DEFINITION || node.kind === import_graphql.Kind.INPUT_OBJECT_TYPE_EXTENSION) {
|
|
62
|
-
markAsUsed(node.name.value);
|
|
63
|
-
if (node.fields) {
|
|
64
|
-
node.fields.forEach(findRelated);
|
|
65
|
-
}
|
|
66
|
-
} else if (node.kind === import_graphql.Kind.INTERFACE_TYPE_DEFINITION || node.kind === import_graphql.Kind.INTERFACE_TYPE_EXTENSION) {
|
|
67
|
-
markAsUsed(node.name.value);
|
|
68
|
-
if (node.fields) {
|
|
69
|
-
node.fields.forEach(findRelated);
|
|
70
|
-
}
|
|
71
|
-
if (node.interfaces) {
|
|
72
|
-
node.interfaces.forEach(findRelated);
|
|
73
|
-
}
|
|
74
|
-
} else if (node.kind === import_graphql.Kind.UNION_TYPE_DEFINITION || node.kind === import_graphql.Kind.UNION_TYPE_EXTENSION) {
|
|
75
|
-
markAsUsed(node.name.value);
|
|
76
|
-
if (node.types) {
|
|
77
|
-
node.types.forEach(findRelated);
|
|
78
|
-
}
|
|
79
|
-
} else if (node.kind === import_graphql.Kind.ENUM_TYPE_DEFINITION || node.kind === import_graphql.Kind.ENUM_TYPE_EXTENSION) {
|
|
80
|
-
markAsUsed(node.name.value);
|
|
81
|
-
} else if (node.kind === import_graphql.Kind.SCALAR_TYPE_DEFINITION || node.kind === import_graphql.Kind.SCALAR_TYPE_EXTENSION) {
|
|
82
|
-
if (!isGraphQLPrimitive(node.name.value)) {
|
|
83
|
-
markAsUsed(node.name.value);
|
|
84
|
-
}
|
|
85
|
-
} else if (node.kind === import_graphql.Kind.INPUT_VALUE_DEFINITION) {
|
|
86
|
-
findRelated(resolveTypeNode(node.type));
|
|
87
|
-
} else if (node.kind === import_graphql.Kind.FIELD_DEFINITION) {
|
|
88
|
-
findRelated(resolveTypeNode(node.type));
|
|
89
|
-
if (node.arguments) {
|
|
90
|
-
node.arguments.forEach(findRelated);
|
|
91
|
-
}
|
|
92
|
-
} else if (node.kind === import_graphql.Kind.NAMED_TYPE && !isGraphQLPrimitive(node.name.value)) {
|
|
93
|
-
markAsUsed(node.name.value);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return used;
|
|
97
|
-
}
|
|
98
|
-
function resolveTypeNode(node) {
|
|
99
|
-
if (node.kind === import_graphql.Kind.LIST_TYPE) {
|
|
100
|
-
return resolveTypeNode(node.type);
|
|
101
|
-
}
|
|
102
|
-
if (node.kind === import_graphql.Kind.NON_NULL_TYPE) {
|
|
103
|
-
return resolveTypeNode(node.type);
|
|
104
|
-
}
|
|
105
|
-
return node;
|
|
106
|
-
}
|
|
107
|
-
function isGraphQLPrimitive(name) {
|
|
108
|
-
return ["String", "Boolean", "ID", "Float", "Int"].includes(name);
|
|
109
|
-
}
|
|
110
|
-
function unique(val, i, all) {
|
|
111
|
-
return i === all.indexOf(val);
|
|
112
|
-
}
|
|
113
|
-
function withQuotes(val) {
|
|
114
|
-
return `'${val}'`;
|
|
115
|
-
}
|
|
116
|
-
function indent(size) {
|
|
117
|
-
const space = new Array(size).fill(" ").join("");
|
|
118
|
-
function indentInner(val) {
|
|
119
|
-
return val.split("\n").map((line) => `${space}${line}`).join("\n");
|
|
120
|
-
}
|
|
121
|
-
return indentInner;
|
|
122
|
-
}
|
|
123
|
-
function buildBlock({
|
|
124
|
-
name,
|
|
125
|
-
lines
|
|
126
|
-
}) {
|
|
127
|
-
if (!lines.length) {
|
|
128
|
-
return "";
|
|
129
|
-
}
|
|
130
|
-
return [`${name} {`, ...lines.map(indent(2)), "};"].join("\n");
|
|
131
|
-
}
|
|
132
|
-
const getRelativePath = function(filepath, basePath) {
|
|
133
|
-
const normalizedFilepath = normalize(filepath);
|
|
134
|
-
const normalizedBasePath = ensureStartsWithSeparator(
|
|
135
|
-
normalize(ensureEndsWithSeparator(basePath))
|
|
136
|
-
);
|
|
137
|
-
const [, relativePath] = normalizedFilepath.split(normalizedBasePath);
|
|
138
|
-
return relativePath;
|
|
139
|
-
};
|
|
140
|
-
function groupSourcesByModule(sources, basePath) {
|
|
141
|
-
const grouped = {};
|
|
142
|
-
sources.forEach((source) => {
|
|
143
|
-
if (!source.location) {
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
const relativePath = getRelativePath(source.location, basePath);
|
|
147
|
-
if (relativePath) {
|
|
148
|
-
const mod = extractModuleDirectory(source.location, basePath);
|
|
149
|
-
if (!grouped[mod]) {
|
|
150
|
-
grouped[mod] = [];
|
|
151
|
-
}
|
|
152
|
-
grouped[mod].push(source);
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
return grouped;
|
|
156
|
-
}
|
|
157
|
-
function extractModuleDirectory(filepath, basePath) {
|
|
158
|
-
const relativePath = getRelativePath(filepath, basePath);
|
|
159
|
-
const [moduleDirectory] = relativePath.split(sep);
|
|
160
|
-
return moduleDirectory;
|
|
161
|
-
}
|
|
162
|
-
function stripFilename(path) {
|
|
163
|
-
const parsedPath = (0, import_parse_filepath.default)(path);
|
|
164
|
-
return normalize(parsedPath.dir);
|
|
165
|
-
}
|
|
166
|
-
function normalize(path) {
|
|
167
|
-
return path.replace(/\\/g, "/");
|
|
168
|
-
}
|
|
169
|
-
function ensureEndsWithSeparator(path) {
|
|
170
|
-
return path.endsWith(sep) ? path : path + sep;
|
|
171
|
-
}
|
|
172
|
-
function ensureStartsWithSeparator(path) {
|
|
173
|
-
return path.startsWith(".") ? path.replace(/^(..\/)|(.\/)/, "/") : path.startsWith("/") ? path : "/" + path;
|
|
174
|
-
}
|
|
175
|
-
function pushUnique(list, item) {
|
|
176
|
-
if (!list.includes(item)) {
|
|
177
|
-
list.push(item);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
function concatByKey(left, right, key) {
|
|
181
|
-
return [.../* @__PURE__ */ new Set([...left[key], ...right[key]])];
|
|
182
|
-
}
|
|
183
|
-
function uniqueByKey(left, right, key) {
|
|
184
|
-
return left[key].filter((item) => !right[key].includes(item));
|
|
185
|
-
}
|
|
186
|
-
function createObject(keys, valueFn) {
|
|
187
|
-
const obj = {};
|
|
188
|
-
keys.forEach((key) => {
|
|
189
|
-
obj[key] = valueFn(key);
|
|
190
|
-
});
|
|
191
|
-
return obj;
|
|
192
|
-
}
|
|
193
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
194
|
-
0 && (module.exports = {
|
|
195
|
-
buildBlock,
|
|
196
|
-
collectUsedTypes,
|
|
197
|
-
concatByKey,
|
|
198
|
-
createObject,
|
|
199
|
-
groupSourcesByModule,
|
|
200
|
-
indent,
|
|
201
|
-
isGraphQLPrimitive,
|
|
202
|
-
normalize,
|
|
203
|
-
pushUnique,
|
|
204
|
-
resolveTypeNode,
|
|
205
|
-
stripFilename,
|
|
206
|
-
unique,
|
|
207
|
-
uniqueByKey,
|
|
208
|
-
withQuotes
|
|
209
|
-
});
|
package/dist/modules/utils.mjs
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Kind
|
|
3
|
-
} from "graphql";
|
|
4
|
-
import parse from "parse-filepath";
|
|
5
|
-
const sep = "/";
|
|
6
|
-
function collectUsedTypes(doc) {
|
|
7
|
-
const used = [];
|
|
8
|
-
doc.definitions.forEach(findRelated);
|
|
9
|
-
function markAsUsed(type) {
|
|
10
|
-
pushUnique(used, type);
|
|
11
|
-
}
|
|
12
|
-
function findRelated(node) {
|
|
13
|
-
if (node.kind === Kind.OBJECT_TYPE_DEFINITION || node.kind === Kind.OBJECT_TYPE_EXTENSION) {
|
|
14
|
-
markAsUsed(node.name.value);
|
|
15
|
-
if (node.fields) {
|
|
16
|
-
node.fields.forEach(findRelated);
|
|
17
|
-
}
|
|
18
|
-
if (node.interfaces) {
|
|
19
|
-
node.interfaces.forEach(findRelated);
|
|
20
|
-
}
|
|
21
|
-
} else if (node.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION || node.kind === Kind.INPUT_OBJECT_TYPE_EXTENSION) {
|
|
22
|
-
markAsUsed(node.name.value);
|
|
23
|
-
if (node.fields) {
|
|
24
|
-
node.fields.forEach(findRelated);
|
|
25
|
-
}
|
|
26
|
-
} else if (node.kind === Kind.INTERFACE_TYPE_DEFINITION || node.kind === Kind.INTERFACE_TYPE_EXTENSION) {
|
|
27
|
-
markAsUsed(node.name.value);
|
|
28
|
-
if (node.fields) {
|
|
29
|
-
node.fields.forEach(findRelated);
|
|
30
|
-
}
|
|
31
|
-
if (node.interfaces) {
|
|
32
|
-
node.interfaces.forEach(findRelated);
|
|
33
|
-
}
|
|
34
|
-
} else if (node.kind === Kind.UNION_TYPE_DEFINITION || node.kind === Kind.UNION_TYPE_EXTENSION) {
|
|
35
|
-
markAsUsed(node.name.value);
|
|
36
|
-
if (node.types) {
|
|
37
|
-
node.types.forEach(findRelated);
|
|
38
|
-
}
|
|
39
|
-
} else if (node.kind === Kind.ENUM_TYPE_DEFINITION || node.kind === Kind.ENUM_TYPE_EXTENSION) {
|
|
40
|
-
markAsUsed(node.name.value);
|
|
41
|
-
} else if (node.kind === Kind.SCALAR_TYPE_DEFINITION || node.kind === Kind.SCALAR_TYPE_EXTENSION) {
|
|
42
|
-
if (!isGraphQLPrimitive(node.name.value)) {
|
|
43
|
-
markAsUsed(node.name.value);
|
|
44
|
-
}
|
|
45
|
-
} else if (node.kind === Kind.INPUT_VALUE_DEFINITION) {
|
|
46
|
-
findRelated(resolveTypeNode(node.type));
|
|
47
|
-
} else if (node.kind === Kind.FIELD_DEFINITION) {
|
|
48
|
-
findRelated(resolveTypeNode(node.type));
|
|
49
|
-
if (node.arguments) {
|
|
50
|
-
node.arguments.forEach(findRelated);
|
|
51
|
-
}
|
|
52
|
-
} else if (node.kind === Kind.NAMED_TYPE && !isGraphQLPrimitive(node.name.value)) {
|
|
53
|
-
markAsUsed(node.name.value);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return used;
|
|
57
|
-
}
|
|
58
|
-
function resolveTypeNode(node) {
|
|
59
|
-
if (node.kind === Kind.LIST_TYPE) {
|
|
60
|
-
return resolveTypeNode(node.type);
|
|
61
|
-
}
|
|
62
|
-
if (node.kind === Kind.NON_NULL_TYPE) {
|
|
63
|
-
return resolveTypeNode(node.type);
|
|
64
|
-
}
|
|
65
|
-
return node;
|
|
66
|
-
}
|
|
67
|
-
function isGraphQLPrimitive(name) {
|
|
68
|
-
return ["String", "Boolean", "ID", "Float", "Int"].includes(name);
|
|
69
|
-
}
|
|
70
|
-
function unique(val, i, all) {
|
|
71
|
-
return i === all.indexOf(val);
|
|
72
|
-
}
|
|
73
|
-
function withQuotes(val) {
|
|
74
|
-
return `'${val}'`;
|
|
75
|
-
}
|
|
76
|
-
function indent(size) {
|
|
77
|
-
const space = new Array(size).fill(" ").join("");
|
|
78
|
-
function indentInner(val) {
|
|
79
|
-
return val.split("\n").map((line) => `${space}${line}`).join("\n");
|
|
80
|
-
}
|
|
81
|
-
return indentInner;
|
|
82
|
-
}
|
|
83
|
-
function buildBlock({
|
|
84
|
-
name,
|
|
85
|
-
lines
|
|
86
|
-
}) {
|
|
87
|
-
if (!lines.length) {
|
|
88
|
-
return "";
|
|
89
|
-
}
|
|
90
|
-
return [`${name} {`, ...lines.map(indent(2)), "};"].join("\n");
|
|
91
|
-
}
|
|
92
|
-
const getRelativePath = function(filepath, basePath) {
|
|
93
|
-
const normalizedFilepath = normalize(filepath);
|
|
94
|
-
const normalizedBasePath = ensureStartsWithSeparator(
|
|
95
|
-
normalize(ensureEndsWithSeparator(basePath))
|
|
96
|
-
);
|
|
97
|
-
const [, relativePath] = normalizedFilepath.split(normalizedBasePath);
|
|
98
|
-
return relativePath;
|
|
99
|
-
};
|
|
100
|
-
function groupSourcesByModule(sources, basePath) {
|
|
101
|
-
const grouped = {};
|
|
102
|
-
sources.forEach((source) => {
|
|
103
|
-
if (!source.location) {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
const relativePath = getRelativePath(source.location, basePath);
|
|
107
|
-
if (relativePath) {
|
|
108
|
-
const mod = extractModuleDirectory(source.location, basePath);
|
|
109
|
-
if (!grouped[mod]) {
|
|
110
|
-
grouped[mod] = [];
|
|
111
|
-
}
|
|
112
|
-
grouped[mod].push(source);
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
return grouped;
|
|
116
|
-
}
|
|
117
|
-
function extractModuleDirectory(filepath, basePath) {
|
|
118
|
-
const relativePath = getRelativePath(filepath, basePath);
|
|
119
|
-
const [moduleDirectory] = relativePath.split(sep);
|
|
120
|
-
return moduleDirectory;
|
|
121
|
-
}
|
|
122
|
-
function stripFilename(path) {
|
|
123
|
-
const parsedPath = parse(path);
|
|
124
|
-
return normalize(parsedPath.dir);
|
|
125
|
-
}
|
|
126
|
-
function normalize(path) {
|
|
127
|
-
return path.replace(/\\/g, "/");
|
|
128
|
-
}
|
|
129
|
-
function ensureEndsWithSeparator(path) {
|
|
130
|
-
return path.endsWith(sep) ? path : path + sep;
|
|
131
|
-
}
|
|
132
|
-
function ensureStartsWithSeparator(path) {
|
|
133
|
-
return path.startsWith(".") ? path.replace(/^(..\/)|(.\/)/, "/") : path.startsWith("/") ? path : "/" + path;
|
|
134
|
-
}
|
|
135
|
-
function pushUnique(list, item) {
|
|
136
|
-
if (!list.includes(item)) {
|
|
137
|
-
list.push(item);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
function concatByKey(left, right, key) {
|
|
141
|
-
return [.../* @__PURE__ */ new Set([...left[key], ...right[key]])];
|
|
142
|
-
}
|
|
143
|
-
function uniqueByKey(left, right, key) {
|
|
144
|
-
return left[key].filter((item) => !right[key].includes(item));
|
|
145
|
-
}
|
|
146
|
-
function createObject(keys, valueFn) {
|
|
147
|
-
const obj = {};
|
|
148
|
-
keys.forEach((key) => {
|
|
149
|
-
obj[key] = valueFn(key);
|
|
150
|
-
});
|
|
151
|
-
return obj;
|
|
152
|
-
}
|
|
153
|
-
export {
|
|
154
|
-
buildBlock,
|
|
155
|
-
collectUsedTypes,
|
|
156
|
-
concatByKey,
|
|
157
|
-
createObject,
|
|
158
|
-
groupSourcesByModule,
|
|
159
|
-
indent,
|
|
160
|
-
isGraphQLPrimitive,
|
|
161
|
-
normalize,
|
|
162
|
-
pushUnique,
|
|
163
|
-
resolveTypeNode,
|
|
164
|
-
stripFilename,
|
|
165
|
-
unique,
|
|
166
|
-
uniqueByKey,
|
|
167
|
-
withQuotes
|
|
168
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { RawResolversConfig } from '@graphql-codegen/visitor-plugin-common';
|
|
2
|
-
|
|
3
|
-
interface TypeScriptResolversPluginConfig extends RawResolversConfig {
|
|
4
|
-
useIndexSignature?: boolean;
|
|
5
|
-
noSchemaStitching?: boolean;
|
|
6
|
-
wrapFieldDefinitions?: boolean;
|
|
7
|
-
customResolveInfo?: string;
|
|
8
|
-
customResolverFn?: string;
|
|
9
|
-
customSubscriptionResolver?: string;
|
|
10
|
-
directiveResolverMappings?: Record<string, string>;
|
|
11
|
-
allowParentTypeOverride?: boolean;
|
|
12
|
-
optionalInfoArgument?: boolean;
|
|
13
|
-
makeResolverTypeCallable?: boolean;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export { TypeScriptResolversPluginConfig };
|
package/dist/resolvers/config.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
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);
|
|
File without changes
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { PluginFunction, Types } from '@graphql-codegen/plugin-helpers';
|
|
2
|
-
export { TypeScriptResolversVisitor } from './visitor.js';
|
|
3
|
-
import { TypeScriptResolversPluginConfig } from './config.js';
|
|
4
|
-
export { TypeScriptResolversPluginConfig } from './config.js';
|
|
5
|
-
import 'graphql';
|
|
6
|
-
import '@graphql-codegen/visitor-plugin-common';
|
|
7
|
-
|
|
8
|
-
declare const plugin: PluginFunction<TypeScriptResolversPluginConfig, Types.ComplexPluginOutput>;
|
|
9
|
-
|
|
10
|
-
export { plugin };
|