@graphql-codegen/graphql-modules-preset 2.5.11 → 2.5.12-alpha-20230109071557-db6d5c74b
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 +6 -9
- package/cjs/index.js +6 -5
- package/cjs/utils.js +1 -3
- package/esm/builder.js +7 -10
- package/esm/index.js +6 -5
- package/esm/utils.js +1 -3
- package/package.json +2 -2
- package/typings/builder.d.cts +1 -1
- package/typings/builder.d.ts +1 -1
- package/typings/utils.d.cts +1 -1
- package/typings/utils.d.ts +1 -1
package/cjs/builder.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildModule = void 0;
|
|
4
|
-
const graphql_1 = require("graphql");
|
|
5
4
|
const change_case_all_1 = require("change-case-all");
|
|
5
|
+
const graphql_1 = require("graphql");
|
|
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'];
|
|
@@ -164,7 +164,7 @@ function buildModule(name, doc, { importNamespace, importPath, encapsulate, requ
|
|
|
164
164
|
const lines = [];
|
|
165
165
|
for (const kind in registry) {
|
|
166
166
|
const k = kind;
|
|
167
|
-
if (
|
|
167
|
+
if (Object.prototype.hasOwnProperty.call(registry, k) && resolverKeys.includes(k)) {
|
|
168
168
|
const types = registry[k];
|
|
169
169
|
types.forEach(typeName => {
|
|
170
170
|
if (k === 'enums') {
|
|
@@ -194,7 +194,7 @@ function buildModule(name, doc, { importNamespace, importPath, encapsulate, requ
|
|
|
194
194
|
const blocks = [(0, utils_js_1.buildBlock)({ name: `${(0, utils_js_1.withQuotes)('*')}?:`, lines: [wildcardField] })];
|
|
195
195
|
// Type.Field
|
|
196
196
|
for (const typeName in picks.objects) {
|
|
197
|
-
if (
|
|
197
|
+
if (Object.prototype.hasOwnProperty.call(picks.objects, typeName)) {
|
|
198
198
|
const fields = picks.objects[typeName];
|
|
199
199
|
const lines = [wildcardField].concat(fields.map(field => printResolveMiddlewareRecord(field)));
|
|
200
200
|
blocks.push((0, utils_js_1.buildBlock)({
|
|
@@ -258,20 +258,17 @@ function buildModule(name, doc, { importNamespace, importPath, encapsulate, requ
|
|
|
258
258
|
function collectFields(node, picksObj) {
|
|
259
259
|
const name = node.name.value;
|
|
260
260
|
if (node.fields) {
|
|
261
|
-
|
|
262
|
-
picksObj[name] = [];
|
|
263
|
-
}
|
|
261
|
+
picksObj[name] || (picksObj[name] = []);
|
|
264
262
|
node.fields.forEach(field => {
|
|
265
263
|
picksObj[name].push(field.name.value);
|
|
266
264
|
});
|
|
267
265
|
}
|
|
268
266
|
}
|
|
269
267
|
function collectValuesFromEnum(node) {
|
|
268
|
+
var _a;
|
|
270
269
|
const name = node.name.value;
|
|
271
270
|
if (node.values) {
|
|
272
|
-
|
|
273
|
-
picks.enums[name] = [];
|
|
274
|
-
}
|
|
271
|
+
(_a = picks.enums)[name] || (_a[name] = []);
|
|
275
272
|
node.values.forEach(field => {
|
|
276
273
|
picks.enums[name].push(field.name.value);
|
|
277
274
|
});
|
package/cjs/index.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.preset = void 0;
|
|
4
|
-
const graphql_1 = require("graphql");
|
|
5
4
|
const path_1 = require("path");
|
|
6
|
-
const utils_js_1 = require("./utils.js");
|
|
7
|
-
const builder_js_1 = require("./builder.js");
|
|
8
5
|
const visitor_plugin_common_1 = require("@graphql-codegen/visitor-plugin-common");
|
|
6
|
+
const graphql_1 = require("graphql");
|
|
7
|
+
const builder_js_1 = require("./builder.js");
|
|
8
|
+
const utils_js_1 = require("./utils.js");
|
|
9
9
|
exports.preset = {
|
|
10
10
|
buildGeneratesSection: options => {
|
|
11
|
+
var _a;
|
|
11
12
|
const { baseOutputDir } = options;
|
|
12
13
|
const { baseTypesPath, encapsulateModuleTypes } = options.presetConfig;
|
|
13
14
|
const useGraphQLModules = (0, visitor_plugin_common_1.getConfigValue)(options === null || options === void 0 ? void 0 : options.presetConfig.useGraphQLModules, true);
|
|
@@ -18,7 +19,7 @@ exports.preset = {
|
|
|
18
19
|
if (!baseTypesPath) {
|
|
19
20
|
throw new Error(`Preset "graphql-modules" requires you to specify "baseTypesPath" configuration and point it to your base types file (generated by "typescript" plugin)!`);
|
|
20
21
|
}
|
|
21
|
-
if (!options.schemaAst ||
|
|
22
|
+
if (!((_a = options.schemaAst) === null || _a === void 0 ? void 0 : _a.extensions.sources)) {
|
|
22
23
|
throw new Error(`Preset "graphql-modules" requires to use GraphQL SDL`);
|
|
23
24
|
}
|
|
24
25
|
const extensions = options.schemaAst.extensions;
|
|
@@ -76,7 +77,7 @@ exports.preset = {
|
|
|
76
77
|
schema: options.schema,
|
|
77
78
|
documents: [],
|
|
78
79
|
plugins: [
|
|
79
|
-
...options.plugins.filter(p => typeof p === 'object' &&
|
|
80
|
+
...options.plugins.filter(p => typeof p === 'object' && Boolean(p.add)),
|
|
80
81
|
{
|
|
81
82
|
'graphql-modules-plugin': {},
|
|
82
83
|
},
|
package/cjs/utils.js
CHANGED
|
@@ -132,9 +132,7 @@ function groupSourcesByModule(sources, basePath) {
|
|
|
132
132
|
if (relativePath) {
|
|
133
133
|
// PERF: we could guess the module by matching source.location with a list of already resolved paths
|
|
134
134
|
const mod = extractModuleDirectory(source.location, basePath);
|
|
135
|
-
|
|
136
|
-
grouped[mod] = [];
|
|
137
|
-
}
|
|
135
|
+
grouped[mod] || (grouped[mod] = []);
|
|
138
136
|
grouped[mod].push(source);
|
|
139
137
|
}
|
|
140
138
|
});
|
package/esm/builder.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { visit, Kind, isScalarType, } from 'graphql';
|
|
2
1
|
import { pascalCase } from 'change-case-all';
|
|
3
|
-
import {
|
|
2
|
+
import { isScalarType, Kind, visit, } from 'graphql';
|
|
3
|
+
import { buildBlock, collectUsedTypes, concatByKey, createObject, indent, pushUnique, unique, uniqueByKey, withQuotes, } from './utils.js';
|
|
4
4
|
const registryKeys = ['objects', 'inputs', 'interfaces', 'scalars', 'unions', 'enums'];
|
|
5
5
|
const resolverKeys = ['scalars', 'objects', 'enums'];
|
|
6
6
|
export function buildModule(name, doc, { importNamespace, importPath, encapsulate, requireRootResolvers, shouldDeclare, rootTypes, schema, baseVisitor, useGraphQLModules, useTypeImports = false, }) {
|
|
@@ -161,7 +161,7 @@ export function buildModule(name, doc, { importNamespace, importPath, encapsulat
|
|
|
161
161
|
const lines = [];
|
|
162
162
|
for (const kind in registry) {
|
|
163
163
|
const k = kind;
|
|
164
|
-
if (
|
|
164
|
+
if (Object.prototype.hasOwnProperty.call(registry, k) && resolverKeys.includes(k)) {
|
|
165
165
|
const types = registry[k];
|
|
166
166
|
types.forEach(typeName => {
|
|
167
167
|
if (k === 'enums') {
|
|
@@ -191,7 +191,7 @@ export function buildModule(name, doc, { importNamespace, importPath, encapsulat
|
|
|
191
191
|
const blocks = [buildBlock({ name: `${withQuotes('*')}?:`, lines: [wildcardField] })];
|
|
192
192
|
// Type.Field
|
|
193
193
|
for (const typeName in picks.objects) {
|
|
194
|
-
if (
|
|
194
|
+
if (Object.prototype.hasOwnProperty.call(picks.objects, typeName)) {
|
|
195
195
|
const fields = picks.objects[typeName];
|
|
196
196
|
const lines = [wildcardField].concat(fields.map(field => printResolveMiddlewareRecord(field)));
|
|
197
197
|
blocks.push(buildBlock({
|
|
@@ -255,20 +255,17 @@ export function buildModule(name, doc, { importNamespace, importPath, encapsulat
|
|
|
255
255
|
function collectFields(node, picksObj) {
|
|
256
256
|
const name = node.name.value;
|
|
257
257
|
if (node.fields) {
|
|
258
|
-
|
|
259
|
-
picksObj[name] = [];
|
|
260
|
-
}
|
|
258
|
+
picksObj[name] || (picksObj[name] = []);
|
|
261
259
|
node.fields.forEach(field => {
|
|
262
260
|
picksObj[name].push(field.name.value);
|
|
263
261
|
});
|
|
264
262
|
}
|
|
265
263
|
}
|
|
266
264
|
function collectValuesFromEnum(node) {
|
|
265
|
+
var _a;
|
|
267
266
|
const name = node.name.value;
|
|
268
267
|
if (node.values) {
|
|
269
|
-
|
|
270
|
-
picks.enums[name] = [];
|
|
271
|
-
}
|
|
268
|
+
(_a = picks.enums)[name] || (_a[name] = []);
|
|
272
269
|
node.values.forEach(field => {
|
|
273
270
|
picks.enums[name].push(field.name.value);
|
|
274
271
|
});
|
package/esm/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { join, relative, resolve } from 'path';
|
|
2
|
+
import { BaseVisitor, getConfigValue } from '@graphql-codegen/visitor-plugin-common';
|
|
1
3
|
import { concatAST, isScalarType } from 'graphql';
|
|
2
|
-
import { resolve, relative, join } from 'path';
|
|
3
|
-
import { groupSourcesByModule, stripFilename, normalize, isGraphQLPrimitive } from './utils.js';
|
|
4
4
|
import { buildModule } from './builder.js';
|
|
5
|
-
import {
|
|
5
|
+
import { groupSourcesByModule, isGraphQLPrimitive, normalize, stripFilename } from './utils.js';
|
|
6
6
|
export const preset = {
|
|
7
7
|
buildGeneratesSection: options => {
|
|
8
|
+
var _a;
|
|
8
9
|
const { baseOutputDir } = options;
|
|
9
10
|
const { baseTypesPath, encapsulateModuleTypes } = options.presetConfig;
|
|
10
11
|
const useGraphQLModules = getConfigValue(options === null || options === void 0 ? void 0 : options.presetConfig.useGraphQLModules, true);
|
|
@@ -15,7 +16,7 @@ export const preset = {
|
|
|
15
16
|
if (!baseTypesPath) {
|
|
16
17
|
throw new Error(`Preset "graphql-modules" requires you to specify "baseTypesPath" configuration and point it to your base types file (generated by "typescript" plugin)!`);
|
|
17
18
|
}
|
|
18
|
-
if (!options.schemaAst ||
|
|
19
|
+
if (!((_a = options.schemaAst) === null || _a === void 0 ? void 0 : _a.extensions.sources)) {
|
|
19
20
|
throw new Error(`Preset "graphql-modules" requires to use GraphQL SDL`);
|
|
20
21
|
}
|
|
21
22
|
const extensions = options.schemaAst.extensions;
|
|
@@ -73,7 +74,7 @@ export const preset = {
|
|
|
73
74
|
schema: options.schema,
|
|
74
75
|
documents: [],
|
|
75
76
|
plugins: [
|
|
76
|
-
...options.plugins.filter(p => typeof p === 'object' &&
|
|
77
|
+
...options.plugins.filter(p => typeof p === 'object' && Boolean(p.add)),
|
|
77
78
|
{
|
|
78
79
|
'graphql-modules-plugin': {},
|
|
79
80
|
},
|
package/esm/utils.js
CHANGED
|
@@ -121,9 +121,7 @@ export function groupSourcesByModule(sources, basePath) {
|
|
|
121
121
|
if (relativePath) {
|
|
122
122
|
// PERF: we could guess the module by matching source.location with a list of already resolved paths
|
|
123
123
|
const mod = extractModuleDirectory(source.location, basePath);
|
|
124
|
-
|
|
125
|
-
grouped[mod] = [];
|
|
126
|
-
}
|
|
124
|
+
grouped[mod] || (grouped[mod] = []);
|
|
127
125
|
grouped[mod].push(source);
|
|
128
126
|
}
|
|
129
127
|
});
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/graphql-modules-preset",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.12-alpha-20230109071557-db6d5c74b",
|
|
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
9
|
"@graphql-codegen/plugin-helpers": "^3.1.2",
|
|
10
|
-
"@graphql-codegen/visitor-plugin-common": "2.13.
|
|
10
|
+
"@graphql-codegen/visitor-plugin-common": "2.13.8-alpha-20230109071557-db6d5c74b",
|
|
11
11
|
"@graphql-tools/utils": "^9.0.0",
|
|
12
12
|
"parse-filepath": "^1.0.2",
|
|
13
13
|
"change-case-all": "1.0.15",
|
package/typings/builder.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { BaseVisitor } from '@graphql-codegen/visitor-plugin-common';
|
|
1
2
|
import { DocumentNode, GraphQLSchema } from 'graphql';
|
|
2
3
|
import { ModulesConfig } from './config.cjs';
|
|
3
|
-
import { BaseVisitor } from '@graphql-codegen/visitor-plugin-common';
|
|
4
4
|
export declare function buildModule(name: string, doc: DocumentNode, { importNamespace, importPath, encapsulate, requireRootResolvers, shouldDeclare, rootTypes, schema, baseVisitor, useGraphQLModules, useTypeImports, }: {
|
|
5
5
|
importNamespace: string;
|
|
6
6
|
importPath: string;
|
package/typings/builder.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { BaseVisitor } from '@graphql-codegen/visitor-plugin-common';
|
|
1
2
|
import { DocumentNode, GraphQLSchema } from 'graphql';
|
|
2
3
|
import { ModulesConfig } from './config.js';
|
|
3
|
-
import { BaseVisitor } from '@graphql-codegen/visitor-plugin-common';
|
|
4
4
|
export declare function buildModule(name: string, doc: DocumentNode, { importNamespace, importPath, encapsulate, requireRootResolvers, shouldDeclare, rootTypes, schema, baseVisitor, useGraphQLModules, useTypeImports, }: {
|
|
5
5
|
importNamespace: string;
|
|
6
6
|
importPath: string;
|
package/typings/utils.d.cts
CHANGED
package/typings/utils.d.ts
CHANGED