@graphql-codegen/core 2.6.3-alpha-20221031143038-b4e11f6bc → 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 +6 -5
- package/cjs/utils.js +1 -24
- package/esm/codegen.js +8 -7
- package/esm/utils.js +1 -23
- package/package.json +3 -3
- package/typings/utils.d.cts +1 -3
- package/typings/utils.d.ts +1 -3
package/cjs/codegen.js
CHANGED
|
@@ -60,17 +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, () =>
|
|
70
|
-
? (0, utils_js_1.fastValidateGraphQLDocuments)(schemaInstance, [...documents, ...fragments], rules)
|
|
71
|
-
: (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)));
|
|
72
70
|
}, 'Validate documents against schema');
|
|
73
|
-
|
|
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
|
+
}
|
|
74
75
|
}
|
|
75
76
|
const prepend = new Set();
|
|
76
77
|
const append = new Set();
|
package/cjs/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
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,26 +77,3 @@ 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
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
|
-
import { extractHashFromSchema,
|
|
6
|
+
import { extractHashFromSchema, 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 || [];
|
|
@@ -57,17 +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, () =>
|
|
67
|
-
? fastValidateGraphQLDocuments(schemaInstance, [...documents, ...fragments], rules)
|
|
68
|
-
: 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)));
|
|
69
67
|
}, 'Validate documents against schema');
|
|
70
|
-
|
|
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
|
+
}
|
|
71
72
|
}
|
|
72
73
|
const prepend = new Set();
|
|
73
74
|
const append = new Set();
|
package/esm/utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isDocumentNode } from '@graphql-tools/utils';
|
|
2
|
-
import { isSchema, Kind
|
|
2
|
+
import { isSchema, Kind } from 'graphql';
|
|
3
3
|
export function isObjectMap(obj) {
|
|
4
4
|
return obj && typeof obj === 'object' && !Array.isArray(obj);
|
|
5
5
|
}
|
|
@@ -66,25 +66,3 @@ 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,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": {
|
package/typings/utils.d.cts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Types } from '@graphql-codegen/plugin-helpers';
|
|
2
|
-
import {
|
|
3
|
-
import { DocumentNode, GraphQLSchema, ValidationRule } from 'graphql';
|
|
2
|
+
import { DocumentNode, GraphQLSchema } from 'graphql';
|
|
4
3
|
export declare function isObjectMap(obj: any): obj is Types.PluginConfig<any>;
|
|
5
4
|
export declare function prioritize<T>(...values: T[]): T;
|
|
6
5
|
export declare function pickFlag<TConfig, TKey extends keyof TConfig>(flag: TKey, config: TConfig): TConfig[TKey] | undefined;
|
|
@@ -9,4 +8,3 @@ export declare function shouldValidateDocumentsAgainstSchema(skipDocumentsValida
|
|
|
9
8
|
export declare function getSkipDocumentsValidationOption(options: Types.GenerateOptions): Types.SkipDocumentsValidationOptions;
|
|
10
9
|
export declare function hasFederationSpec(schemaOrAST: GraphQLSchema | DocumentNode): boolean;
|
|
11
10
|
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,6 +1,5 @@
|
|
|
1
1
|
import { Types } from '@graphql-codegen/plugin-helpers';
|
|
2
|
-
import {
|
|
3
|
-
import { DocumentNode, GraphQLSchema, ValidationRule } from 'graphql';
|
|
2
|
+
import { DocumentNode, GraphQLSchema } from 'graphql';
|
|
4
3
|
export declare function isObjectMap(obj: any): obj is Types.PluginConfig<any>;
|
|
5
4
|
export declare function prioritize<T>(...values: T[]): T;
|
|
6
5
|
export declare function pickFlag<TConfig, TKey extends keyof TConfig>(flag: TKey, config: TConfig): TConfig[TKey] | undefined;
|
|
@@ -9,4 +8,3 @@ export declare function shouldValidateDocumentsAgainstSchema(skipDocumentsValida
|
|
|
9
8
|
export declare function getSkipDocumentsValidationOption(options: Types.GenerateOptions): Types.SkipDocumentsValidationOptions;
|
|
10
9
|
export declare function hasFederationSpec(schemaOrAST: GraphQLSchema | DocumentNode): boolean;
|
|
11
10
|
export declare function extractHashFromSchema(schema: GraphQLSchema): string | null;
|
|
12
|
-
export declare function fastValidateGraphQLDocuments(schema: GraphQLSchema, documentFiles: Source[], effectiveRules?: ValidationRule[]): Promise<readonly LoadDocumentError[]>;
|