@graphql-codegen/graphql-modules-preset 2.4.3-alpha-d8d060f00.0 → 2.5.0-alpha-8815d56b3.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/cjs/builder.js +11 -6
- package/cjs/index.js +3 -1
- package/esm/builder.js +11 -6
- package/esm/index.js +3 -1
- package/package.json +3 -3
- package/typings/builder.d.ts +2 -1
- package/typings/config.d.ts +20 -0
package/cjs/builder.js
CHANGED
|
@@ -6,7 +6,7 @@ const change_case_all_1 = require("change-case-all");
|
|
|
6
6
|
const utils_js_1 = require("./utils.js");
|
|
7
7
|
const registryKeys = ['objects', 'inputs', 'interfaces', 'scalars', 'unions', 'enums'];
|
|
8
8
|
const resolverKeys = ['scalars', 'objects', 'enums'];
|
|
9
|
-
function buildModule(name, doc, { importNamespace, importPath, encapsulate, shouldDeclare, rootTypes, schema, baseVisitor, useGraphQLModules, }) {
|
|
9
|
+
function buildModule(name, doc, { importNamespace, importPath, encapsulate, requireRootResolvers, shouldDeclare, rootTypes, schema, baseVisitor, useGraphQLModules, }) {
|
|
10
10
|
const picks = (0, utils_js_1.createObject)(registryKeys, () => ({}));
|
|
11
11
|
const defined = (0, utils_js_1.createObject)(registryKeys, () => []);
|
|
12
12
|
const extended = (0, utils_js_1.createObject)(registryKeys, () => []);
|
|
@@ -135,7 +135,9 @@ function buildModule(name, doc, { importNamespace, importPath, encapsulate, shou
|
|
|
135
135
|
function printResolveSignaturesPerType(registry) {
|
|
136
136
|
return [
|
|
137
137
|
[...registry.objects, ...registry.interfaces]
|
|
138
|
-
.map(name => printResolverType(name, 'DefinedFields',
|
|
138
|
+
.map(name => printResolverType(name, 'DefinedFields',
|
|
139
|
+
// In case of enabled `requireRootResolvers` flag, the preset has to produce a non-optional properties.
|
|
140
|
+
requireRootResolvers && rootTypes.includes(name), !rootTypes.includes(name) && defined.objects.includes(name) ? ` | '__isTypeOf'` : ''))
|
|
139
141
|
.join('\n'),
|
|
140
142
|
].join('\n');
|
|
141
143
|
}
|
|
@@ -172,7 +174,9 @@ function buildModule(name, doc, { importNamespace, importPath, encapsulate, shou
|
|
|
172
174
|
lines.push(`${typeName}?: ${encapsulateTypeName(importNamespace)}.Resolvers['${typeName}'];`);
|
|
173
175
|
}
|
|
174
176
|
else {
|
|
175
|
-
|
|
177
|
+
// In case of enabled `requireRootResolvers` flag, the preset has to produce a non-optional property.
|
|
178
|
+
const fieldModifier = requireRootResolvers && rootTypes.includes(typeName) ? '' : '?';
|
|
179
|
+
lines.push(`${typeName}${fieldModifier}: ${encapsulateTypeName(typeName)}Resolvers;`);
|
|
176
180
|
}
|
|
177
181
|
});
|
|
178
182
|
}
|
|
@@ -207,10 +211,11 @@ function buildModule(name, doc, { importNamespace, importPath, encapsulate, shou
|
|
|
207
211
|
function printResolveMiddlewareRecord(path) {
|
|
208
212
|
return `${path}?: gm.Middleware[];`;
|
|
209
213
|
}
|
|
210
|
-
function printResolverType(typeName, picksTypeName, extraKeys = '') {
|
|
211
|
-
|
|
214
|
+
function printResolverType(typeName, picksTypeName, requireFieldsResolvers = false, extraKeys = '') {
|
|
215
|
+
const typeSignature = `Pick<${importNamespace}.${baseVisitor.convertName(typeName, {
|
|
212
216
|
suffix: 'Resolvers',
|
|
213
|
-
})}, ${picksTypeName}['${typeName}']${extraKeys}
|
|
217
|
+
})}, ${picksTypeName}['${typeName}']${extraKeys}>`;
|
|
218
|
+
return `export type ${encapsulateTypeName(`${typeName}Resolvers`)} = ${requireFieldsResolvers ? `Required<${typeSignature}>` : typeSignature};`;
|
|
214
219
|
}
|
|
215
220
|
function printPicks(typeName, records) {
|
|
216
221
|
return records[typeName].filter(utils_js_1.unique).map(utils_js_1.withQuotes).join(' | ');
|
package/cjs/index.js
CHANGED
|
@@ -8,9 +8,10 @@ const builder_js_1 = require("./builder.js");
|
|
|
8
8
|
const visitor_plugin_common_1 = require("@graphql-codegen/visitor-plugin-common");
|
|
9
9
|
exports.preset = {
|
|
10
10
|
buildGeneratesSection: options => {
|
|
11
|
-
const useGraphQLModules = (0, visitor_plugin_common_1.getConfigValue)(options === null || options === void 0 ? void 0 : options.presetConfig.useGraphQLModules, true);
|
|
12
11
|
const { baseOutputDir } = options;
|
|
13
12
|
const { baseTypesPath, encapsulateModuleTypes } = options.presetConfig;
|
|
13
|
+
const useGraphQLModules = (0, visitor_plugin_common_1.getConfigValue)(options === null || options === void 0 ? void 0 : options.presetConfig.useGraphQLModules, true);
|
|
14
|
+
const requireRootResolvers = (0, visitor_plugin_common_1.getConfigValue)(options === null || options === void 0 ? void 0 : options.presetConfig.requireRootResolvers, false);
|
|
14
15
|
const cwd = (0, path_1.resolve)(options.presetConfig.cwd || process.cwd());
|
|
15
16
|
const importTypesNamespace = options.presetConfig.importTypesNamespace || 'Types';
|
|
16
17
|
if (!baseTypesPath) {
|
|
@@ -88,6 +89,7 @@ exports.preset = {
|
|
|
88
89
|
importNamespace: importTypesNamespace,
|
|
89
90
|
importPath,
|
|
90
91
|
encapsulate: encapsulateModuleTypes || 'namespace',
|
|
92
|
+
requireRootResolvers,
|
|
91
93
|
shouldDeclare,
|
|
92
94
|
schema,
|
|
93
95
|
baseVisitor,
|
package/esm/builder.js
CHANGED
|
@@ -3,7 +3,7 @@ import { pascalCase } from 'change-case-all';
|
|
|
3
3
|
import { unique, withQuotes, buildBlock, pushUnique, concatByKey, uniqueByKey, createObject, collectUsedTypes, indent, } from './utils.js';
|
|
4
4
|
const registryKeys = ['objects', 'inputs', 'interfaces', 'scalars', 'unions', 'enums'];
|
|
5
5
|
const resolverKeys = ['scalars', 'objects', 'enums'];
|
|
6
|
-
export function buildModule(name, doc, { importNamespace, importPath, encapsulate, shouldDeclare, rootTypes, schema, baseVisitor, useGraphQLModules, }) {
|
|
6
|
+
export function buildModule(name, doc, { importNamespace, importPath, encapsulate, requireRootResolvers, shouldDeclare, rootTypes, schema, baseVisitor, useGraphQLModules, }) {
|
|
7
7
|
const picks = createObject(registryKeys, () => ({}));
|
|
8
8
|
const defined = createObject(registryKeys, () => []);
|
|
9
9
|
const extended = createObject(registryKeys, () => []);
|
|
@@ -132,7 +132,9 @@ export function buildModule(name, doc, { importNamespace, importPath, encapsulat
|
|
|
132
132
|
function printResolveSignaturesPerType(registry) {
|
|
133
133
|
return [
|
|
134
134
|
[...registry.objects, ...registry.interfaces]
|
|
135
|
-
.map(name => printResolverType(name, 'DefinedFields',
|
|
135
|
+
.map(name => printResolverType(name, 'DefinedFields',
|
|
136
|
+
// In case of enabled `requireRootResolvers` flag, the preset has to produce a non-optional properties.
|
|
137
|
+
requireRootResolvers && rootTypes.includes(name), !rootTypes.includes(name) && defined.objects.includes(name) ? ` | '__isTypeOf'` : ''))
|
|
136
138
|
.join('\n'),
|
|
137
139
|
].join('\n');
|
|
138
140
|
}
|
|
@@ -169,7 +171,9 @@ export function buildModule(name, doc, { importNamespace, importPath, encapsulat
|
|
|
169
171
|
lines.push(`${typeName}?: ${encapsulateTypeName(importNamespace)}.Resolvers['${typeName}'];`);
|
|
170
172
|
}
|
|
171
173
|
else {
|
|
172
|
-
|
|
174
|
+
// In case of enabled `requireRootResolvers` flag, the preset has to produce a non-optional property.
|
|
175
|
+
const fieldModifier = requireRootResolvers && rootTypes.includes(typeName) ? '' : '?';
|
|
176
|
+
lines.push(`${typeName}${fieldModifier}: ${encapsulateTypeName(typeName)}Resolvers;`);
|
|
173
177
|
}
|
|
174
178
|
});
|
|
175
179
|
}
|
|
@@ -204,10 +208,11 @@ export function buildModule(name, doc, { importNamespace, importPath, encapsulat
|
|
|
204
208
|
function printResolveMiddlewareRecord(path) {
|
|
205
209
|
return `${path}?: gm.Middleware[];`;
|
|
206
210
|
}
|
|
207
|
-
function printResolverType(typeName, picksTypeName, extraKeys = '') {
|
|
208
|
-
|
|
211
|
+
function printResolverType(typeName, picksTypeName, requireFieldsResolvers = false, extraKeys = '') {
|
|
212
|
+
const typeSignature = `Pick<${importNamespace}.${baseVisitor.convertName(typeName, {
|
|
209
213
|
suffix: 'Resolvers',
|
|
210
|
-
})}, ${picksTypeName}['${typeName}']${extraKeys}
|
|
214
|
+
})}, ${picksTypeName}['${typeName}']${extraKeys}>`;
|
|
215
|
+
return `export type ${encapsulateTypeName(`${typeName}Resolvers`)} = ${requireFieldsResolvers ? `Required<${typeSignature}>` : typeSignature};`;
|
|
211
216
|
}
|
|
212
217
|
function printPicks(typeName, records) {
|
|
213
218
|
return records[typeName].filter(unique).map(withQuotes).join(' | ');
|
package/esm/index.js
CHANGED
|
@@ -5,9 +5,10 @@ import { buildModule } from './builder.js';
|
|
|
5
5
|
import { BaseVisitor, getConfigValue } from '@graphql-codegen/visitor-plugin-common';
|
|
6
6
|
export const preset = {
|
|
7
7
|
buildGeneratesSection: options => {
|
|
8
|
-
const useGraphQLModules = getConfigValue(options === null || options === void 0 ? void 0 : options.presetConfig.useGraphQLModules, true);
|
|
9
8
|
const { baseOutputDir } = options;
|
|
10
9
|
const { baseTypesPath, encapsulateModuleTypes } = options.presetConfig;
|
|
10
|
+
const useGraphQLModules = getConfigValue(options === null || options === void 0 ? void 0 : options.presetConfig.useGraphQLModules, true);
|
|
11
|
+
const requireRootResolvers = getConfigValue(options === null || options === void 0 ? void 0 : options.presetConfig.requireRootResolvers, false);
|
|
11
12
|
const cwd = resolve(options.presetConfig.cwd || process.cwd());
|
|
12
13
|
const importTypesNamespace = options.presetConfig.importTypesNamespace || 'Types';
|
|
13
14
|
if (!baseTypesPath) {
|
|
@@ -85,6 +86,7 @@ export const preset = {
|
|
|
85
86
|
importNamespace: importTypesNamespace,
|
|
86
87
|
importPath,
|
|
87
88
|
encapsulate: encapsulateModuleTypes || 'namespace',
|
|
89
|
+
requireRootResolvers,
|
|
88
90
|
shouldDeclare,
|
|
89
91
|
schema,
|
|
90
92
|
baseVisitor,
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/graphql-modules-preset",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0-alpha-8815d56b3.0",
|
|
4
4
|
"description": "GraphQL Code Generator preset for modularized schema",
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@graphql-codegen/plugin-helpers": "^2.6.
|
|
10
|
-
"@graphql-codegen/visitor-plugin-common": "2.12.
|
|
9
|
+
"@graphql-codegen/plugin-helpers": "^2.6.0",
|
|
10
|
+
"@graphql-codegen/visitor-plugin-common": "2.12.0",
|
|
11
11
|
"@graphql-tools/utils": "^8.8.0",
|
|
12
12
|
"parse-filepath": "^1.0.2",
|
|
13
13
|
"change-case-all": "1.0.14",
|
package/typings/builder.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { DocumentNode, GraphQLSchema } from 'graphql';
|
|
2
2
|
import { ModulesConfig } from './config.js';
|
|
3
3
|
import { BaseVisitor } from '@graphql-codegen/visitor-plugin-common';
|
|
4
|
-
export declare function buildModule(name: string, doc: DocumentNode, { importNamespace, importPath, encapsulate, shouldDeclare, rootTypes, schema, baseVisitor, useGraphQLModules, }: {
|
|
4
|
+
export declare function buildModule(name: string, doc: DocumentNode, { importNamespace, importPath, encapsulate, requireRootResolvers, shouldDeclare, rootTypes, schema, baseVisitor, useGraphQLModules, }: {
|
|
5
5
|
importNamespace: string;
|
|
6
6
|
importPath: string;
|
|
7
7
|
encapsulate: ModulesConfig['encapsulateModuleTypes'];
|
|
8
|
+
requireRootResolvers: ModulesConfig['requireRootResolvers'];
|
|
8
9
|
shouldDeclare: boolean;
|
|
9
10
|
rootTypes: string[];
|
|
10
11
|
baseVisitor: BaseVisitor;
|
package/typings/config.d.ts
CHANGED
|
@@ -82,6 +82,26 @@ export declare type ModulesConfig = {
|
|
|
82
82
|
*
|
|
83
83
|
*/
|
|
84
84
|
encapsulateModuleTypes: 'prefix' | 'namespace' | 'none';
|
|
85
|
+
/**
|
|
86
|
+
* @name requireRootResolvers
|
|
87
|
+
* @type boolean
|
|
88
|
+
* @default false
|
|
89
|
+
* @description Generate resolvers of root types (Query, Mutation and Subscription) as non-optional.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```yml
|
|
93
|
+
* generates:
|
|
94
|
+
* src/:
|
|
95
|
+
* preset: modules
|
|
96
|
+
* presetConfig:
|
|
97
|
+
* baseTypesPath: types.ts
|
|
98
|
+
* filename: types.ts
|
|
99
|
+
* requireRootResolvers: true
|
|
100
|
+
* plugins:
|
|
101
|
+
* - typescript-resolvers
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
requireRootResolvers?: boolean;
|
|
85
105
|
/**
|
|
86
106
|
* @name useGraphQLModules
|
|
87
107
|
* @type boolean
|