@graphql-codegen/core 2.6.3-alpha-20221025134913-ec8a36be2 → 2.6.3-alpha-20221031143038-b4e11f6bc
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 +5 -2
- package/cjs/execute-plugin.js +2 -2
- package/cjs/utils.js +24 -1
- package/esm/codegen.js +7 -4
- package/esm/execute-plugin.js +3 -3
- package/esm/utils.js +23 -1
- package/package.json +2 -2
- package/typings/utils.d.cts +3 -1
- package/typings/utils.d.ts +3 -1
package/cjs/codegen.js
CHANGED
|
@@ -66,7 +66,9 @@ async function codegen(options) {
|
|
|
66
66
|
.concat(documents.map(doc => doc.hash))
|
|
67
67
|
.concat(JSON.stringify(fragments))
|
|
68
68
|
.join(',');
|
|
69
|
-
return options.cache('documents-validation', cacheKey, () =>
|
|
69
|
+
return options.cache('documents-validation', cacheKey, () => options.documentsValidator === 'codegen'
|
|
70
|
+
? (0, utils_js_1.fastValidateGraphQLDocuments)(schemaInstance, [...documents, ...fragments], rules)
|
|
71
|
+
: (0, utils_1.validateGraphQlDocuments)(schemaInstance, [...documents, ...fragments], rules));
|
|
70
72
|
}, 'Validate documents against schema');
|
|
71
73
|
(0, utils_1.checkValidationErrors)(errors);
|
|
72
74
|
}
|
|
@@ -206,7 +208,8 @@ function validateDuplicateDocuments(files) {
|
|
|
206
208
|
`.trimRight())
|
|
207
209
|
.join('');
|
|
208
210
|
const definitionKindName = kind.replace('Definition', '').toLowerCase();
|
|
209
|
-
throw new
|
|
211
|
+
throw new plugin_helpers_1.DetailedError(`Not all ${definitionKindName}s have an unique name: ${duplicated.join(', ')}`, `
|
|
212
|
+
Not all ${definitionKindName}s have an unique name
|
|
210
213
|
${list}
|
|
211
214
|
`);
|
|
212
215
|
}
|
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/cjs/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractHashFromSchema = exports.hasFederationSpec = exports.getSkipDocumentsValidationOption = exports.shouldValidateDocumentsAgainstSchema = exports.shouldValidateDuplicateDocuments = exports.pickFlag = exports.prioritize = exports.isObjectMap = void 0;
|
|
3
|
+
exports.fastValidateGraphQLDocuments = exports.extractHashFromSchema = exports.hasFederationSpec = exports.getSkipDocumentsValidationOption = exports.shouldValidateDocumentsAgainstSchema = exports.shouldValidateDuplicateDocuments = exports.pickFlag = exports.prioritize = exports.isObjectMap = void 0;
|
|
4
4
|
const utils_1 = require("@graphql-tools/utils");
|
|
5
5
|
const graphql_1 = require("graphql");
|
|
6
6
|
function isObjectMap(obj) {
|
|
@@ -77,3 +77,26 @@ function extractHashFromSchema(schema) {
|
|
|
77
77
|
return (_a = schema.extensions['hash']) !== null && _a !== void 0 ? _a : null;
|
|
78
78
|
}
|
|
79
79
|
exports.extractHashFromSchema = extractHashFromSchema;
|
|
80
|
+
function fastValidateGraphQLDocuments(schema, documentFiles, effectiveRules) {
|
|
81
|
+
const document = {
|
|
82
|
+
kind: graphql_1.Kind.DOCUMENT,
|
|
83
|
+
definitions: documentFiles.flatMap(df => df.document.definitions),
|
|
84
|
+
};
|
|
85
|
+
const errors = (0, graphql_1.validate)(schema, document, effectiveRules);
|
|
86
|
+
if (errors) {
|
|
87
|
+
return Promise.reject(errors.reduce((acc, e) => {
|
|
88
|
+
if (!acc[e.name]) {
|
|
89
|
+
acc[e.name] = {
|
|
90
|
+
filePath: e.name,
|
|
91
|
+
errors: [],
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
acc[e.name].errors.push(e);
|
|
95
|
+
return acc;
|
|
96
|
+
}, {}));
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
return Promise.resolve([]);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.fastValidateGraphQLDocuments = fastValidateGraphQLDocuments;
|
package/esm/codegen.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
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
4
|
import { checkValidationErrors, validateGraphQlDocuments, asArray } from '@graphql-tools/utils';
|
|
5
5
|
import { mergeSchemas } from '@graphql-tools/schema';
|
|
6
|
-
import { extractHashFromSchema, getSkipDocumentsValidationOption, hasFederationSpec, pickFlag, prioritize, shouldValidateDocumentsAgainstSchema, shouldValidateDuplicateDocuments, } from './utils.js';
|
|
6
|
+
import { extractHashFromSchema, fastValidateGraphQLDocuments, getSkipDocumentsValidationOption, hasFederationSpec, pickFlag, prioritize, shouldValidateDocumentsAgainstSchema, shouldValidateDuplicateDocuments, } from './utils.js';
|
|
7
7
|
export async function codegen(options) {
|
|
8
8
|
var _a;
|
|
9
9
|
const documents = options.documents || [];
|
|
@@ -63,7 +63,9 @@ export async function codegen(options) {
|
|
|
63
63
|
.concat(documents.map(doc => doc.hash))
|
|
64
64
|
.concat(JSON.stringify(fragments))
|
|
65
65
|
.join(',');
|
|
66
|
-
return options.cache('documents-validation', cacheKey, () =>
|
|
66
|
+
return options.cache('documents-validation', cacheKey, () => options.documentsValidator === 'codegen'
|
|
67
|
+
? fastValidateGraphQLDocuments(schemaInstance, [...documents, ...fragments], rules)
|
|
68
|
+
: validateGraphQlDocuments(schemaInstance, [...documents, ...fragments], rules));
|
|
67
69
|
}, 'Validate documents against schema');
|
|
68
70
|
checkValidationErrors(errors);
|
|
69
71
|
}
|
|
@@ -201,7 +203,8 @@ function validateDuplicateDocuments(files) {
|
|
|
201
203
|
`.trimRight())
|
|
202
204
|
.join('');
|
|
203
205
|
const definitionKindName = kind.replace('Definition', '').toLowerCase();
|
|
204
|
-
throw new
|
|
206
|
+
throw new DetailedError(`Not all ${definitionKindName}s have an unique name: ${duplicated.join(', ')}`, `
|
|
207
|
+
Not all ${definitionKindName}s have an unique name
|
|
205
208
|
${list}
|
|
206
209
|
`);
|
|
207
210
|
}
|
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/esm/utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isDocumentNode } from '@graphql-tools/utils';
|
|
2
|
-
import { isSchema, Kind } from 'graphql';
|
|
2
|
+
import { isSchema, Kind, validate } from 'graphql';
|
|
3
3
|
export function isObjectMap(obj) {
|
|
4
4
|
return obj && typeof obj === 'object' && !Array.isArray(obj);
|
|
5
5
|
}
|
|
@@ -66,3 +66,25 @@ export function extractHashFromSchema(schema) {
|
|
|
66
66
|
}
|
|
67
67
|
return (_a = schema.extensions['hash']) !== null && _a !== void 0 ? _a : null;
|
|
68
68
|
}
|
|
69
|
+
export function fastValidateGraphQLDocuments(schema, documentFiles, effectiveRules) {
|
|
70
|
+
const document = {
|
|
71
|
+
kind: Kind.DOCUMENT,
|
|
72
|
+
definitions: documentFiles.flatMap(df => df.document.definitions),
|
|
73
|
+
};
|
|
74
|
+
const errors = validate(schema, document, effectiveRules);
|
|
75
|
+
if (errors) {
|
|
76
|
+
return Promise.reject(errors.reduce((acc, e) => {
|
|
77
|
+
if (!acc[e.name]) {
|
|
78
|
+
acc[e.name] = {
|
|
79
|
+
filePath: e.name,
|
|
80
|
+
errors: [],
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
acc[e.name].errors.push(e);
|
|
84
|
+
return acc;
|
|
85
|
+
}, {}));
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
return Promise.resolve([]);
|
|
89
|
+
}
|
|
90
|
+
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/core",
|
|
3
|
-
"version": "2.6.3-alpha-
|
|
3
|
+
"version": "2.6.3-alpha-20221031143038-b4e11f6bc",
|
|
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-20221031143038-b4e11f6bc",
|
|
9
9
|
"@graphql-tools/schema": "^9.0.0",
|
|
10
10
|
"@graphql-tools/utils": "^8.8.0",
|
|
11
11
|
"tslib": "~2.4.0"
|
package/typings/utils.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Types } from '@graphql-codegen/plugin-helpers';
|
|
2
|
-
import {
|
|
2
|
+
import { LoadDocumentError, Source } from '@graphql-tools/utils';
|
|
3
|
+
import { DocumentNode, GraphQLSchema, ValidationRule } from 'graphql';
|
|
3
4
|
export declare function isObjectMap(obj: any): obj is Types.PluginConfig<any>;
|
|
4
5
|
export declare function prioritize<T>(...values: T[]): T;
|
|
5
6
|
export declare function pickFlag<TConfig, TKey extends keyof TConfig>(flag: TKey, config: TConfig): TConfig[TKey] | undefined;
|
|
@@ -8,3 +9,4 @@ export declare function shouldValidateDocumentsAgainstSchema(skipDocumentsValida
|
|
|
8
9
|
export declare function getSkipDocumentsValidationOption(options: Types.GenerateOptions): Types.SkipDocumentsValidationOptions;
|
|
9
10
|
export declare function hasFederationSpec(schemaOrAST: GraphQLSchema | DocumentNode): boolean;
|
|
10
11
|
export declare function extractHashFromSchema(schema: GraphQLSchema): string | null;
|
|
12
|
+
export declare function fastValidateGraphQLDocuments(schema: GraphQLSchema, documentFiles: Source[], effectiveRules?: ValidationRule[]): Promise<readonly LoadDocumentError[]>;
|
package/typings/utils.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Types } from '@graphql-codegen/plugin-helpers';
|
|
2
|
-
import {
|
|
2
|
+
import { LoadDocumentError, Source } from '@graphql-tools/utils';
|
|
3
|
+
import { DocumentNode, GraphQLSchema, ValidationRule } from 'graphql';
|
|
3
4
|
export declare function isObjectMap(obj: any): obj is Types.PluginConfig<any>;
|
|
4
5
|
export declare function prioritize<T>(...values: T[]): T;
|
|
5
6
|
export declare function pickFlag<TConfig, TKey extends keyof TConfig>(flag: TKey, config: TConfig): TConfig[TKey] | undefined;
|
|
@@ -8,3 +9,4 @@ export declare function shouldValidateDocumentsAgainstSchema(skipDocumentsValida
|
|
|
8
9
|
export declare function getSkipDocumentsValidationOption(options: Types.GenerateOptions): Types.SkipDocumentsValidationOptions;
|
|
9
10
|
export declare function hasFederationSpec(schemaOrAST: GraphQLSchema | DocumentNode): boolean;
|
|
10
11
|
export declare function extractHashFromSchema(schema: GraphQLSchema): string | null;
|
|
12
|
+
export declare function fastValidateGraphQLDocuments(schema: GraphQLSchema, documentFiles: Source[], effectiveRules?: ValidationRule[]): Promise<readonly LoadDocumentError[]>;
|