@graphql-codegen/core 6.2.0 → 6.2.1-alpha-20260925063940-9ae630f839ac00a5cd73196e832697845f07b30e

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
@@ -87,20 +87,21 @@ async function codegen(options) {
87
87
  }));
88
88
  const rules = graphql_1.specifiedRules.filter(rule => !ignored.some(ignoredRule => rule.name.startsWith(ignoredRule)));
89
89
  const schemaHash = (0, utils_js_1.extractHashFromSchema)(schemaInstance);
90
+ const documentHashes = transformedDocuments.map(d => d.hash);
90
91
  if (!schemaHash ||
91
92
  !options.cache ||
92
- transformedDocuments.some(d => typeof d.hash !== 'string')) {
93
+ !documentHashes.every((hash) => typeof hash === 'string')) {
93
94
  return Promise.resolve((0, utils_1.validateGraphQlDocuments)(schemaInstance, [
94
- ...transformedDocuments.flatMap(d => d.document),
95
+ ...transformedDocuments.flatMap(d => (d.document ? [d.document] : [])),
95
96
  ...fragments.flatMap(f => f.document),
96
97
  ], rules));
97
98
  }
98
99
  const cacheKey = [schemaHash]
99
- .concat(transformedDocuments.map(doc => doc.hash))
100
+ .concat(documentHashes)
100
101
  .concat(JSON.stringify(fragments))
101
102
  .join(',');
102
103
  return options.cache('documents-validation', cacheKey, () => Promise.resolve((0, utils_1.validateGraphQlDocuments)(schemaInstance, [
103
- ...transformedDocuments.flatMap(d => d.document),
104
+ ...transformedDocuments.flatMap(d => (d.document ? [d.document] : [])),
104
105
  ...fragments.flatMap(f => f.document),
105
106
  ], rules)));
106
107
  }, 'Validate documents against schema');
@@ -21,10 +21,11 @@ async function executePlugin(options, plugin) {
21
21
  const documents = options.documents || [];
22
22
  const pluginContext = options.pluginContext || {};
23
23
  const profiler = options.profiler ?? (0, plugin_helpers_1.createNoopProfiler)();
24
- if (plugin.validate && typeof plugin.validate === 'function') {
24
+ const validate = plugin.validate?.bind(plugin);
25
+ if (validate && typeof validate === 'function') {
25
26
  try {
26
27
  // FIXME: Sync validate signature with plugin signature
27
- await profiler.run(async () => plugin.validate(outputSchema, documents, options.config, options.outputFilename, options.allPlugins, pluginContext), `Plugin ${options.name} validate`);
28
+ await profiler.run(async () => validate(outputSchema, documents, options.config, options.outputFilename, options.allPlugins, pluginContext), `Plugin ${options.name} validate`);
28
29
  }
29
30
  catch (e) {
30
31
  throw new Error(`Plugin "${options.name}" validation failed: \n
package/esm/codegen.js CHANGED
@@ -83,20 +83,21 @@ export async function codegen(options) {
83
83
  }));
84
84
  const rules = specifiedRules.filter(rule => !ignored.some(ignoredRule => rule.name.startsWith(ignoredRule)));
85
85
  const schemaHash = extractHashFromSchema(schemaInstance);
86
+ const documentHashes = transformedDocuments.map(d => d.hash);
86
87
  if (!schemaHash ||
87
88
  !options.cache ||
88
- transformedDocuments.some(d => typeof d.hash !== 'string')) {
89
+ !documentHashes.every((hash) => typeof hash === 'string')) {
89
90
  return Promise.resolve(validateGraphQlDocuments(schemaInstance, [
90
- ...transformedDocuments.flatMap(d => d.document),
91
+ ...transformedDocuments.flatMap(d => (d.document ? [d.document] : [])),
91
92
  ...fragments.flatMap(f => f.document),
92
93
  ], rules));
93
94
  }
94
95
  const cacheKey = [schemaHash]
95
- .concat(transformedDocuments.map(doc => doc.hash))
96
+ .concat(documentHashes)
96
97
  .concat(JSON.stringify(fragments))
97
98
  .join(',');
98
99
  return options.cache('documents-validation', cacheKey, () => Promise.resolve(validateGraphQlDocuments(schemaInstance, [
99
- ...transformedDocuments.flatMap(d => d.document),
100
+ ...transformedDocuments.flatMap(d => (d.document ? [d.document] : [])),
100
101
  ...fragments.flatMap(f => f.document),
101
102
  ], rules)));
102
103
  }, 'Validate documents against schema');
@@ -18,10 +18,11 @@ export async function executePlugin(options, plugin) {
18
18
  const documents = options.documents || [];
19
19
  const pluginContext = options.pluginContext || {};
20
20
  const profiler = options.profiler ?? createNoopProfiler();
21
- if (plugin.validate && typeof plugin.validate === 'function') {
21
+ const validate = plugin.validate?.bind(plugin);
22
+ if (validate && typeof validate === 'function') {
22
23
  try {
23
24
  // FIXME: Sync validate signature with plugin signature
24
- await profiler.run(async () => plugin.validate(outputSchema, documents, options.config, options.outputFilename, options.allPlugins, pluginContext), `Plugin ${options.name} validate`);
25
+ await profiler.run(async () => validate(outputSchema, documents, options.config, options.outputFilename, options.allPlugins, pluginContext), `Plugin ${options.name} validate`);
25
26
  }
26
27
  catch (e) {
27
28
  throw new Error(`Plugin "${options.name}" validation failed: \n
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@graphql-codegen/core",
3
- "version": "6.2.0",
3
+ "version": "6.2.1-alpha-20260925063940-9ae630f839ac00a5cd73196e832697845f07b30e",
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 || ^17.0.0"
6
6
  },
7
7
  "dependencies": {
8
+ "@graphql-codegen/plugin-helpers": "^7.3.0",
8
9
  "@graphql-tools/schema": "^10.0.0",
9
10
  "@graphql-tools/utils": "^11.2.0",
10
- "tslib": "^2.8.0",
11
- "@graphql-codegen/plugin-helpers": "^7.1.0"
11
+ "tslib": "^2.8.0"
12
12
  },
13
13
  "repository": {
14
14
  "type": "git",