@graphql-codegen/graphql-modules-preset 2.5.11 → 2.5.12-alpha-20230109074516-4d59d62ba

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 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 (registry.hasOwnProperty(k) && resolverKeys.includes(k)) {
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 (picks.objects.hasOwnProperty(typeName)) {
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
- if (!picksObj[name]) {
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
- if (!picks.enums[name]) {
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 || !options.schemaAst.extensions.sources) {
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' && !!p.add),
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
- if (!grouped[mod]) {
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 { unique, withQuotes, buildBlock, pushUnique, concatByKey, uniqueByKey, createObject, collectUsedTypes, indent, } from './utils.js';
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 (registry.hasOwnProperty(k) && resolverKeys.includes(k)) {
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 (picks.objects.hasOwnProperty(typeName)) {
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
- if (!picksObj[name]) {
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
- if (!picks.enums[name]) {
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 { BaseVisitor, getConfigValue } from '@graphql-codegen/visitor-plugin-common';
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 || !options.schemaAst.extensions.sources) {
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' && !!p.add),
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
- if (!grouped[mod]) {
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.11",
3
+ "version": "2.5.12-alpha-20230109074516-4d59d62ba",
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.7",
10
+ "@graphql-codegen/visitor-plugin-common": "2.13.8-alpha-20230109074516-4d59d62ba",
11
11
  "@graphql-tools/utils": "^9.0.0",
12
12
  "parse-filepath": "^1.0.2",
13
13
  "change-case-all": "1.0.15",
@@ -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;
@@ -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;
@@ -1,5 +1,5 @@
1
- import { DocumentNode, NamedTypeNode, TypeNode } from 'graphql';
2
1
  import { Source } from '@graphql-tools/utils';
2
+ import { DocumentNode, NamedTypeNode, TypeNode } from 'graphql';
3
3
  /**
4
4
  * Searches every node to collect used types
5
5
  */
@@ -1,5 +1,5 @@
1
- import { DocumentNode, NamedTypeNode, TypeNode } from 'graphql';
2
1
  import { Source } from '@graphql-tools/utils';
2
+ import { DocumentNode, NamedTypeNode, TypeNode } from 'graphql';
3
3
  /**
4
4
  * Searches every node to collect used types
5
5
  */