@graphql-codegen/core 2.6.3-alpha-20221025134913-ec8a36be2 → 2.6.3-alpha-20221031145604-c8709223b
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 +8 -4
- package/cjs/execute-plugin.js +2 -2
- package/esm/codegen.js +10 -6
- package/esm/execute-plugin.js +3 -3
- package/package.json +3 -3
package/cjs/codegen.js
CHANGED
|
@@ -60,15 +60,18 @@ async function codegen(options) {
|
|
|
60
60
|
const rules = graphql_1.specifiedRules.filter(rule => !ignored.some(ignoredRule => rule.name.startsWith(ignoredRule)));
|
|
61
61
|
const schemaHash = (0, utils_js_1.extractHashFromSchema)(schemaInstance);
|
|
62
62
|
if (!schemaHash || !options.cache || documents.some(d => typeof d.hash !== 'string')) {
|
|
63
|
-
return (0, utils_1.validateGraphQlDocuments)(schemaInstance, [...documents, ...fragments], rules);
|
|
63
|
+
return Promise.resolve((0, utils_1.validateGraphQlDocuments)(schemaInstance, [...documents.flatMap(d => d.document), ...fragments.flatMap(f => f.document)], rules));
|
|
64
64
|
}
|
|
65
65
|
const cacheKey = [schemaHash]
|
|
66
66
|
.concat(documents.map(doc => doc.hash))
|
|
67
67
|
.concat(JSON.stringify(fragments))
|
|
68
68
|
.join(',');
|
|
69
|
-
return options.cache('documents-validation', cacheKey, () => (0, utils_1.validateGraphQlDocuments)(schemaInstance, [...documents, ...fragments], rules));
|
|
69
|
+
return options.cache('documents-validation', cacheKey, () => Promise.resolve((0, utils_1.validateGraphQlDocuments)(schemaInstance, [...documents.flatMap(d => d.document), ...fragments.flatMap(f => f.document)], rules)));
|
|
70
70
|
}, 'Validate documents against schema');
|
|
71
|
-
|
|
71
|
+
if (errors) {
|
|
72
|
+
throw new Error(`GraphQL Document Validation failed with ${errors.length} errors;
|
|
73
|
+
${errors.map((error, index) => `Error ${index}: ${error.stack}`).join('\n\n')}`);
|
|
74
|
+
}
|
|
72
75
|
}
|
|
73
76
|
const prepend = new Set();
|
|
74
77
|
const append = new Set();
|
|
@@ -206,7 +209,8 @@ function validateDuplicateDocuments(files) {
|
|
|
206
209
|
`.trimRight())
|
|
207
210
|
.join('');
|
|
208
211
|
const definitionKindName = kind.replace('Definition', '').toLowerCase();
|
|
209
|
-
throw new
|
|
212
|
+
throw new plugin_helpers_1.DetailedError(`Not all ${definitionKindName}s have an unique name: ${duplicated.join(', ')}`, `
|
|
213
|
+
Not all ${definitionKindName}s have an unique name
|
|
210
214
|
${list}
|
|
211
215
|
`);
|
|
212
216
|
}
|
package/cjs/execute-plugin.js
CHANGED
|
@@ -6,7 +6,7 @@ const graphql_1 = require("graphql");
|
|
|
6
6
|
async function executePlugin(options, plugin) {
|
|
7
7
|
var _a;
|
|
8
8
|
if (!plugin || !plugin.plugin || typeof plugin.plugin !== 'function') {
|
|
9
|
-
throw new
|
|
9
|
+
throw new plugin_helpers_1.DetailedError(`Invalid Custom Plugin "${options.name}"`, `
|
|
10
10
|
Plugin ${options.name} does not export a valid JS object with "plugin" function.
|
|
11
11
|
|
|
12
12
|
Make sure your custom plugin is written in the following form:
|
|
@@ -28,7 +28,7 @@ async function executePlugin(options, plugin) {
|
|
|
28
28
|
await profiler.run(async () => plugin.validate(outputSchema, documents, options.config, options.outputFilename, options.allPlugins, pluginContext), `Plugin ${options.name} validate`);
|
|
29
29
|
}
|
|
30
30
|
catch (e) {
|
|
31
|
-
throw new
|
|
31
|
+
throw new plugin_helpers_1.DetailedError(`Plugin "${options.name}" validation failed:`, `
|
|
32
32
|
${e.message}
|
|
33
33
|
`);
|
|
34
34
|
}
|
package/esm/codegen.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { isComplexPluginOutput, federationSpec, getCachedDocumentNodeFromSchema, createNoopProfiler, } from '@graphql-codegen/plugin-helpers';
|
|
1
|
+
import { DetailedError, isComplexPluginOutput, federationSpec, getCachedDocumentNodeFromSchema, createNoopProfiler, } from '@graphql-codegen/plugin-helpers';
|
|
2
2
|
import { visit, Kind, print, specifiedRules } from 'graphql';
|
|
3
3
|
import { executePlugin } from './execute-plugin.js';
|
|
4
|
-
import {
|
|
4
|
+
import { validateGraphQlDocuments, asArray } from '@graphql-tools/utils';
|
|
5
5
|
import { mergeSchemas } from '@graphql-tools/schema';
|
|
6
6
|
import { extractHashFromSchema, getSkipDocumentsValidationOption, hasFederationSpec, pickFlag, prioritize, shouldValidateDocumentsAgainstSchema, shouldValidateDuplicateDocuments, } from './utils.js';
|
|
7
7
|
export async function codegen(options) {
|
|
@@ -57,15 +57,18 @@ export async function codegen(options) {
|
|
|
57
57
|
const rules = specifiedRules.filter(rule => !ignored.some(ignoredRule => rule.name.startsWith(ignoredRule)));
|
|
58
58
|
const schemaHash = extractHashFromSchema(schemaInstance);
|
|
59
59
|
if (!schemaHash || !options.cache || documents.some(d => typeof d.hash !== 'string')) {
|
|
60
|
-
return validateGraphQlDocuments(schemaInstance, [...documents, ...fragments], rules);
|
|
60
|
+
return Promise.resolve(validateGraphQlDocuments(schemaInstance, [...documents.flatMap(d => d.document), ...fragments.flatMap(f => f.document)], rules));
|
|
61
61
|
}
|
|
62
62
|
const cacheKey = [schemaHash]
|
|
63
63
|
.concat(documents.map(doc => doc.hash))
|
|
64
64
|
.concat(JSON.stringify(fragments))
|
|
65
65
|
.join(',');
|
|
66
|
-
return options.cache('documents-validation', cacheKey, () => validateGraphQlDocuments(schemaInstance, [...documents, ...fragments], rules));
|
|
66
|
+
return options.cache('documents-validation', cacheKey, () => Promise.resolve(validateGraphQlDocuments(schemaInstance, [...documents.flatMap(d => d.document), ...fragments.flatMap(f => f.document)], rules)));
|
|
67
67
|
}, 'Validate documents against schema');
|
|
68
|
-
|
|
68
|
+
if (errors) {
|
|
69
|
+
throw new Error(`GraphQL Document Validation failed with ${errors.length} errors;
|
|
70
|
+
${errors.map((error, index) => `Error ${index}: ${error.stack}`).join('\n\n')}`);
|
|
71
|
+
}
|
|
69
72
|
}
|
|
70
73
|
const prepend = new Set();
|
|
71
74
|
const append = new Set();
|
|
@@ -201,7 +204,8 @@ function validateDuplicateDocuments(files) {
|
|
|
201
204
|
`.trimRight())
|
|
202
205
|
.join('');
|
|
203
206
|
const definitionKindName = kind.replace('Definition', '').toLowerCase();
|
|
204
|
-
throw new
|
|
207
|
+
throw new DetailedError(`Not all ${definitionKindName}s have an unique name: ${duplicated.join(', ')}`, `
|
|
208
|
+
Not all ${definitionKindName}s have an unique name
|
|
205
209
|
${list}
|
|
206
210
|
`);
|
|
207
211
|
}
|
package/esm/execute-plugin.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { createNoopProfiler } from '@graphql-codegen/plugin-helpers';
|
|
1
|
+
import { DetailedError, createNoopProfiler } from '@graphql-codegen/plugin-helpers';
|
|
2
2
|
import { buildASTSchema } from 'graphql';
|
|
3
3
|
export async function executePlugin(options, plugin) {
|
|
4
4
|
var _a;
|
|
5
5
|
if (!plugin || !plugin.plugin || typeof plugin.plugin !== 'function') {
|
|
6
|
-
throw new
|
|
6
|
+
throw new DetailedError(`Invalid Custom Plugin "${options.name}"`, `
|
|
7
7
|
Plugin ${options.name} does not export a valid JS object with "plugin" function.
|
|
8
8
|
|
|
9
9
|
Make sure your custom plugin is written in the following form:
|
|
@@ -25,7 +25,7 @@ export async function executePlugin(options, plugin) {
|
|
|
25
25
|
await profiler.run(async () => plugin.validate(outputSchema, documents, options.config, options.outputFilename, options.allPlugins, pluginContext), `Plugin ${options.name} validate`);
|
|
26
26
|
}
|
|
27
27
|
catch (e) {
|
|
28
|
-
throw new
|
|
28
|
+
throw new DetailedError(`Plugin "${options.name}" validation failed:`, `
|
|
29
29
|
${e.message}
|
|
30
30
|
`);
|
|
31
31
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/core",
|
|
3
|
-
"version": "2.6.3-alpha-
|
|
3
|
+
"version": "2.6.3-alpha-20221031145604-c8709223b",
|
|
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": "2.7.2-alpha-
|
|
8
|
+
"@graphql-codegen/plugin-helpers": "2.7.2-alpha-20221031145604-c8709223b",
|
|
9
9
|
"@graphql-tools/schema": "^9.0.0",
|
|
10
|
-
"@graphql-tools/utils": "
|
|
10
|
+
"@graphql-tools/utils": "9.0.0-alpha-20221031144042-b669677e",
|
|
11
11
|
"tslib": "~2.4.0"
|
|
12
12
|
},
|
|
13
13
|
"repository": {
|