@graphitation/graphql-codegen-near-operation-file-preset-with-resolver-metadata 1.1.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 ADDED
@@ -0,0 +1 @@
1
+ [{"/mnt/vss/_work/1/s/packages/graphql-codegen-near-operation-file-preset-with-resolver-metadata/src/__tests__/definitions-metadata.test.ts":"1","/mnt/vss/_work/1/s/packages/graphql-codegen-near-operation-file-preset-with-resolver-metadata/src/__tests__/near-operation-file.spec.ts":"2","/mnt/vss/_work/1/s/packages/graphql-codegen-near-operation-file-preset-with-resolver-metadata/src/definitions-metadata.ts":"3","/mnt/vss/_work/1/s/packages/graphql-codegen-near-operation-file-preset-with-resolver-metadata/src/index.ts":"4"},{"size":10642,"mtime":1753885683297,"results":"5","hashOfConfig":"6"},{"size":27474,"mtime":1753885683297,"results":"7","hashOfConfig":"6"},{"size":9699,"mtime":1753885683297,"results":"8","hashOfConfig":"6"},{"size":5325,"mtime":1753885683297,"results":"9","hashOfConfig":"6"},{"filePath":"10","messages":"11","suppressedMessages":"12","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1g2flma",{"filePath":"13","messages":"14","suppressedMessages":"15","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"16","messages":"17","suppressedMessages":"18","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"19","messages":"20","suppressedMessages":"21","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/mnt/vss/_work/1/s/packages/graphql-codegen-near-operation-file-preset-with-resolver-metadata/src/__tests__/definitions-metadata.test.ts",[],["22"],"/mnt/vss/_work/1/s/packages/graphql-codegen-near-operation-file-preset-with-resolver-metadata/src/__tests__/near-operation-file.spec.ts",[],[],"/mnt/vss/_work/1/s/packages/graphql-codegen-near-operation-file-preset-with-resolver-metadata/src/definitions-metadata.ts",[],[],"/mnt/vss/_work/1/s/packages/graphql-codegen-near-operation-file-preset-with-resolver-metadata/src/index.ts",[],[],{"ruleId":"23","severity":2,"message":"24","line":6,"column":1,"nodeType":"25","messageId":"26","endLine":6,"endColumn":34,"fix":"27","suppressions":"28"},"no-var","Unexpected var, use let or const instead.","VariableDeclaration","unexpectedVar",{"range":"29","text":"30"},["31"],[181,184],"let",{"kind":"32","justification":"33"},"directive",""]
package/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # Change Log - @graphitation/graphql-codegen-near-operation-file-preset-with-resolver-metadata
2
+
3
+ <!-- This log was last generated on Wed, 30 Jul 2025 14:38:43 GMT and should not be manually modified. -->
4
+
5
+ <!-- Start content -->
6
+
7
+ ## 1.1.0
8
+
9
+ Wed, 30 Jul 2025 14:38:43 GMT
10
+
11
+ ### Minor changes
12
+
13
+ - Wrapping near-operation-file preset and adding resolvers metadata (77059398+vejrj@users.noreply.github.com)
package/NOTICE ADDED
@@ -0,0 +1,27 @@
1
+ NOTICES
2
+
3
+ This repository incorporates material as listed below or described in the code.
4
+
5
+ graphql-code-generator
6
+
7
+ The MIT License (MIT)
8
+
9
+ Copyright (c) 2016 Dotan Simha
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # graphql-codegen-near-operation-file-preset-with-resolver-metadata
@@ -0,0 +1,19 @@
1
+ import { DocumentNode } from "graphql";
2
+ import { Types } from "@graphql-codegen/plugin-helpers";
3
+ import { SchemaDefinitions } from "@graphitation/supermassive";
4
+ import { NearOperationFileConfig } from ".";
5
+ export type ResolversPerOperation = {
6
+ [key: string]: {
7
+ [operation: string]: string[];
8
+ };
9
+ };
10
+ export type SupportedOperations = {
11
+ [rootOperationType: string]: string[];
12
+ };
13
+ export type DefinitionsMetadata = {
14
+ resolverMetadata?: Record<string, string[]>;
15
+ supportedOperations?: SupportedOperations;
16
+ schemaMetadata?: SchemaDefinitions;
17
+ };
18
+ export declare function getDefinitionsMetadata(documents: DocumentNode[], options: Types.PresetFnArgs<NearOperationFileConfig>): DefinitionsMetadata | null;
19
+ //# sourceMappingURL=definitions-metadata.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definitions-metadata.d.ts","sourceRoot":"","sources":["../src/definitions-metadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,YAAY,EAAE,MAAM,SAAS,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,iCAAiC,CAAC;AACxD,OAAO,EAGL,iBAAiB,EAElB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,uBAAuB,EAAsB,MAAM,GAAG,CAAC;AAEhE,MAAM,MAAM,qBAAqB,GAAG;IAClC,CAAC,GAAG,EAAE,MAAM,GAAG;QACb,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;KAC/B,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAAE,CAAC,iBAAiB,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;CAAE,CAAC;AAC5E,MAAM,MAAM,mBAAmB,GAAG;IAChC,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC5C,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;IAC1C,cAAc,CAAC,EAAE,iBAAiB,CAAC;CACpC,CAAC;AAEF,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,YAAY,EAAE,EACzB,OAAO,EAAE,KAAK,CAAC,YAAY,CAAC,uBAAuB,CAAC,8BA6IrD"}
@@ -0,0 +1,278 @@
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 definitions_metadata_exports = {};
20
+ __export(definitions_metadata_exports, {
21
+ getDefinitionsMetadata: () => getDefinitionsMetadata
22
+ });
23
+ module.exports = __toCommonJS(definitions_metadata_exports);
24
+ var import_graphql = require("graphql");
25
+ var import_supermassive = require("@graphitation/supermassive");
26
+ function getDefinitionsMetadata(documents, options) {
27
+ var _a;
28
+ const {
29
+ supportedResolvers,
30
+ supportedOperations: configSupportedOperations,
31
+ usedResolversMetadataDirectoryPath
32
+ } = options.presetConfig;
33
+ const schema = options.schemaAst || (0, import_graphql.buildASTSchema)(options.schema);
34
+ if (usedResolversMetadataDirectoryPath) {
35
+ const supportedOperations = configSupportedOperations || {};
36
+ if (!Object.keys(supportedOperations).length && supportedResolvers) {
37
+ for (const document of documents) {
38
+ if (!document) {
39
+ continue;
40
+ }
41
+ for (const definition of document.definitions) {
42
+ if (definition.kind === "OperationDefinition") {
43
+ definition.selectionSet.selections.forEach((selection) => {
44
+ var _a2, _b;
45
+ if (selection.kind === "Field" && existsInSupportedResolvers(
46
+ supportedResolvers,
47
+ selection.name.value,
48
+ definition.operation
49
+ )) {
50
+ const { operation } = definition;
51
+ if (!supportedOperations[operation]) {
52
+ supportedOperations[operation] = [];
53
+ }
54
+ if (((_a2 = definition.name) == null ? void 0 : _a2.value) && !supportedOperations[operation].includes(
55
+ definition.name.value
56
+ )) {
57
+ supportedOperations[operation].push((_b = definition.name) == null ? void 0 : _b.value);
58
+ }
59
+ }
60
+ });
61
+ }
62
+ }
63
+ }
64
+ }
65
+ const operationDefinitions = {};
66
+ const fragmentDefinitions = {};
67
+ for (const document of documents) {
68
+ if (!document) {
69
+ continue;
70
+ }
71
+ for (const definition of document.definitions) {
72
+ switch (definition.kind) {
73
+ case "OperationDefinition": {
74
+ if (!definition.name) {
75
+ throw Error("Operation should have a name");
76
+ }
77
+ if (!((_a = supportedOperations[definition.operation]) == null ? void 0 : _a.includes(
78
+ definition.name.value
79
+ ))) {
80
+ break;
81
+ }
82
+ operationDefinitions[definition.name.value] = (0, import_supermassive.extractMinimalViableSchemaForRequestDocument)(schema, {
83
+ kind: "Document",
84
+ definitions: [definition]
85
+ });
86
+ break;
87
+ }
88
+ case "FragmentDefinition": {
89
+ fragmentDefinitions[definition.name.value] = (0, import_supermassive.extractMinimalViableSchemaForRequestDocument)(schema, {
90
+ kind: "Document",
91
+ definitions: [definition]
92
+ });
93
+ break;
94
+ }
95
+ default: {
96
+ break;
97
+ }
98
+ }
99
+ }
100
+ }
101
+ const { fragmentSpreadMap } = getTraverseMetadata(
102
+ operationDefinitions,
103
+ fragmentDefinitions
104
+ );
105
+ const usedFragmentDefinitions = {};
106
+ for (const [key, value] of Object.entries(fragmentDefinitions)) {
107
+ for (const fragmentSpreadValues of Object.values(fragmentSpreadMap)) {
108
+ if (fragmentSpreadValues.includes(key)) {
109
+ usedFragmentDefinitions[key] = value;
110
+ }
111
+ }
112
+ }
113
+ const mergedDefinitions = (0, import_supermassive.mergeSchemaDefinitions)({ types: {} }, [
114
+ ...Object.values(operationDefinitions).map((item) => item.definitions),
115
+ ...Object.values(usedFragmentDefinitions).map((item) => item.definitions)
116
+ ]);
117
+ const resolverMetadata = getResolverMetadata(mergedDefinitions);
118
+ const output = {};
119
+ if (Object.keys(supportedOperations).length) {
120
+ output.supportedOperations = supportedOperations;
121
+ }
122
+ if (Object.keys(resolverMetadata).length) {
123
+ output.resolverMetadata = resolverMetadata;
124
+ }
125
+ output.schemaMetadata = mergedDefinitions;
126
+ return output;
127
+ }
128
+ return null;
129
+ }
130
+ const TypeKind = {
131
+ SCALAR: 1,
132
+ OBJECT: 2,
133
+ INTERFACE: 3,
134
+ UNION: 4,
135
+ ENUM: 5,
136
+ INPUT: 6
137
+ };
138
+ function getResolverMetadata(mergedDefinitions) {
139
+ var _a, _b, _c, _d, _e;
140
+ const resolverMetadata = {};
141
+ const interfaceFields = {};
142
+ for (const [type, [typeKind, fields]] of Object.entries(
143
+ mergedDefinitions.types
144
+ )) {
145
+ if (typeKind === TypeKind.INTERFACE) {
146
+ for (const field of Object.keys(fields != null ? fields : {})) {
147
+ (_a = interfaceFields[type]) != null ? _a : interfaceFields[type] = [];
148
+ if (!interfaceFields[type].includes(field)) {
149
+ interfaceFields[type].push(field);
150
+ }
151
+ }
152
+ }
153
+ }
154
+ for (const [type, [typeKind, fields, interfaces]] of Object.entries(
155
+ mergedDefinitions.types
156
+ )) {
157
+ if (typeKind === TypeKind.ENUM) {
158
+ continue;
159
+ }
160
+ if (typeKind === TypeKind.UNION) {
161
+ (_b = resolverMetadata[type]) != null ? _b : resolverMetadata[type] = [];
162
+ if (!resolverMetadata[type].includes("__resolveType")) {
163
+ resolverMetadata[type].push("__resolveType");
164
+ }
165
+ continue;
166
+ }
167
+ if (typeKind === TypeKind.INTERFACE) {
168
+ (_c = resolverMetadata[type]) != null ? _c : resolverMetadata[type] = [];
169
+ if (!resolverMetadata[type].includes("__resolveType")) {
170
+ resolverMetadata[type].push("__resolveType");
171
+ }
172
+ continue;
173
+ }
174
+ for (const field of Object.keys(fields != null ? fields : {})) {
175
+ (_d = resolverMetadata[type]) != null ? _d : resolverMetadata[type] = [];
176
+ if (!resolverMetadata[type].includes(field)) {
177
+ resolverMetadata[type].push(field);
178
+ }
179
+ }
180
+ if (interfaces == null ? void 0 : interfaces.length) {
181
+ for (const interfaceName of interfaces) {
182
+ const fields2 = interfaceFields[interfaceName];
183
+ if (!fields2) {
184
+ continue;
185
+ }
186
+ for (const field of fields2) {
187
+ (_e = resolverMetadata[type]) != null ? _e : resolverMetadata[type] = [];
188
+ if (!resolverMetadata[type].includes(field)) {
189
+ resolverMetadata[type].push(field);
190
+ }
191
+ }
192
+ }
193
+ }
194
+ }
195
+ return resolverMetadata;
196
+ }
197
+ function getTraverseMetadata(operationDefinitions, fragmentDefinitions) {
198
+ const fragmentSpreadMap = {};
199
+ const fragmentSpreadsUsed = {};
200
+ for (const [definitionName, { fragmentSpreads }] of Object.entries(
201
+ operationDefinitions
202
+ )) {
203
+ fragmentSpreads.map((value) => {
204
+ var _a;
205
+ (_a = fragmentSpreadMap[definitionName]) != null ? _a : fragmentSpreadMap[definitionName] = [];
206
+ fragmentSpreadMap[definitionName].push(value);
207
+ if (fragmentSpreadsUsed[value] === void 0) {
208
+ fragmentSpreadsUsed[value] = false;
209
+ }
210
+ });
211
+ }
212
+ collectFragmentSpreads(
213
+ fragmentDefinitions,
214
+ fragmentSpreadMap,
215
+ fragmentSpreadsUsed
216
+ );
217
+ for (const [key, value] of Object.entries(fragmentSpreadsUsed)) {
218
+ if (!value) {
219
+ throw new Error(`Fragment "${key}" was not visited`);
220
+ }
221
+ if (!fragmentSpreadMap[key]) {
222
+ console.log(fragmentSpreadMap, fragmentSpreadsUsed);
223
+ throw new Error(`Something wrong during visit of fragment ${key}`);
224
+ }
225
+ }
226
+ return {
227
+ fragmentSpreadMap
228
+ };
229
+ }
230
+ function collectFragmentSpreads(fragmentDefinitions, fragmentSpreadMap, fragmentSpreadsUsed) {
231
+ var _a, _b;
232
+ if (Object.values(fragmentSpreadsUsed).every(Boolean)) {
233
+ return;
234
+ }
235
+ const localFragmentSpreads = /* @__PURE__ */ new Set();
236
+ for (const [key, value] of Object.entries(fragmentSpreadsUsed)) {
237
+ if (value) {
238
+ continue;
239
+ }
240
+ const definition = fragmentDefinitions[key];
241
+ fragmentSpreadsUsed[key] = true;
242
+ if (!definition.fragmentSpreads.length) {
243
+ (_a = fragmentSpreadMap[key]) != null ? _a : fragmentSpreadMap[key] = [];
244
+ }
245
+ for (const fragmentSpread of definition.fragmentSpreads) {
246
+ localFragmentSpreads.add(fragmentSpread);
247
+ (_b = fragmentSpreadMap[key]) != null ? _b : fragmentSpreadMap[key] = [];
248
+ fragmentSpreadMap[key].push(fragmentSpread);
249
+ }
250
+ }
251
+ if (!localFragmentSpreads.size) {
252
+ return;
253
+ }
254
+ for (const localFragmentSpread of localFragmentSpreads) {
255
+ if (typeof fragmentSpreadsUsed[localFragmentSpread] === "boolean") {
256
+ continue;
257
+ }
258
+ fragmentSpreadsUsed[localFragmentSpread] = false;
259
+ }
260
+ return collectFragmentSpreads(
261
+ fragmentDefinitions,
262
+ fragmentSpreadMap,
263
+ fragmentSpreadsUsed
264
+ );
265
+ }
266
+ function existsInSupportedResolvers({ supportedResolvers }, resolverName, operationName) {
267
+ if (!supportedResolvers || !supportedResolvers.configs) {
268
+ return false;
269
+ }
270
+ return supportedResolvers.configs.some((config) => {
271
+ if (config.value && config.value[operationName]) {
272
+ const resolvers = config.value[operationName];
273
+ if (resolvers.includes(resolverName)) {
274
+ return true;
275
+ }
276
+ }
277
+ });
278
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/definitions-metadata.ts"],
4
+ "sourcesContent": ["import { buildASTSchema, DocumentNode } from \"graphql\";\nimport { Types } from \"@graphql-codegen/plugin-helpers\";\nimport {\n extractMinimalViableSchemaForRequestDocument,\n mergeSchemaDefinitions,\n SchemaDefinitions,\n type ExtractMinimalViableSchemaResult,\n} from \"@graphitation/supermassive\";\nimport { NearOperationFileConfig, SupportedResolvers } from \".\";\n\nexport type ResolversPerOperation = {\n [key: string]: {\n [operation: string]: string[];\n };\n};\n\nexport type SupportedOperations = { [rootOperationType: string]: string[] };\nexport type DefinitionsMetadata = {\n resolverMetadata?: Record<string, string[]>;\n supportedOperations?: SupportedOperations;\n schemaMetadata?: SchemaDefinitions;\n};\n\nexport function getDefinitionsMetadata(\n documents: DocumentNode[],\n options: Types.PresetFnArgs<NearOperationFileConfig>,\n) {\n const {\n supportedResolvers,\n supportedOperations: configSupportedOperations,\n usedResolversMetadataDirectoryPath,\n } = options.presetConfig;\n const schema = options.schemaAst || buildASTSchema(options.schema);\n if (usedResolversMetadataDirectoryPath) {\n const supportedOperations: SupportedOperations =\n configSupportedOperations || {};\n\n if (!Object.keys(supportedOperations).length && supportedResolvers) {\n for (const document of documents) {\n if (!document) {\n continue;\n }\n\n for (const definition of document.definitions) {\n if (definition.kind === \"OperationDefinition\") {\n definition.selectionSet.selections.forEach((selection) => {\n if (\n selection.kind === \"Field\" &&\n existsInSupportedResolvers(\n supportedResolvers,\n selection.name.value,\n definition.operation,\n )\n ) {\n const { operation } = definition;\n if (!supportedOperations[operation]) {\n supportedOperations[operation] = [];\n }\n\n if (\n definition.name?.value &&\n !supportedOperations[operation].includes(\n definition.name.value,\n )\n ) {\n supportedOperations[operation].push(definition.name?.value);\n }\n }\n });\n }\n }\n }\n }\n\n const operationDefinitions: Record<\n string,\n ExtractMinimalViableSchemaResult\n > = {};\n const fragmentDefinitions: Record<\n string,\n ExtractMinimalViableSchemaResult\n > = {};\n\n for (const document of documents) {\n if (!document) {\n continue;\n }\n\n for (const definition of document.definitions) {\n switch (definition.kind) {\n case \"OperationDefinition\": {\n if (!definition.name) {\n throw Error(\"Operation should have a name\");\n }\n\n if (\n !supportedOperations[definition.operation]?.includes(\n definition.name.value,\n )\n ) {\n break;\n }\n\n operationDefinitions[definition.name.value] =\n extractMinimalViableSchemaForRequestDocument(schema, {\n kind: \"Document\",\n definitions: [definition],\n });\n break;\n }\n case \"FragmentDefinition\": {\n fragmentDefinitions[definition.name.value] =\n extractMinimalViableSchemaForRequestDocument(schema, {\n kind: \"Document\",\n definitions: [definition],\n });\n\n break;\n }\n default: {\n break;\n }\n }\n }\n }\n\n const { fragmentSpreadMap } = getTraverseMetadata(\n operationDefinitions,\n fragmentDefinitions,\n );\n\n const usedFragmentDefinitions: Record<\n string,\n ExtractMinimalViableSchemaResult\n > = {};\n\n for (const [key, value] of Object.entries(fragmentDefinitions)) {\n for (const fragmentSpreadValues of Object.values(fragmentSpreadMap)) {\n if (fragmentSpreadValues.includes(key)) {\n usedFragmentDefinitions[key] = value;\n }\n }\n }\n\n const mergedDefinitions = mergeSchemaDefinitions({ types: {} }, [\n ...Object.values(operationDefinitions).map((item) => item.definitions),\n ...Object.values(usedFragmentDefinitions).map((item) => item.definitions),\n ]);\n\n const resolverMetadata = getResolverMetadata(mergedDefinitions);\n const output: DefinitionsMetadata = {};\n\n if (Object.keys(supportedOperations).length) {\n output.supportedOperations = supportedOperations;\n }\n\n if (Object.keys(resolverMetadata).length) {\n output.resolverMetadata = resolverMetadata;\n }\n\n output.schemaMetadata = mergedDefinitions;\n\n return output;\n }\n\n return null;\n}\n\nconst TypeKind = {\n SCALAR: 1,\n OBJECT: 2,\n INTERFACE: 3,\n UNION: 4,\n ENUM: 5,\n INPUT: 6,\n} as const;\n\nfunction getResolverMetadata(mergedDefinitions: SchemaDefinitions) {\n const resolverMetadata: Record<string, string[]> = {};\n\n const interfaceFields: Record<string, string[]> = {};\n for (const [type, [typeKind, fields]] of Object.entries(\n mergedDefinitions.types,\n )) {\n if (typeKind === TypeKind.INTERFACE) {\n for (const field of Object.keys(fields ?? {})) {\n interfaceFields[type] ??= [];\n if (!interfaceFields[type].includes(field)) {\n interfaceFields[type].push(field);\n }\n }\n }\n }\n\n for (const [type, [typeKind, fields, interfaces]] of Object.entries(\n mergedDefinitions.types,\n )) {\n if (typeKind === TypeKind.ENUM) {\n continue;\n }\n if (typeKind === TypeKind.UNION) {\n resolverMetadata[type] ??= [];\n if (!resolverMetadata[type].includes(\"__resolveType\")) {\n resolverMetadata[type].push(\"__resolveType\");\n }\n continue;\n }\n\n if (typeKind === TypeKind.INTERFACE) {\n resolverMetadata[type] ??= [];\n if (!resolverMetadata[type].includes(\"__resolveType\")) {\n resolverMetadata[type].push(\"__resolveType\");\n }\n continue;\n }\n\n for (const field of Object.keys(fields ?? {})) {\n resolverMetadata[type] ??= [];\n if (!resolverMetadata[type].includes(field)) {\n resolverMetadata[type].push(field);\n }\n }\n\n if (interfaces?.length) {\n for (const interfaceName of interfaces) {\n const fields = interfaceFields[interfaceName];\n if (!fields) {\n continue;\n }\n for (const field of fields) {\n resolverMetadata[type] ??= [];\n if (!resolverMetadata[type].includes(field)) {\n resolverMetadata[type].push(field);\n }\n }\n }\n }\n }\n\n return resolverMetadata;\n}\n\nfunction getTraverseMetadata(\n operationDefinitions: Record<string, ExtractMinimalViableSchemaResult>,\n fragmentDefinitions: Record<string, ExtractMinimalViableSchemaResult>,\n) {\n const fragmentSpreadMap: Record<string, string[]> = {};\n const fragmentSpreadsUsed: Record<string, boolean> = {};\n for (const [definitionName, { fragmentSpreads }] of Object.entries(\n operationDefinitions,\n )) {\n fragmentSpreads.map((value) => {\n fragmentSpreadMap[definitionName] ??= [];\n\n fragmentSpreadMap[definitionName].push(value);\n if (fragmentSpreadsUsed[value] === undefined) {\n fragmentSpreadsUsed[value] = false;\n }\n });\n }\n\n collectFragmentSpreads(\n fragmentDefinitions,\n fragmentSpreadMap,\n fragmentSpreadsUsed,\n );\n\n // Validation that everyFragment in spread visited its implementation\n for (const [key, value] of Object.entries(fragmentSpreadsUsed)) {\n if (!value) {\n throw new Error(`Fragment \"${key}\" was not visited`);\n }\n\n if (!fragmentSpreadMap[key]) {\n console.log(fragmentSpreadMap, fragmentSpreadsUsed);\n throw new Error(`Something wrong during visit of fragment ${key}`);\n }\n }\n\n return {\n fragmentSpreadMap,\n };\n}\n\nfunction collectFragmentSpreads(\n fragmentDefinitions: Record<string, ExtractMinimalViableSchemaResult>,\n fragmentSpreadMap: Record<string, string[]>,\n fragmentSpreadsUsed: Record<string, boolean>,\n) {\n if (Object.values(fragmentSpreadsUsed).every(Boolean)) {\n return;\n }\n\n const localFragmentSpreads = new Set<string>();\n for (const [key, value] of Object.entries(fragmentSpreadsUsed)) {\n if (value) {\n continue;\n }\n\n const definition = fragmentDefinitions[key];\n fragmentSpreadsUsed[key] = true;\n if (!definition.fragmentSpreads.length) {\n fragmentSpreadMap[key] ??= [];\n }\n\n for (const fragmentSpread of definition.fragmentSpreads) {\n localFragmentSpreads.add(fragmentSpread);\n\n fragmentSpreadMap[key] ??= [];\n\n fragmentSpreadMap[key].push(fragmentSpread);\n }\n }\n\n if (!localFragmentSpreads.size) {\n return;\n }\n\n for (const localFragmentSpread of localFragmentSpreads) {\n if (typeof fragmentSpreadsUsed[localFragmentSpread] === \"boolean\") {\n continue;\n }\n\n fragmentSpreadsUsed[localFragmentSpread] = false;\n }\n\n return collectFragmentSpreads(\n fragmentDefinitions,\n fragmentSpreadMap,\n fragmentSpreadsUsed,\n );\n}\n\nfunction existsInSupportedResolvers(\n { supportedResolvers }: SupportedResolvers,\n resolverName: string,\n operationName: string,\n): boolean {\n if (!supportedResolvers || !supportedResolvers.configs) {\n return false;\n }\n\n return supportedResolvers.configs.some((config) => {\n if (config.value && config.value[operationName]) {\n const resolvers = config.value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 "names": ["_a", "fields"]
7
+ }
@@ -0,0 +1,262 @@
1
+ // src/definitions-metadata.ts
2
+ import { buildASTSchema } from "graphql";
3
+ import {
4
+ extractMinimalViableSchemaForRequestDocument,
5
+ mergeSchemaDefinitions
6
+ } from "@graphitation/supermassive";
7
+ function getDefinitionsMetadata(documents, options) {
8
+ var _a;
9
+ const {
10
+ supportedResolvers,
11
+ supportedOperations: configSupportedOperations,
12
+ usedResolversMetadataDirectoryPath
13
+ } = options.presetConfig;
14
+ const schema = options.schemaAst || buildASTSchema(options.schema);
15
+ if (usedResolversMetadataDirectoryPath) {
16
+ const supportedOperations = configSupportedOperations || {};
17
+ if (!Object.keys(supportedOperations).length && supportedResolvers) {
18
+ for (const document of documents) {
19
+ if (!document) {
20
+ continue;
21
+ }
22
+ for (const definition of document.definitions) {
23
+ if (definition.kind === "OperationDefinition") {
24
+ definition.selectionSet.selections.forEach((selection) => {
25
+ var _a2, _b;
26
+ if (selection.kind === "Field" && existsInSupportedResolvers(
27
+ supportedResolvers,
28
+ selection.name.value,
29
+ definition.operation
30
+ )) {
31
+ const { operation } = definition;
32
+ if (!supportedOperations[operation]) {
33
+ supportedOperations[operation] = [];
34
+ }
35
+ if (((_a2 = definition.name) == null ? void 0 : _a2.value) && !supportedOperations[operation].includes(
36
+ definition.name.value
37
+ )) {
38
+ supportedOperations[operation].push((_b = definition.name) == null ? void 0 : _b.value);
39
+ }
40
+ }
41
+ });
42
+ }
43
+ }
44
+ }
45
+ }
46
+ const operationDefinitions = {};
47
+ const fragmentDefinitions = {};
48
+ for (const document of documents) {
49
+ if (!document) {
50
+ continue;
51
+ }
52
+ for (const definition of document.definitions) {
53
+ switch (definition.kind) {
54
+ case "OperationDefinition": {
55
+ if (!definition.name) {
56
+ throw Error("Operation should have a name");
57
+ }
58
+ if (!((_a = supportedOperations[definition.operation]) == null ? void 0 : _a.includes(
59
+ definition.name.value
60
+ ))) {
61
+ break;
62
+ }
63
+ operationDefinitions[definition.name.value] = extractMinimalViableSchemaForRequestDocument(schema, {
64
+ kind: "Document",
65
+ definitions: [definition]
66
+ });
67
+ break;
68
+ }
69
+ case "FragmentDefinition": {
70
+ fragmentDefinitions[definition.name.value] = extractMinimalViableSchemaForRequestDocument(schema, {
71
+ kind: "Document",
72
+ definitions: [definition]
73
+ });
74
+ break;
75
+ }
76
+ default: {
77
+ break;
78
+ }
79
+ }
80
+ }
81
+ }
82
+ const { fragmentSpreadMap } = getTraverseMetadata(
83
+ operationDefinitions,
84
+ fragmentDefinitions
85
+ );
86
+ const usedFragmentDefinitions = {};
87
+ for (const [key, value] of Object.entries(fragmentDefinitions)) {
88
+ for (const fragmentSpreadValues of Object.values(fragmentSpreadMap)) {
89
+ if (fragmentSpreadValues.includes(key)) {
90
+ usedFragmentDefinitions[key] = value;
91
+ }
92
+ }
93
+ }
94
+ const mergedDefinitions = mergeSchemaDefinitions({ types: {} }, [
95
+ ...Object.values(operationDefinitions).map((item) => item.definitions),
96
+ ...Object.values(usedFragmentDefinitions).map((item) => item.definitions)
97
+ ]);
98
+ const resolverMetadata = getResolverMetadata(mergedDefinitions);
99
+ const output = {};
100
+ if (Object.keys(supportedOperations).length) {
101
+ output.supportedOperations = supportedOperations;
102
+ }
103
+ if (Object.keys(resolverMetadata).length) {
104
+ output.resolverMetadata = resolverMetadata;
105
+ }
106
+ output.schemaMetadata = mergedDefinitions;
107
+ return output;
108
+ }
109
+ return null;
110
+ }
111
+ var TypeKind = {
112
+ SCALAR: 1,
113
+ OBJECT: 2,
114
+ INTERFACE: 3,
115
+ UNION: 4,
116
+ ENUM: 5,
117
+ INPUT: 6
118
+ };
119
+ function getResolverMetadata(mergedDefinitions) {
120
+ var _a, _b, _c, _d, _e;
121
+ const resolverMetadata = {};
122
+ const interfaceFields = {};
123
+ for (const [type, [typeKind, fields]] of Object.entries(
124
+ mergedDefinitions.types
125
+ )) {
126
+ if (typeKind === TypeKind.INTERFACE) {
127
+ for (const field of Object.keys(fields != null ? fields : {})) {
128
+ (_a = interfaceFields[type]) != null ? _a : interfaceFields[type] = [];
129
+ if (!interfaceFields[type].includes(field)) {
130
+ interfaceFields[type].push(field);
131
+ }
132
+ }
133
+ }
134
+ }
135
+ for (const [type, [typeKind, fields, interfaces]] of Object.entries(
136
+ mergedDefinitions.types
137
+ )) {
138
+ if (typeKind === TypeKind.ENUM) {
139
+ continue;
140
+ }
141
+ if (typeKind === TypeKind.UNION) {
142
+ (_b = resolverMetadata[type]) != null ? _b : resolverMetadata[type] = [];
143
+ if (!resolverMetadata[type].includes("__resolveType")) {
144
+ resolverMetadata[type].push("__resolveType");
145
+ }
146
+ continue;
147
+ }
148
+ if (typeKind === TypeKind.INTERFACE) {
149
+ (_c = resolverMetadata[type]) != null ? _c : resolverMetadata[type] = [];
150
+ if (!resolverMetadata[type].includes("__resolveType")) {
151
+ resolverMetadata[type].push("__resolveType");
152
+ }
153
+ continue;
154
+ }
155
+ for (const field of Object.keys(fields != null ? fields : {})) {
156
+ (_d = resolverMetadata[type]) != null ? _d : resolverMetadata[type] = [];
157
+ if (!resolverMetadata[type].includes(field)) {
158
+ resolverMetadata[type].push(field);
159
+ }
160
+ }
161
+ if (interfaces == null ? void 0 : interfaces.length) {
162
+ for (const interfaceName of interfaces) {
163
+ const fields2 = interfaceFields[interfaceName];
164
+ if (!fields2) {
165
+ continue;
166
+ }
167
+ for (const field of fields2) {
168
+ (_e = resolverMetadata[type]) != null ? _e : resolverMetadata[type] = [];
169
+ if (!resolverMetadata[type].includes(field)) {
170
+ resolverMetadata[type].push(field);
171
+ }
172
+ }
173
+ }
174
+ }
175
+ }
176
+ return resolverMetadata;
177
+ }
178
+ function getTraverseMetadata(operationDefinitions, fragmentDefinitions) {
179
+ const fragmentSpreadMap = {};
180
+ const fragmentSpreadsUsed = {};
181
+ for (const [definitionName, { fragmentSpreads }] of Object.entries(
182
+ operationDefinitions
183
+ )) {
184
+ fragmentSpreads.map((value) => {
185
+ var _a;
186
+ (_a = fragmentSpreadMap[definitionName]) != null ? _a : fragmentSpreadMap[definitionName] = [];
187
+ fragmentSpreadMap[definitionName].push(value);
188
+ if (fragmentSpreadsUsed[value] === void 0) {
189
+ fragmentSpreadsUsed[value] = false;
190
+ }
191
+ });
192
+ }
193
+ collectFragmentSpreads(
194
+ fragmentDefinitions,
195
+ fragmentSpreadMap,
196
+ fragmentSpreadsUsed
197
+ );
198
+ for (const [key, value] of Object.entries(fragmentSpreadsUsed)) {
199
+ if (!value) {
200
+ throw new Error(`Fragment "${key}" was not visited`);
201
+ }
202
+ if (!fragmentSpreadMap[key]) {
203
+ console.log(fragmentSpreadMap, fragmentSpreadsUsed);
204
+ throw new Error(`Something wrong during visit of fragment ${key}`);
205
+ }
206
+ }
207
+ return {
208
+ fragmentSpreadMap
209
+ };
210
+ }
211
+ function collectFragmentSpreads(fragmentDefinitions, fragmentSpreadMap, fragmentSpreadsUsed) {
212
+ var _a, _b;
213
+ if (Object.values(fragmentSpreadsUsed).every(Boolean)) {
214
+ return;
215
+ }
216
+ const localFragmentSpreads = /* @__PURE__ */ new Set();
217
+ for (const [key, value] of Object.entries(fragmentSpreadsUsed)) {
218
+ if (value) {
219
+ continue;
220
+ }
221
+ const definition = fragmentDefinitions[key];
222
+ fragmentSpreadsUsed[key] = true;
223
+ if (!definition.fragmentSpreads.length) {
224
+ (_a = fragmentSpreadMap[key]) != null ? _a : fragmentSpreadMap[key] = [];
225
+ }
226
+ for (const fragmentSpread of definition.fragmentSpreads) {
227
+ localFragmentSpreads.add(fragmentSpread);
228
+ (_b = fragmentSpreadMap[key]) != null ? _b : fragmentSpreadMap[key] = [];
229
+ fragmentSpreadMap[key].push(fragmentSpread);
230
+ }
231
+ }
232
+ if (!localFragmentSpreads.size) {
233
+ return;
234
+ }
235
+ for (const localFragmentSpread of localFragmentSpreads) {
236
+ if (typeof fragmentSpreadsUsed[localFragmentSpread] === "boolean") {
237
+ continue;
238
+ }
239
+ fragmentSpreadsUsed[localFragmentSpread] = false;
240
+ }
241
+ return collectFragmentSpreads(
242
+ fragmentDefinitions,
243
+ fragmentSpreadMap,
244
+ fragmentSpreadsUsed
245
+ );
246
+ }
247
+ function existsInSupportedResolvers({ supportedResolvers }, resolverName, operationName) {
248
+ if (!supportedResolvers || !supportedResolvers.configs) {
249
+ return false;
250
+ }
251
+ return supportedResolvers.configs.some((config) => {
252
+ if (config.value && config.value[operationName]) {
253
+ const resolvers = config.value[operationName];
254
+ if (resolvers.includes(resolverName)) {
255
+ return true;
256
+ }
257
+ }
258
+ });
259
+ }
260
+ export {
261
+ getDefinitionsMetadata
262
+ };
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/definitions-metadata.ts"],
4
+ "sourcesContent": ["import { buildASTSchema, DocumentNode } from \"graphql\";\nimport { Types } from \"@graphql-codegen/plugin-helpers\";\nimport {\n extractMinimalViableSchemaForRequestDocument,\n mergeSchemaDefinitions,\n SchemaDefinitions,\n type ExtractMinimalViableSchemaResult,\n} from \"@graphitation/supermassive\";\nimport { NearOperationFileConfig, SupportedResolvers } from \".\";\n\nexport type ResolversPerOperation = {\n [key: string]: {\n [operation: string]: string[];\n };\n};\n\nexport type SupportedOperations = { [rootOperationType: string]: string[] };\nexport type DefinitionsMetadata = {\n resolverMetadata?: Record<string, string[]>;\n supportedOperations?: SupportedOperations;\n schemaMetadata?: SchemaDefinitions;\n};\n\nexport function getDefinitionsMetadata(\n documents: DocumentNode[],\n options: Types.PresetFnArgs<NearOperationFileConfig>,\n) {\n const {\n supportedResolvers,\n supportedOperations: configSupportedOperations,\n usedResolversMetadataDirectoryPath,\n } = options.presetConfig;\n const schema = options.schemaAst || buildASTSchema(options.schema);\n if (usedResolversMetadataDirectoryPath) {\n const supportedOperations: SupportedOperations =\n configSupportedOperations || {};\n\n if (!Object.keys(supportedOperations).length && supportedResolvers) {\n for (const document of documents) {\n if (!document) {\n continue;\n }\n\n for (const definition of document.definitions) {\n if (definition.kind === \"OperationDefinition\") {\n definition.selectionSet.selections.forEach((selection) => {\n if (\n selection.kind === \"Field\" &&\n existsInSupportedResolvers(\n supportedResolvers,\n selection.name.value,\n definition.operation,\n )\n ) {\n const { operation } = definition;\n if (!supportedOperations[operation]) {\n supportedOperations[operation] = [];\n }\n\n if (\n definition.name?.value &&\n !supportedOperations[operation].includes(\n definition.name.value,\n )\n ) {\n supportedOperations[operation].push(definition.name?.value);\n }\n }\n });\n }\n }\n }\n }\n\n const operationDefinitions: Record<\n string,\n ExtractMinimalViableSchemaResult\n > = {};\n const fragmentDefinitions: Record<\n string,\n ExtractMinimalViableSchemaResult\n > = {};\n\n for (const document of documents) {\n if (!document) {\n continue;\n }\n\n for (const definition of document.definitions) {\n switch (definition.kind) {\n case \"OperationDefinition\": {\n if (!definition.name) {\n throw Error(\"Operation should have a name\");\n }\n\n if (\n !supportedOperations[definition.operation]?.includes(\n definition.name.value,\n )\n ) {\n break;\n }\n\n operationDefinitions[definition.name.value] =\n extractMinimalViableSchemaForRequestDocument(schema, {\n kind: \"Document\",\n definitions: [definition],\n });\n break;\n }\n case \"FragmentDefinition\": {\n fragmentDefinitions[definition.name.value] =\n extractMinimalViableSchemaForRequestDocument(schema, {\n kind: \"Document\",\n definitions: [definition],\n });\n\n break;\n }\n default: {\n break;\n }\n }\n }\n }\n\n const { fragmentSpreadMap } = getTraverseMetadata(\n operationDefinitions,\n fragmentDefinitions,\n );\n\n const usedFragmentDefinitions: Record<\n string,\n ExtractMinimalViableSchemaResult\n > = {};\n\n for (const [key, value] of Object.entries(fragmentDefinitions)) {\n for (const fragmentSpreadValues of Object.values(fragmentSpreadMap)) {\n if (fragmentSpreadValues.includes(key)) {\n usedFragmentDefinitions[key] = value;\n }\n }\n }\n\n const mergedDefinitions = mergeSchemaDefinitions({ types: {} }, [\n ...Object.values(operationDefinitions).map((item) => item.definitions),\n ...Object.values(usedFragmentDefinitions).map((item) => item.definitions),\n ]);\n\n const resolverMetadata = getResolverMetadata(mergedDefinitions);\n const output: DefinitionsMetadata = {};\n\n if (Object.keys(supportedOperations).length) {\n output.supportedOperations = supportedOperations;\n }\n\n if (Object.keys(resolverMetadata).length) {\n output.resolverMetadata = resolverMetadata;\n }\n\n output.schemaMetadata = mergedDefinitions;\n\n return output;\n }\n\n return null;\n}\n\nconst TypeKind = {\n SCALAR: 1,\n OBJECT: 2,\n INTERFACE: 3,\n UNION: 4,\n ENUM: 5,\n INPUT: 6,\n} as const;\n\nfunction getResolverMetadata(mergedDefinitions: SchemaDefinitions) {\n const resolverMetadata: Record<string, string[]> = {};\n\n const interfaceFields: Record<string, string[]> = {};\n for (const [type, [typeKind, fields]] of Object.entries(\n mergedDefinitions.types,\n )) {\n if (typeKind === TypeKind.INTERFACE) {\n for (const field of Object.keys(fields ?? {})) {\n interfaceFields[type] ??= [];\n if (!interfaceFields[type].includes(field)) {\n interfaceFields[type].push(field);\n }\n }\n }\n }\n\n for (const [type, [typeKind, fields, interfaces]] of Object.entries(\n mergedDefinitions.types,\n )) {\n if (typeKind === TypeKind.ENUM) {\n continue;\n }\n if (typeKind === TypeKind.UNION) {\n resolverMetadata[type] ??= [];\n if (!resolverMetadata[type].includes(\"__resolveType\")) {\n resolverMetadata[type].push(\"__resolveType\");\n }\n continue;\n }\n\n if (typeKind === TypeKind.INTERFACE) {\n resolverMetadata[type] ??= [];\n if (!resolverMetadata[type].includes(\"__resolveType\")) {\n resolverMetadata[type].push(\"__resolveType\");\n }\n continue;\n }\n\n for (const field of Object.keys(fields ?? {})) {\n resolverMetadata[type] ??= [];\n if (!resolverMetadata[type].includes(field)) {\n resolverMetadata[type].push(field);\n }\n }\n\n if (interfaces?.length) {\n for (const interfaceName of interfaces) {\n const fields = interfaceFields[interfaceName];\n if (!fields) {\n continue;\n }\n for (const field of fields) {\n resolverMetadata[type] ??= [];\n if (!resolverMetadata[type].includes(field)) {\n resolverMetadata[type].push(field);\n }\n }\n }\n }\n }\n\n return resolverMetadata;\n}\n\nfunction getTraverseMetadata(\n operationDefinitions: Record<string, ExtractMinimalViableSchemaResult>,\n fragmentDefinitions: Record<string, ExtractMinimalViableSchemaResult>,\n) {\n const fragmentSpreadMap: Record<string, string[]> = {};\n const fragmentSpreadsUsed: Record<string, boolean> = {};\n for (const [definitionName, { fragmentSpreads }] of Object.entries(\n operationDefinitions,\n )) {\n fragmentSpreads.map((value) => {\n fragmentSpreadMap[definitionName] ??= [];\n\n fragmentSpreadMap[definitionName].push(value);\n if (fragmentSpreadsUsed[value] === undefined) {\n fragmentSpreadsUsed[value] = false;\n }\n });\n }\n\n collectFragmentSpreads(\n fragmentDefinitions,\n fragmentSpreadMap,\n fragmentSpreadsUsed,\n );\n\n // Validation that everyFragment in spread visited its implementation\n for (const [key, value] of Object.entries(fragmentSpreadsUsed)) {\n if (!value) {\n throw new Error(`Fragment \"${key}\" was not visited`);\n }\n\n if (!fragmentSpreadMap[key]) {\n console.log(fragmentSpreadMap, fragmentSpreadsUsed);\n throw new Error(`Something wrong during visit of fragment ${key}`);\n }\n }\n\n return {\n fragmentSpreadMap,\n };\n}\n\nfunction collectFragmentSpreads(\n fragmentDefinitions: Record<string, ExtractMinimalViableSchemaResult>,\n fragmentSpreadMap: Record<string, string[]>,\n fragmentSpreadsUsed: Record<string, boolean>,\n) {\n if (Object.values(fragmentSpreadsUsed).every(Boolean)) {\n return;\n }\n\n const localFragmentSpreads = new Set<string>();\n for (const [key, value] of Object.entries(fragmentSpreadsUsed)) {\n if (value) {\n continue;\n }\n\n const definition = fragmentDefinitions[key];\n fragmentSpreadsUsed[key] = true;\n if (!definition.fragmentSpreads.length) {\n fragmentSpreadMap[key] ??= [];\n }\n\n for (const fragmentSpread of definition.fragmentSpreads) {\n localFragmentSpreads.add(fragmentSpread);\n\n fragmentSpreadMap[key] ??= [];\n\n fragmentSpreadMap[key].push(fragmentSpread);\n }\n }\n\n if (!localFragmentSpreads.size) {\n return;\n }\n\n for (const localFragmentSpread of localFragmentSpreads) {\n if (typeof fragmentSpreadsUsed[localFragmentSpread] === \"boolean\") {\n continue;\n }\n\n fragmentSpreadsUsed[localFragmentSpread] = false;\n }\n\n return collectFragmentSpreads(\n fragmentDefinitions,\n fragmentSpreadMap,\n fragmentSpreadsUsed,\n );\n}\n\nfunction existsInSupportedResolvers(\n { supportedResolvers }: SupportedResolvers,\n resolverName: string,\n operationName: string,\n): boolean {\n if (!supportedResolvers || !supportedResolvers.configs) {\n return false;\n }\n\n return supportedResolvers.configs.some((config) => {\n if (config.value && config.value[operationName]) {\n const resolvers = config.value[operationName];\n if (resolvers.includes(resolverName)) {\n return true;\n }\n }\n });\n}\n"],
5
+ "mappings": ";AAAA,SAAS,sBAAoC;AAE7C;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAgBA,SAAS,uBACd,WACA,SACA;AA1BF;AA2BE,QAAM;AAAA,IACJ;AAAA,IACA,qBAAqB;AAAA,IACrB;AAAA,EACF,IAAI,QAAQ;AACZ,QAAM,SAAS,QAAQ,aAAa,eAAe,QAAQ,MAAM;AACjE,MAAI,oCAAoC;AACtC,UAAM,sBACJ,6BAA6B,CAAC;AAEhC,QAAI,CAAC,OAAO,KAAK,mBAAmB,EAAE,UAAU,oBAAoB;AAClE,iBAAW,YAAY,WAAW;AAChC,YAAI,CAAC,UAAU;AACb;AAAA,QACF;AAEA,mBAAW,cAAc,SAAS,aAAa;AAC7C,cAAI,WAAW,SAAS,uBAAuB;AAC7C,uBAAW,aAAa,WAAW,QAAQ,CAAC,cAAc;AA7CtE,kBAAAA,KAAA;AA8Cc,kBACE,UAAU,SAAS,WACnB;AAAA,gBACE;AAAA,gBACA,UAAU,KAAK;AAAA,gBACf,WAAW;AAAA,cACb,GACA;AACA,sBAAM,EAAE,UAAU,IAAI;AACtB,oBAAI,CAAC,oBAAoB,SAAS,GAAG;AACnC,sCAAoB,SAAS,IAAI,CAAC;AAAA,gBACpC;AAEA,sBACEA,MAAA,WAAW,SAAX,gBAAAA,IAAiB,UACjB,CAAC,oBAAoB,SAAS,EAAE;AAAA,kBAC9B,WAAW,KAAK;AAAA,gBAClB,GACA;AACA,sCAAoB,S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AAO;AAAA,EACT;AAEA,SAAO,mBAAmB,QAAQ,KAAK,CAAC,WAAW;AACjD,QAAI,OAAO,SAAS,OAAO,MAAM,aAAa,GAAG;AAC/C,YAAM,YAAY,OAAO,MAAM,aAAa;AAC5C,UAAI,UAAU,SAAS,YAAY,GAAG;AACpC,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF,CAAC;AACH;",
6
+ "names": ["_a", "fields"]
7
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,128 @@
1
+ import { Types } from "@graphql-codegen/plugin-helpers";
2
+ import { FragmentImport, ImportSource } from "@graphql-codegen/visitor-plugin-common";
3
+ import { SupportedOperations } from "./definitions-metadata";
4
+ export type { DefinitionsMetadata } from "./definitions-metadata";
5
+ export type FragmentImportFromFn = (source: ImportSource<FragmentImport>, sourceFilePath: string) => ImportSource<FragmentImport>;
6
+ export type NearOperationFileConfig = {
7
+ /**
8
+ * @description Required, should point to the base schema types file.
9
+ * The key of the output is used a the base path for this file.
10
+ *
11
+ * If you wish to use an NPM package or a local workspace package, make sure to prefix the package name with `~`.
12
+ *
13
+ * @exampleMarkdown
14
+ * ```yml
15
+ * generates:
16
+ * src/:
17
+ * preset: near-operation-file
18
+ * presetConfig:
19
+ * baseTypesPath: types.ts
20
+ * plugins:
21
+ * - typescript-operations
22
+ * ```
23
+ */
24
+ baseTypesPath: string;
25
+ /**
26
+ * @description Overrides all external fragments import types by using a specific file path or a package name.
27
+ *
28
+ * If you wish to use an NPM package or a local workspace package, make sure to prefix the package name with `~`.
29
+ *
30
+ * @exampleMarkdown
31
+ * ```yml
32
+ * generates:
33
+ * src/:
34
+ * preset: near-operation-file
35
+ * presetConfig:
36
+ * baseTypesPath: types.ts
37
+ * importAllFragmentsFrom: '@fragments'
38
+ * plugins:
39
+ * - typescript-operations
40
+ * ```
41
+ */
42
+ importAllFragmentsFrom?: string | FragmentImportFromFn;
43
+ /**
44
+ * @description Optional, sets the extension for the generated files. Use this to override the extension if you are using plugins that requires a different type of extensions (such as `typescript-react-apollo`)
45
+ * @default .generates.ts
46
+ *
47
+ * @exampleMarkdown
48
+ * ```yml
49
+ * generates:
50
+ * src/:
51
+ * preset: near-operation-file
52
+ * presetConfig:
53
+ * baseTypesPath: types.ts
54
+ * extension: .generated.tsx
55
+ * plugins:
56
+ * - typescript-operations
57
+ * - typescript-react-apollo
58
+ * ```
59
+ */
60
+ extension?: string;
61
+ /**
62
+ * @description Optional, override the `cwd` of the execution. We are using `cwd` to figure out the imports between files. Use this if your execuion path is not your project root directory.
63
+ * @default process.cwd()
64
+ *
65
+ * @exampleMarkdown
66
+ * ```yml
67
+ * generates:
68
+ * src/:
69
+ * preset: near-operation-file
70
+ * presetConfig:
71
+ * baseTypesPath: types.ts
72
+ * cwd: /some/path
73
+ * plugins:
74
+ * - typescript-operations
75
+ * ```
76
+ */
77
+ cwd?: string;
78
+ /**
79
+ * @description Optional, defines a folder, (Relative to the source files) where the generated files will be created.
80
+ * @default ''
81
+ *
82
+ * @exampleMarkdown
83
+ * ```yml
84
+ * generates:
85
+ * src/:
86
+ * preset: near-operation-file
87
+ * presetConfig:
88
+ * baseTypesPath: types.ts
89
+ * folder: __generated__
90
+ * plugins:
91
+ * - typescript-operations
92
+ * ```
93
+ */
94
+ folder?: string;
95
+ /**
96
+ * @description Optional, override the name of the import namespace used to import from the `baseTypesPath` file.
97
+ * @default Types
98
+ *
99
+ * @exampleMarkdown
100
+ * ```yml
101
+ * generates:
102
+ * src/:
103
+ * preset: near-operation-file
104
+ * presetConfig:
105
+ * baseTypesPath: types.ts
106
+ * importTypesNamespace: SchemaTypes
107
+ * plugins:
108
+ * - typescript-operations
109
+ * ```
110
+ */
111
+ importTypesNamespace?: string;
112
+ supportedResolvers?: SupportedResolvers;
113
+ supportedOperations?: SupportedOperations;
114
+ sharedFragmentsDirectoryName?: string;
115
+ usedResolversMetadataDirectoryPath?: string;
116
+ };
117
+ export type SupportedResolvers = {
118
+ supportedResolvers?: {
119
+ configs?: {
120
+ value?: {
121
+ [operation: string]: string[];
122
+ };
123
+ }[];
124
+ };
125
+ };
126
+ export declare const preset: Types.OutputPreset<NearOperationFileConfig>;
127
+ export default preset;
128
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iCAAiC,CAAC;AAKxD,OAAO,EACL,cAAc,EACd,YAAY,EACb,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAEL,mBAAmB,EACpB,MAAM,wBAAwB,CAAC;AAGhC,YAAY,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAElE,MAAM,MAAM,oBAAoB,GAAG,CACjC,MAAM,EAAE,YAAY,CAAC,cAAc,CAAC,EACpC,cAAc,EAAE,MAAM,KACnB,YAAY,CAAC,cAAc,CAAC,CAAC;AAElC,MAAM,MAAM,uBAAuB,GAAG;IACpC;;;;;;;;;;;;;;;;OAgBG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB;;;;;;;;;;;;;;;;OAgBG;IACH,sBAAsB,CAAC,EAAE,MAAM,GAAG,oBAAoB,CAAC;IACvD;;;;;;;;;;;;;;;;OAgBG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;;;;;;;;;;;OAeG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;;;;;;;;;;;;;OAeG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;;;;;;;;;;;OAeG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;IAC1C,4BAA4B,CAAC,EAAE,MAAM,CAAC;IACtC,kCAAkC,CAAC,EAAE,MAAM,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,kBAAkB,CAAC,EAAE;QACnB,OAAO,CAAC,EAAE;YACR,KAAK,CAAC,EAAE;gBAAE,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;aAAE,CAAC;SAC3C,EAAE,CAAC;KACL,CAAC;CACH,CAAC;AAEF,eAAO,MAAM,MAAM,EAAE,KAAK,CAAC,YAAY,CAAC,uBAAuB,CA0C9D,CAAC;AAEF,eAAe,MAAM,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,72 @@
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
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var src_exports = {};
30
+ __export(src_exports, {
31
+ default: () => src_default,
32
+ preset: () => preset
33
+ });
34
+ module.exports = __toCommonJS(src_exports);
35
+ var import_near_operation_file_preset = require("@graphql-codegen/near-operation-file-preset");
36
+ var import_path = __toESM(require("path"));
37
+ var import_definitions_metadata = require("./definitions-metadata");
38
+ var import_fs = require("fs");
39
+ const preset = {
40
+ buildGeneratesSection: (options) => {
41
+ const documents = options.documents.map(
42
+ (documentFile) => {
43
+ if (!documentFile.document || !documentFile.document.definitions || !documentFile.location) {
44
+ throw new Error(
45
+ `Document "${documentFile.location}" does not contain any definitions or location!`
46
+ );
47
+ }
48
+ return documentFile.document;
49
+ }
50
+ );
51
+ const resolverMetadata = (0, import_definitions_metadata.getDefinitionsMetadata)(documents, options);
52
+ if (resolverMetadata && options.presetConfig.usedResolversMetadataDirectoryPath) {
53
+ const { schemaMetadata, ...definitionsMetadata } = resolverMetadata;
54
+ (0, import_fs.writeFileSync)(
55
+ import_path.default.resolve(
56
+ options.presetConfig.usedResolversMetadataDirectoryPath,
57
+ "./definitions-metadata.json"
58
+ ),
59
+ JSON.stringify(definitionsMetadata, null, 2)
60
+ );
61
+ (0, import_fs.writeFileSync)(
62
+ import_path.default.resolve(
63
+ options.presetConfig.usedResolversMetadataDirectoryPath,
64
+ "./schema-metadata.json"
65
+ ),
66
+ JSON.stringify(schemaMetadata, null, 2)
67
+ );
68
+ }
69
+ return import_near_operation_file_preset.preset.buildGeneratesSection(options);
70
+ }
71
+ };
72
+ var src_default = preset;
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts"],
4
+ "sourcesContent": ["import { Types } from \"@graphql-codegen/plugin-helpers\";\nimport { preset as nearOperationPreset } from \"@graphql-codegen/near-operation-file-preset\";\nimport path from \"path\";\nimport { Source } from \"@graphql-tools/utils\";\nimport { DocumentNode } from \"graphql\";\nimport {\n FragmentImport,\n ImportSource,\n} from \"@graphql-codegen/visitor-plugin-common\";\nimport {\n getDefinitionsMetadata,\n SupportedOperations,\n} from \"./definitions-metadata\";\nimport { writeFileSync } from \"fs\";\n\nexport type { DefinitionsMetadata } from \"./definitions-metadata\";\n\nexport type FragmentImportFromFn = (\n source: ImportSource<FragmentImport>,\n sourceFilePath: string,\n) => ImportSource<FragmentImport>;\n\nexport type NearOperationFileConfig = {\n /**\n * @description Required, should point to the base schema types file.\n * The key of the output is used a the base path for this file.\n *\n * If you wish to use an NPM package or a local workspace package, make sure to prefix the package name with `~`.\n *\n * @exampleMarkdown\n * ```yml\n * generates:\n * src/:\n * preset: near-operation-file\n * presetConfig:\n * baseTypesPath: types.ts\n * plugins:\n * - typescript-operations\n * ```\n */\n baseTypesPath: string;\n /**\n * @description Overrides all external fragments import types by using a specific file path or a package name.\n *\n * If you wish to use an NPM package or a local workspace package, make sure to prefix the package name with `~`.\n *\n * @exampleMarkdown\n * ```yml\n * generates:\n * src/:\n * preset: near-operation-file\n * presetConfig:\n * baseTypesPath: types.ts\n * importAllFragmentsFrom: '@fragments'\n * plugins:\n * - typescript-operations\n * ```\n */\n importAllFragmentsFrom?: string | FragmentImportFromFn;\n /**\n * @description Optional, sets the extension for the generated files. Use this to override the extension if you are using plugins that requires a different type of extensions (such as `typescript-react-apollo`)\n * @default .generates.ts\n *\n * @exampleMarkdown\n * ```yml\n * generates:\n * src/:\n * preset: near-operation-file\n * presetConfig:\n * baseTypesPath: types.ts\n * extension: .generated.tsx\n * plugins:\n * - typescript-operations\n * - typescript-react-apollo\n * ```\n */\n extension?: string;\n /**\n * @description Optional, override the `cwd` of the execution. We are using `cwd` to figure out the imports between files. Use this if your execuion path is not your project root directory.\n * @default process.cwd()\n *\n * @exampleMarkdown\n * ```yml\n * generates:\n * src/:\n * preset: near-operation-file\n * presetConfig:\n * baseTypesPath: types.ts\n * cwd: /some/path\n * plugins:\n * - typescript-operations\n * ```\n */\n cwd?: string;\n /**\n * @description Optional, defines a folder, (Relative to the source files) where the generated files will be created.\n * @default ''\n *\n * @exampleMarkdown\n * ```yml\n * generates:\n * src/:\n * preset: near-operation-file\n * presetConfig:\n * baseTypesPath: types.ts\n * folder: __generated__\n * plugins:\n * - typescript-operations\n * ```\n */\n folder?: string;\n /**\n * @description Optional, override the name of the import namespace used to import from the `baseTypesPath` file.\n * @default Types\n *\n * @exampleMarkdown\n * ```yml\n * generates:\n * src/:\n * preset: near-operation-file\n * presetConfig:\n * baseTypesPath: types.ts\n * importTypesNamespace: SchemaTypes\n * plugins:\n * - typescript-operations\n * ```\n */\n importTypesNamespace?: string;\n supportedResolvers?: SupportedResolvers;\n supportedOperations?: SupportedOperations;\n sharedFragmentsDirectoryName?: string;\n usedResolversMetadataDirectoryPath?: string;\n};\n\nexport type SupportedResolvers = {\n supportedResolvers?: {\n configs?: {\n value?: { [operation: string]: string[] };\n }[];\n };\n};\n\nexport const preset: Types.OutputPreset<NearOperationFileConfig> = {\n buildGeneratesSection: (options) => {\n const documents: DocumentNode[] = options.documents.map(\n (documentFile: Source) => {\n if (\n !documentFile.document ||\n !documentFile.document.definitions ||\n !documentFile.location\n ) {\n throw new Error(\n `Document \"${documentFile.location}\" does not contain any definitions or location!`,\n );\n }\n\n return documentFile.document;\n },\n );\n\n const resolverMetadata = getDefinitionsMetadata(documents, options);\n if (\n resolverMetadata &&\n options.presetConfig.usedResolversMetadataDirectoryPath\n ) {\n const { schemaMetadata, ...definitionsMetadata } = resolverMetadata;\n writeFileSync(\n path.resolve(\n options.presetConfig.usedResolversMetadataDirectoryPath,\n \"./definitions-metadata.json\",\n ),\n JSON.stringify(definitionsMetadata, null, 2),\n );\n writeFileSync(\n path.resolve(\n options.presetConfig.usedResolversMetadataDirectoryPath,\n \"./schema-metadata.json\",\n ),\n JSON.stringify(schemaMetadata, null, 2),\n );\n }\n\n return nearOperationPreset.buildGeneratesSection(options);\n },\n};\n\nexport default preset;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,wCAA8C;AAC9C,kBAAiB;AAOjB,kCAGO;AACP,gBAA8B;AAiIvB,MAAM,SAAsD;AAAA,EACjE,uBAAuB,CAAC,YAAY;AAClC,UAAM,YAA4B,QAAQ,UAAU;AAAA,MAClD,CAAC,iBAAyB;AACxB,YACE,CAAC,aAAa,YACd,CAAC,aAAa,SAAS,eACvB,CAAC,aAAa,UACd;AACA,gBAAM,IAAI;AAAA,YACR,aAAa,aAAa;AAAA,UAC5B;AAAA,QACF;AAEA,eAAO,aAAa;AAAA,MACtB;AAAA,IACF;AAEA,UAAM,uBAAmB,oDAAuB,WAAW,OAAO;AAClE,QACE,oBACA,QAAQ,aAAa,oCACrB;AACA,YAAM,EAAE,gBAAgB,GAAG,oBAAoB,IAAI;AACnD;AAAA,QACE,YAAAA,QAAK;AAAA,UACH,QAAQ,aAAa;AAAA,UACrB;AAAA,QACF;AAAA,QACA,KAAK,UAAU,qBAAqB,MAAM,CAAC;AAAA,MAC7C;AACA;AAAA,QACE,YAAAA,QAAK;AAAA,UACH,QAAQ,aAAa;AAAA,UACrB;AAAA,QACF;AAAA,QACA,KAAK,UAAU,gBAAgB,MAAM,CAAC;AAAA,MACxC;AAAA,IACF;AAEA,WAAO,kCAAAC,OAAoB,sBAAsB,OAAO;AAAA,EAC1D;AACF;AAEA,IAAO,cAAQ;",
6
+ "names": ["path", "nearOperationPreset"]
7
+ }
package/lib/index.mjs ADDED
@@ -0,0 +1,45 @@
1
+ // src/index.ts
2
+ import { preset as nearOperationPreset } from "@graphql-codegen/near-operation-file-preset";
3
+ import path from "path";
4
+ import {
5
+ getDefinitionsMetadata
6
+ } from "./definitions-metadata.mjs";
7
+ import { writeFileSync } from "fs";
8
+ var preset = {
9
+ buildGeneratesSection: (options) => {
10
+ const documents = options.documents.map(
11
+ (documentFile) => {
12
+ if (!documentFile.document || !documentFile.document.definitions || !documentFile.location) {
13
+ throw new Error(
14
+ `Document "${documentFile.location}" does not contain any definitions or location!`
15
+ );
16
+ }
17
+ return documentFile.document;
18
+ }
19
+ );
20
+ const resolverMetadata = getDefinitionsMetadata(documents, options);
21
+ if (resolverMetadata && options.presetConfig.usedResolversMetadataDirectoryPath) {
22
+ const { schemaMetadata, ...definitionsMetadata } = resolverMetadata;
23
+ writeFileSync(
24
+ path.resolve(
25
+ options.presetConfig.usedResolversMetadataDirectoryPath,
26
+ "./definitions-metadata.json"
27
+ ),
28
+ JSON.stringify(definitionsMetadata, null, 2)
29
+ );
30
+ writeFileSync(
31
+ path.resolve(
32
+ options.presetConfig.usedResolversMetadataDirectoryPath,
33
+ "./schema-metadata.json"
34
+ ),
35
+ JSON.stringify(schemaMetadata, null, 2)
36
+ );
37
+ }
38
+ return nearOperationPreset.buildGeneratesSection(options);
39
+ }
40
+ };
41
+ var src_default = preset;
42
+ export {
43
+ src_default as default,
44
+ preset
45
+ };
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts"],
4
+ "sourcesContent": ["import { Types } from \"@graphql-codegen/plugin-helpers\";\nimport { preset as nearOperationPreset } from \"@graphql-codegen/near-operation-file-preset\";\nimport path from \"path\";\nimport { Source } from \"@graphql-tools/utils\";\nimport { DocumentNode } from \"graphql\";\nimport {\n FragmentImport,\n ImportSource,\n} from \"@graphql-codegen/visitor-plugin-common\";\nimport {\n getDefinitionsMetadata,\n SupportedOperations,\n} from \"./definitions-metadata\";\nimport { writeFileSync } from \"fs\";\n\nexport type { DefinitionsMetadata } from \"./definitions-metadata\";\n\nexport type FragmentImportFromFn = (\n source: ImportSource<FragmentImport>,\n sourceFilePath: string,\n) => ImportSource<FragmentImport>;\n\nexport type NearOperationFileConfig = {\n /**\n * @description Required, should point to the base schema types file.\n * The key of the output is used a the base path for this file.\n *\n * If you wish to use an NPM package or a local workspace package, make sure to prefix the package name with `~`.\n *\n * @exampleMarkdown\n * ```yml\n * generates:\n * src/:\n * preset: near-operation-file\n * presetConfig:\n * baseTypesPath: types.ts\n * plugins:\n * - typescript-operations\n * ```\n */\n baseTypesPath: string;\n /**\n * @description Overrides all external fragments import types by using a specific file path or a package name.\n *\n * If you wish to use an NPM package or a local workspace package, make sure to prefix the package name with `~`.\n *\n * @exampleMarkdown\n * ```yml\n * generates:\n * src/:\n * preset: near-operation-file\n * presetConfig:\n * baseTypesPath: types.ts\n * importAllFragmentsFrom: '@fragments'\n * plugins:\n * - typescript-operations\n * ```\n */\n importAllFragmentsFrom?: string | FragmentImportFromFn;\n /**\n * @description Optional, sets the extension for the generated files. Use this to override the extension if you are using plugins that requires a different type of extensions (such as `typescript-react-apollo`)\n * @default .generates.ts\n *\n * @exampleMarkdown\n * ```yml\n * generates:\n * src/:\n * preset: near-operation-file\n * presetConfig:\n * baseTypesPath: types.ts\n * extension: .generated.tsx\n * plugins:\n * - typescript-operations\n * - typescript-react-apollo\n * ```\n */\n extension?: string;\n /**\n * @description Optional, override the `cwd` of the execution. We are using `cwd` to figure out the imports between files. Use this if your execuion path is not your project root directory.\n * @default process.cwd()\n *\n * @exampleMarkdown\n * ```yml\n * generates:\n * src/:\n * preset: near-operation-file\n * presetConfig:\n * baseTypesPath: types.ts\n * cwd: /some/path\n * plugins:\n * - typescript-operations\n * ```\n */\n cwd?: string;\n /**\n * @description Optional, defines a folder, (Relative to the source files) where the generated files will be created.\n * @default ''\n *\n * @exampleMarkdown\n * ```yml\n * generates:\n * src/:\n * preset: near-operation-file\n * presetConfig:\n * baseTypesPath: types.ts\n * folder: __generated__\n * plugins:\n * - typescript-operations\n * ```\n */\n folder?: string;\n /**\n * @description Optional, override the name of the import namespace used to import from the `baseTypesPath` file.\n * @default Types\n *\n * @exampleMarkdown\n * ```yml\n * generates:\n * src/:\n * preset: near-operation-file\n * presetConfig:\n * baseTypesPath: types.ts\n * importTypesNamespace: SchemaTypes\n * plugins:\n * - typescript-operations\n * ```\n */\n importTypesNamespace?: string;\n supportedResolvers?: SupportedResolvers;\n supportedOperations?: SupportedOperations;\n sharedFragmentsDirectoryName?: string;\n usedResolversMetadataDirectoryPath?: string;\n};\n\nexport type SupportedResolvers = {\n supportedResolvers?: {\n configs?: {\n value?: { [operation: string]: string[] };\n }[];\n };\n};\n\nexport const preset: Types.OutputPreset<NearOperationFileConfig> = {\n buildGeneratesSection: (options) => {\n const documents: DocumentNode[] = options.documents.map(\n (documentFile: Source) => {\n if (\n !documentFile.document ||\n !documentFile.document.definitions ||\n !documentFile.location\n ) {\n throw new Error(\n `Document \"${documentFile.location}\" does not contain any definitions or location!`,\n );\n }\n\n return documentFile.document;\n },\n );\n\n const resolverMetadata = getDefinitionsMetadata(documents, options);\n if (\n resolverMetadata &&\n options.presetConfig.usedResolversMetadataDirectoryPath\n ) {\n const { schemaMetadata, ...definitionsMetadata } = resolverMetadata;\n writeFileSync(\n path.resolve(\n options.presetConfig.usedResolversMetadataDirectoryPath,\n \"./definitions-metadata.json\",\n ),\n JSON.stringify(definitionsMetadata, null, 2),\n );\n writeFileSync(\n path.resolve(\n options.presetConfig.usedResolversMetadataDirectoryPath,\n \"./schema-metadata.json\",\n ),\n JSON.stringify(schemaMetadata, null, 2),\n );\n }\n\n return nearOperationPreset.buildGeneratesSection(options);\n },\n};\n\nexport default preset;\n"],
5
+ "mappings": ";AACA,SAAS,UAAU,2BAA2B;AAC9C,OAAO,UAAU;AAOjB;AAAA,EACE;AAAA,OAEK;AACP,SAAS,qBAAqB;AAiIvB,IAAM,SAAsD;AAAA,EACjE,uBAAuB,CAAC,YAAY;AAClC,UAAM,YAA4B,QAAQ,UAAU;AAAA,MAClD,CAAC,iBAAyB;AACxB,YACE,CAAC,aAAa,YACd,CAAC,aAAa,SAAS,eACvB,CAAC,aAAa,UACd;AACA,gBAAM,IAAI;AAAA,YACR,aAAa,aAAa;AAAA,UAC5B;AAAA,QACF;AAEA,eAAO,aAAa;AAAA,MACtB;AAAA,IACF;AAEA,UAAM,mBAAmB,uBAAuB,WAAW,OAAO;AAClE,QACE,oBACA,QAAQ,aAAa,oCACrB;AACA,YAAM,EAAE,gBAAgB,GAAG,oBAAoB,IAAI;AACnD;AAAA,QACE,KAAK;AAAA,UACH,QAAQ,aAAa;AAAA,UACrB;AAAA,QACF;AAAA,QACA,KAAK,UAAU,qBAAqB,MAAM,CAAC;AAAA,MAC7C;AACA;AAAA,QACE,KAAK;AAAA,UACH,QAAQ,aAAa;AAAA,UACrB;AAAA,QACF;AAAA,QACA,KAAK,UAAU,gBAAgB,MAAM,CAAC;AAAA,MACxC;AAAA,IACF;AAEA,WAAO,oBAAoB,sBAAsB,OAAO;AAAA,EAC1D;AACF;AAEA,IAAO,cAAQ;",
6
+ "names": []
7
+ }
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@graphitation/graphql-codegen-near-operation-file-preset-with-resolver-metadata",
3
+ "license": "MIT",
4
+ "version": "1.1.0",
5
+ "main": "./lib/index",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/microsoft/graphitation.git",
9
+ "directory": "packages/graphql-codegen-near-operation-file-preset"
10
+ },
11
+ "scripts": {
12
+ "build": "monorepo-scripts build",
13
+ "lint": "monorepo-scripts lint",
14
+ "test": "monorepo-scripts test",
15
+ "types": "monorepo-scripts types",
16
+ "just": "monorepo-scripts"
17
+ },
18
+ "dependencies": {
19
+ "@graphql-codegen/plugin-helpers": "^1.18.2",
20
+ "@graphql-codegen/visitor-plugin-common": "^1.17.22",
21
+ "@graphql-codegen/near-operation-file-preset": "1.17.13",
22
+ "@graphql-codegen/add": "^2.0.2",
23
+ "parse-filepath": "^1.0.2",
24
+ "tslib": "~2.0.1"
25
+ },
26
+ "devDependencies": {
27
+ "@types/parse-filepath": "1.0.0"
28
+ },
29
+ "peerDependencies": {
30
+ "graphql": "^15.0.0"
31
+ },
32
+ "sideEffects": false,
33
+ "access": "public",
34
+ "publishConfig": {},
35
+ "types": "./lib/index.d.ts",
36
+ "module": "./lib/index.mjs",
37
+ "exports": {
38
+ ".": {
39
+ "import": "./lib/index.mjs",
40
+ "require": "./lib/index.js",
41
+ "types": "./lib/index.d.ts"
42
+ }
43
+ }
44
+ }