@graphql-codegen/core 3.1.0 → 3.1.1-alpha-20230522105754-148a904b0

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/codegen.js CHANGED
@@ -9,9 +9,8 @@ const execute_plugin_js_1 = require("./execute-plugin.js");
9
9
  const utils_js_1 = require("./utils.js");
10
10
  const transform_document_js_1 = require("./transform-document.js");
11
11
  async function codegen(options) {
12
- var _a;
13
12
  const documents = options.documents || [];
14
- const profiler = (_a = options.profiler) !== null && _a !== void 0 ? _a : (0, plugin_helpers_1.createNoopProfiler)();
13
+ const profiler = options.profiler ?? (0, plugin_helpers_1.createNoopProfiler)();
15
14
  const skipDocumentsValidation = (0, utils_js_1.getSkipDocumentsValidationOption)(options);
16
15
  if (documents.length > 0 && (0, utils_js_1.shouldValidateDuplicateDocuments)(skipDocumentsValidation)) {
17
16
  await profiler.run(async () => validateDuplicateDocuments(documents), 'validateDuplicateDocuments');
@@ -161,13 +160,12 @@ function validateDuplicateDocuments(files) {
161
160
  // duplicated names
162
161
  const definitionMap = {};
163
162
  function addDefinition(file, node, deduplicatedDefinitions) {
164
- var _a, _b, _c;
165
163
  if (typeof node.name !== 'undefined') {
166
- definitionMap[_a = node.kind] || (definitionMap[_a] = {});
167
- (_b = definitionMap[node.kind])[_c = node.name.value] || (_b[_c] = {
164
+ definitionMap[node.kind] ||= {};
165
+ definitionMap[node.kind][node.name.value] ||= {
168
166
  paths: new Set(),
169
167
  contents: new Set(),
170
- });
168
+ };
171
169
  const definitionKindMap = definitionMap[node.kind];
172
170
  const length = definitionKindMap[node.name.value].contents.size;
173
171
  definitionKindMap[node.name.value].paths.add(file.location);
@@ -178,7 +176,7 @@ function validateDuplicateDocuments(files) {
178
176
  }
179
177
  return deduplicatedDefinitions.add(node);
180
178
  }
181
- files.forEach(file => {
179
+ for (const file of files) {
182
180
  const deduplicatedDefinitions = new Set();
183
181
  (0, graphql_1.visit)(file.document, {
184
182
  OperationDefinition(node) {
@@ -189,15 +187,15 @@ function validateDuplicateDocuments(files) {
189
187
  },
190
188
  });
191
189
  file.document.definitions = Array.from(deduplicatedDefinitions);
192
- });
190
+ }
193
191
  const kinds = Object.keys(definitionMap);
194
- kinds.forEach(kind => {
192
+ for (const kind of kinds) {
195
193
  const definitionKindMap = definitionMap[kind];
196
194
  const names = Object.keys(definitionKindMap);
197
195
  if (names.length) {
198
196
  const duplicated = names.filter(name => definitionKindMap[name].contents.size > 1);
199
197
  if (!duplicated.length) {
200
- return;
198
+ continue;
201
199
  }
202
200
  const list = duplicated
203
201
  .map(name => `
@@ -206,15 +204,15 @@ function validateDuplicateDocuments(files) {
206
204
  .map(filepath => {
207
205
  return `
208
206
  - ${filepath}
209
- `.trimRight();
207
+ `.trimEnd();
210
208
  })
211
209
  .join('')}
212
- `.trimRight())
210
+ `.trimEnd())
213
211
  .join('');
214
212
  const definitionKindName = kind.replace('Definition', '').toLowerCase();
215
213
  throw new Error(`Not all ${definitionKindName}s have an unique name: ${duplicated.join(', ')}: \n
216
214
  ${list}
217
215
  `);
218
216
  }
219
- });
217
+ }
220
218
  }
@@ -4,8 +4,7 @@ exports.executePlugin = void 0;
4
4
  const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
5
5
  const graphql_1 = require("graphql");
6
6
  async function executePlugin(options, plugin) {
7
- var _a;
8
- if (!(plugin === null || plugin === void 0 ? void 0 : plugin.plugin) || typeof plugin.plugin !== 'function') {
7
+ if (!plugin?.plugin || typeof plugin.plugin !== 'function') {
9
8
  throw new Error(`Invalid Custom Plugin "${options.name}" \n
10
9
  Plugin ${options.name} does not export a valid JS object with "plugin" function.
11
10
 
@@ -21,7 +20,7 @@ async function executePlugin(options, plugin) {
21
20
  const outputSchema = options.schemaAst || (0, graphql_1.buildASTSchema)(options.schema, options.config);
22
21
  const documents = options.documents || [];
23
22
  const pluginContext = options.pluginContext || {};
24
- const profiler = (_a = options.profiler) !== null && _a !== void 0 ? _a : (0, plugin_helpers_1.createNoopProfiler)();
23
+ const profiler = options.profiler ?? (0, plugin_helpers_1.createNoopProfiler)();
25
24
  if (plugin.validate && typeof plugin.validate === 'function') {
26
25
  try {
27
26
  // FIXME: Sync validate signature with plugin signature
@@ -3,13 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transformDocuments = void 0;
4
4
  const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
5
5
  async function transformDocuments(options) {
6
- var _a;
7
6
  const documentTransforms = options.documentTransforms || [];
8
7
  let documents = options.documents;
9
8
  if (documentTransforms.length === 0 || options.documents.length === 0) {
10
9
  return documents;
11
10
  }
12
- const profiler = (_a = options.profiler) !== null && _a !== void 0 ? _a : (0, plugin_helpers_1.createNoopProfiler)();
11
+ const profiler = options.profiler ?? (0, plugin_helpers_1.createNoopProfiler)();
13
12
  for (const documentTransform of documentTransforms) {
14
13
  const config = typeof documentTransform.config === 'object'
15
14
  ? {
package/cjs/utils.js CHANGED
@@ -70,8 +70,7 @@ function hasFederationSpec(schemaOrAST) {
70
70
  }
71
71
  exports.hasFederationSpec = hasFederationSpec;
72
72
  function extractHashFromSchema(schema) {
73
- var _a;
74
- schema.extensions || (schema.extensions = {});
75
- return (_a = schema.extensions['hash']) !== null && _a !== void 0 ? _a : null;
73
+ schema.extensions ||= {};
74
+ return schema.extensions['hash'] ?? null;
76
75
  }
77
76
  exports.extractHashFromSchema = extractHashFromSchema;
package/esm/codegen.js CHANGED
@@ -6,9 +6,8 @@ import { executePlugin } from './execute-plugin.js';
6
6
  import { extractHashFromSchema, getSkipDocumentsValidationOption, hasFederationSpec, pickFlag, prioritize, shouldValidateDocumentsAgainstSchema, shouldValidateDuplicateDocuments, } from './utils.js';
7
7
  import { transformDocuments } from './transform-document.js';
8
8
  export async function codegen(options) {
9
- var _a;
10
9
  const documents = options.documents || [];
11
- const profiler = (_a = options.profiler) !== null && _a !== void 0 ? _a : createNoopProfiler();
10
+ const profiler = options.profiler ?? createNoopProfiler();
12
11
  const skipDocumentsValidation = getSkipDocumentsValidationOption(options);
13
12
  if (documents.length > 0 && shouldValidateDuplicateDocuments(skipDocumentsValidation)) {
14
13
  await profiler.run(async () => validateDuplicateDocuments(documents), 'validateDuplicateDocuments');
@@ -156,13 +155,12 @@ function validateDuplicateDocuments(files) {
156
155
  // duplicated names
157
156
  const definitionMap = {};
158
157
  function addDefinition(file, node, deduplicatedDefinitions) {
159
- var _a, _b, _c;
160
158
  if (typeof node.name !== 'undefined') {
161
- definitionMap[_a = node.kind] || (definitionMap[_a] = {});
162
- (_b = definitionMap[node.kind])[_c = node.name.value] || (_b[_c] = {
159
+ definitionMap[node.kind] ||= {};
160
+ definitionMap[node.kind][node.name.value] ||= {
163
161
  paths: new Set(),
164
162
  contents: new Set(),
165
- });
163
+ };
166
164
  const definitionKindMap = definitionMap[node.kind];
167
165
  const length = definitionKindMap[node.name.value].contents.size;
168
166
  definitionKindMap[node.name.value].paths.add(file.location);
@@ -173,7 +171,7 @@ function validateDuplicateDocuments(files) {
173
171
  }
174
172
  return deduplicatedDefinitions.add(node);
175
173
  }
176
- files.forEach(file => {
174
+ for (const file of files) {
177
175
  const deduplicatedDefinitions = new Set();
178
176
  visit(file.document, {
179
177
  OperationDefinition(node) {
@@ -184,15 +182,15 @@ function validateDuplicateDocuments(files) {
184
182
  },
185
183
  });
186
184
  file.document.definitions = Array.from(deduplicatedDefinitions);
187
- });
185
+ }
188
186
  const kinds = Object.keys(definitionMap);
189
- kinds.forEach(kind => {
187
+ for (const kind of kinds) {
190
188
  const definitionKindMap = definitionMap[kind];
191
189
  const names = Object.keys(definitionKindMap);
192
190
  if (names.length) {
193
191
  const duplicated = names.filter(name => definitionKindMap[name].contents.size > 1);
194
192
  if (!duplicated.length) {
195
- return;
193
+ continue;
196
194
  }
197
195
  const list = duplicated
198
196
  .map(name => `
@@ -201,15 +199,15 @@ function validateDuplicateDocuments(files) {
201
199
  .map(filepath => {
202
200
  return `
203
201
  - ${filepath}
204
- `.trimRight();
202
+ `.trimEnd();
205
203
  })
206
204
  .join('')}
207
- `.trimRight())
205
+ `.trimEnd())
208
206
  .join('');
209
207
  const definitionKindName = kind.replace('Definition', '').toLowerCase();
210
208
  throw new Error(`Not all ${definitionKindName}s have an unique name: ${duplicated.join(', ')}: \n
211
209
  ${list}
212
210
  `);
213
211
  }
214
- });
212
+ }
215
213
  }
@@ -1,8 +1,7 @@
1
1
  import { createNoopProfiler } from '@graphql-codegen/plugin-helpers';
2
2
  import { buildASTSchema } from 'graphql';
3
3
  export async function executePlugin(options, plugin) {
4
- var _a;
5
- if (!(plugin === null || plugin === void 0 ? void 0 : plugin.plugin) || typeof plugin.plugin !== 'function') {
4
+ if (!plugin?.plugin || typeof plugin.plugin !== 'function') {
6
5
  throw new Error(`Invalid Custom Plugin "${options.name}" \n
7
6
  Plugin ${options.name} does not export a valid JS object with "plugin" function.
8
7
 
@@ -18,7 +17,7 @@ export async function executePlugin(options, plugin) {
18
17
  const outputSchema = options.schemaAst || buildASTSchema(options.schema, options.config);
19
18
  const documents = options.documents || [];
20
19
  const pluginContext = options.pluginContext || {};
21
- const profiler = (_a = options.profiler) !== null && _a !== void 0 ? _a : createNoopProfiler();
20
+ const profiler = options.profiler ?? createNoopProfiler();
22
21
  if (plugin.validate && typeof plugin.validate === 'function') {
23
22
  try {
24
23
  // FIXME: Sync validate signature with plugin signature
@@ -1,12 +1,11 @@
1
1
  import { createNoopProfiler } from '@graphql-codegen/plugin-helpers';
2
2
  export async function transformDocuments(options) {
3
- var _a;
4
3
  const documentTransforms = options.documentTransforms || [];
5
4
  let documents = options.documents;
6
5
  if (documentTransforms.length === 0 || options.documents.length === 0) {
7
6
  return documents;
8
7
  }
9
- const profiler = (_a = options.profiler) !== null && _a !== void 0 ? _a : createNoopProfiler();
8
+ const profiler = options.profiler ?? createNoopProfiler();
10
9
  for (const documentTransform of documentTransforms) {
11
10
  const config = typeof documentTransform.config === 'object'
12
11
  ? {
package/esm/utils.js CHANGED
@@ -60,7 +60,6 @@ export function hasFederationSpec(schemaOrAST) {
60
60
  return false;
61
61
  }
62
62
  export function extractHashFromSchema(schema) {
63
- var _a;
64
- schema.extensions || (schema.extensions = {});
65
- return (_a = schema.extensions['hash']) !== null && _a !== void 0 ? _a : null;
63
+ schema.extensions ||= {};
64
+ return schema.extensions['hash'] ?? null;
66
65
  }
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@graphql-codegen/core",
3
- "version": "3.1.0",
3
+ "version": "3.1.1-alpha-20230522105754-148a904b0",
4
4
  "peerDependencies": {
5
5
  "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"
6
6
  },
7
7
  "dependencies": {
8
- "@graphql-codegen/plugin-helpers": "^4.1.0",
9
- "@graphql-tools/schema": "^9.0.0",
10
- "@graphql-tools/utils": "^9.1.1",
8
+ "@graphql-codegen/plugin-helpers": "4.2.1-alpha-20230522105754-148a904b0",
9
+ "@graphql-tools/schema": "^10.0.0",
10
+ "@graphql-tools/utils": "^10.0.0",
11
11
  "tslib": "~2.5.0"
12
12
  },
13
13
  "repository": {