@graphql-codegen/core 2.4.0 → 2.5.0-alpha-c9cbc7d69.0
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/execute-plugin.d.ts +2 -1
- package/index.js +27 -20
- package/index.mjs +28 -21
- package/package.json +2 -2
package/execute-plugin.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Types, CodegenPlugin } from '@graphql-codegen/plugin-helpers';
|
|
1
|
+
import { Types, CodegenPlugin, Profiler } from '@graphql-codegen/plugin-helpers';
|
|
2
2
|
import { DocumentNode, GraphQLSchema } from 'graphql';
|
|
3
3
|
export interface ExecutePluginOptions {
|
|
4
4
|
name: string;
|
|
@@ -13,5 +13,6 @@ export interface ExecutePluginOptions {
|
|
|
13
13
|
pluginContext?: {
|
|
14
14
|
[key: string]: any;
|
|
15
15
|
};
|
|
16
|
+
profiler?: Profiler;
|
|
16
17
|
}
|
|
17
18
|
export declare function executePlugin(options: ExecutePluginOptions, plugin: CodegenPlugin): Promise<Types.PluginOutput>;
|
package/index.js
CHANGED
|
@@ -8,6 +8,7 @@ const utils = require('@graphql-tools/utils');
|
|
|
8
8
|
const schema = require('@graphql-tools/schema');
|
|
9
9
|
|
|
10
10
|
async function executePlugin(options, plugin) {
|
|
11
|
+
var _a;
|
|
11
12
|
if (!plugin || !plugin.plugin || typeof plugin.plugin !== 'function') {
|
|
12
13
|
throw new pluginHelpers.DetailedError(`Invalid Custom Plugin "${options.name}"`, `
|
|
13
14
|
Plugin ${options.name} does not export a valid JS object with "plugin" function.
|
|
@@ -24,10 +25,11 @@ async function executePlugin(options, plugin) {
|
|
|
24
25
|
const outputSchema = options.schemaAst || graphql.buildASTSchema(options.schema, options.config);
|
|
25
26
|
const documents = options.documents || [];
|
|
26
27
|
const pluginContext = options.pluginContext || {};
|
|
28
|
+
const profiler = (_a = options.profiler) !== null && _a !== void 0 ? _a : pluginHelpers.createNoopProfiler();
|
|
27
29
|
if (plugin.validate && typeof plugin.validate === 'function') {
|
|
28
30
|
try {
|
|
29
31
|
// FIXME: Sync validate signature with plugin signature
|
|
30
|
-
await plugin.validate(outputSchema, documents, options.config, options.outputFilename, options.allPlugins, pluginContext);
|
|
32
|
+
await profiler.run(async () => plugin.validate(outputSchema, documents, options.config, options.outputFilename, options.allPlugins, pluginContext), `Plugin ${options.name} validate`);
|
|
31
33
|
}
|
|
32
34
|
catch (e) {
|
|
33
35
|
throw new pluginHelpers.DetailedError(`Plugin "${options.name}" validation failed:`, `
|
|
@@ -35,11 +37,11 @@ async function executePlugin(options, plugin) {
|
|
|
35
37
|
`);
|
|
36
38
|
}
|
|
37
39
|
}
|
|
38
|
-
return Promise.resolve(plugin.plugin(outputSchema, documents, typeof options.config === 'object' ? { ...options.config } : options.config, {
|
|
40
|
+
return profiler.run(() => Promise.resolve(plugin.plugin(outputSchema, documents, typeof options.config === 'object' ? { ...options.config } : options.config, {
|
|
39
41
|
outputFile: options.outputFilename,
|
|
40
42
|
allPlugins: options.allPlugins,
|
|
41
43
|
pluginContext,
|
|
42
|
-
}));
|
|
44
|
+
})), `Plugin ${options.name} execution`);
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
function isObjectMap(obj) {
|
|
@@ -103,10 +105,12 @@ function hasFederationSpec(schemaOrAST) {
|
|
|
103
105
|
}
|
|
104
106
|
|
|
105
107
|
async function codegen(options) {
|
|
108
|
+
var _a;
|
|
106
109
|
const documents = options.documents || [];
|
|
110
|
+
const profiler = (_a = options.profiler) !== null && _a !== void 0 ? _a : pluginHelpers.createNoopProfiler();
|
|
107
111
|
const skipDocumentsValidation = getSkipDocumentsValidationOption(options);
|
|
108
112
|
if (documents.length > 0 && shouldValidateDuplicateDocuments(skipDocumentsValidation)) {
|
|
109
|
-
validateDuplicateDocuments(documents);
|
|
113
|
+
await profiler.run(async () => validateDuplicateDocuments(documents), 'validateDuplicateDocuments');
|
|
110
114
|
}
|
|
111
115
|
const pluginPackages = Object.keys(options.pluginMap).map(key => options.pluginMap[key]);
|
|
112
116
|
// merged schema with parts added by plugins
|
|
@@ -124,18 +128,20 @@ async function codegen(options) {
|
|
|
124
128
|
}
|
|
125
129
|
// Use mergeSchemas, only if there is no GraphQLSchema provided or the schema should be extended
|
|
126
130
|
const mergeNeeded = !options.schemaAst || additionalTypeDefs.length > 0;
|
|
127
|
-
const schemaInstance =
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
131
|
+
const schemaInstance = await profiler.run(async () => {
|
|
132
|
+
return mergeNeeded
|
|
133
|
+
? schema.mergeSchemas({
|
|
134
|
+
// If GraphQLSchema provided, use it
|
|
135
|
+
schemas: options.schemaAst ? [options.schemaAst] : [],
|
|
136
|
+
// If GraphQLSchema isn't provided but DocumentNode is, use it to get the final GraphQLSchema
|
|
137
|
+
typeDefs: options.schemaAst ? additionalTypeDefs : [options.schema, ...additionalTypeDefs],
|
|
138
|
+
convertExtensions: true,
|
|
139
|
+
assumeValid: true,
|
|
140
|
+
assumeValidSDL: true,
|
|
141
|
+
...options.config,
|
|
142
|
+
})
|
|
143
|
+
: options.schemaAst;
|
|
144
|
+
}, 'Create schema instance');
|
|
139
145
|
const schemaDocumentNode = mergeNeeded || !options.schema ? pluginHelpers.getCachedDocumentNodeFromSchema(schemaInstance) : options.schema;
|
|
140
146
|
if (schemaInstance && documents.length > 0 && shouldValidateDocumentsAgainstSchema(skipDocumentsValidation)) {
|
|
141
147
|
const ignored = ['NoUnusedFragments', 'NoUnusedVariables', 'KnownDirectives'];
|
|
@@ -143,13 +149,13 @@ async function codegen(options) {
|
|
|
143
149
|
ignored.push(...utils.asArray(skipDocumentsValidation.ignoreRules));
|
|
144
150
|
}
|
|
145
151
|
const extraFragments = pickFlag('externalFragments', options.config) || [];
|
|
146
|
-
const errors = await utils.validateGraphQlDocuments(schemaInstance, [
|
|
152
|
+
const errors = await profiler.run(() => utils.validateGraphQlDocuments(schemaInstance, [
|
|
147
153
|
...documents,
|
|
148
154
|
...extraFragments.map(f => ({
|
|
149
155
|
location: f.importFrom,
|
|
150
156
|
document: { kind: graphql.Kind.DOCUMENT, definitions: [f.node] },
|
|
151
157
|
})),
|
|
152
|
-
], graphql.specifiedRules.filter(rule => !ignored.some(ignoredRule => rule.name.startsWith(ignoredRule))));
|
|
158
|
+
], graphql.specifiedRules.filter(rule => !ignored.some(ignoredRule => rule.name.startsWith(ignoredRule)))), 'Validate documents against schema');
|
|
153
159
|
utils.checkValidationErrors(errors);
|
|
154
160
|
}
|
|
155
161
|
const prepend = new Set();
|
|
@@ -164,7 +170,7 @@ async function codegen(options) {
|
|
|
164
170
|
...options.config,
|
|
165
171
|
...pluginConfig,
|
|
166
172
|
};
|
|
167
|
-
const result = await executePlugin({
|
|
173
|
+
const result = await profiler.run(() => executePlugin({
|
|
168
174
|
name,
|
|
169
175
|
config: execConfig,
|
|
170
176
|
parentConfig: options.config,
|
|
@@ -175,7 +181,8 @@ async function codegen(options) {
|
|
|
175
181
|
allPlugins: options.plugins,
|
|
176
182
|
skipDocumentsValidation: options.skipDocumentsValidation,
|
|
177
183
|
pluginContext: options.pluginContext,
|
|
178
|
-
|
|
184
|
+
profiler,
|
|
185
|
+
}, pluginPackage), `Plugin ${name}`);
|
|
179
186
|
if (typeof result === 'string') {
|
|
180
187
|
return result || '';
|
|
181
188
|
}
|
package/index.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { DetailedError, getCachedDocumentNodeFromSchema, isComplexPluginOutput, federationSpec } from '@graphql-codegen/plugin-helpers';
|
|
1
|
+
import { DetailedError, createNoopProfiler, getCachedDocumentNodeFromSchema, isComplexPluginOutput, federationSpec } from '@graphql-codegen/plugin-helpers';
|
|
2
2
|
import { buildASTSchema, isSchema, Kind, specifiedRules, visit, print } from 'graphql';
|
|
3
3
|
import { isDocumentNode, asArray, validateGraphQlDocuments, checkValidationErrors } from '@graphql-tools/utils';
|
|
4
4
|
import { mergeSchemas } from '@graphql-tools/schema';
|
|
5
5
|
|
|
6
6
|
async function executePlugin(options, plugin) {
|
|
7
|
+
var _a;
|
|
7
8
|
if (!plugin || !plugin.plugin || typeof plugin.plugin !== 'function') {
|
|
8
9
|
throw new DetailedError(`Invalid Custom Plugin "${options.name}"`, `
|
|
9
10
|
Plugin ${options.name} does not export a valid JS object with "plugin" function.
|
|
@@ -20,10 +21,11 @@ async function executePlugin(options, plugin) {
|
|
|
20
21
|
const outputSchema = options.schemaAst || buildASTSchema(options.schema, options.config);
|
|
21
22
|
const documents = options.documents || [];
|
|
22
23
|
const pluginContext = options.pluginContext || {};
|
|
24
|
+
const profiler = (_a = options.profiler) !== null && _a !== void 0 ? _a : createNoopProfiler();
|
|
23
25
|
if (plugin.validate && typeof plugin.validate === 'function') {
|
|
24
26
|
try {
|
|
25
27
|
// FIXME: Sync validate signature with plugin signature
|
|
26
|
-
await plugin.validate(outputSchema, documents, options.config, options.outputFilename, options.allPlugins, pluginContext);
|
|
28
|
+
await profiler.run(async () => plugin.validate(outputSchema, documents, options.config, options.outputFilename, options.allPlugins, pluginContext), `Plugin ${options.name} validate`);
|
|
27
29
|
}
|
|
28
30
|
catch (e) {
|
|
29
31
|
throw new DetailedError(`Plugin "${options.name}" validation failed:`, `
|
|
@@ -31,11 +33,11 @@ async function executePlugin(options, plugin) {
|
|
|
31
33
|
`);
|
|
32
34
|
}
|
|
33
35
|
}
|
|
34
|
-
return Promise.resolve(plugin.plugin(outputSchema, documents, typeof options.config === 'object' ? { ...options.config } : options.config, {
|
|
36
|
+
return profiler.run(() => Promise.resolve(plugin.plugin(outputSchema, documents, typeof options.config === 'object' ? { ...options.config } : options.config, {
|
|
35
37
|
outputFile: options.outputFilename,
|
|
36
38
|
allPlugins: options.allPlugins,
|
|
37
39
|
pluginContext,
|
|
38
|
-
}));
|
|
40
|
+
})), `Plugin ${options.name} execution`);
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
function isObjectMap(obj) {
|
|
@@ -99,10 +101,12 @@ function hasFederationSpec(schemaOrAST) {
|
|
|
99
101
|
}
|
|
100
102
|
|
|
101
103
|
async function codegen(options) {
|
|
104
|
+
var _a;
|
|
102
105
|
const documents = options.documents || [];
|
|
106
|
+
const profiler = (_a = options.profiler) !== null && _a !== void 0 ? _a : createNoopProfiler();
|
|
103
107
|
const skipDocumentsValidation = getSkipDocumentsValidationOption(options);
|
|
104
108
|
if (documents.length > 0 && shouldValidateDuplicateDocuments(skipDocumentsValidation)) {
|
|
105
|
-
validateDuplicateDocuments(documents);
|
|
109
|
+
await profiler.run(async () => validateDuplicateDocuments(documents), 'validateDuplicateDocuments');
|
|
106
110
|
}
|
|
107
111
|
const pluginPackages = Object.keys(options.pluginMap).map(key => options.pluginMap[key]);
|
|
108
112
|
// merged schema with parts added by plugins
|
|
@@ -120,18 +124,20 @@ async function codegen(options) {
|
|
|
120
124
|
}
|
|
121
125
|
// Use mergeSchemas, only if there is no GraphQLSchema provided or the schema should be extended
|
|
122
126
|
const mergeNeeded = !options.schemaAst || additionalTypeDefs.length > 0;
|
|
123
|
-
const schemaInstance =
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
127
|
+
const schemaInstance = await profiler.run(async () => {
|
|
128
|
+
return mergeNeeded
|
|
129
|
+
? mergeSchemas({
|
|
130
|
+
// If GraphQLSchema provided, use it
|
|
131
|
+
schemas: options.schemaAst ? [options.schemaAst] : [],
|
|
132
|
+
// If GraphQLSchema isn't provided but DocumentNode is, use it to get the final GraphQLSchema
|
|
133
|
+
typeDefs: options.schemaAst ? additionalTypeDefs : [options.schema, ...additionalTypeDefs],
|
|
134
|
+
convertExtensions: true,
|
|
135
|
+
assumeValid: true,
|
|
136
|
+
assumeValidSDL: true,
|
|
137
|
+
...options.config,
|
|
138
|
+
})
|
|
139
|
+
: options.schemaAst;
|
|
140
|
+
}, 'Create schema instance');
|
|
135
141
|
const schemaDocumentNode = mergeNeeded || !options.schema ? getCachedDocumentNodeFromSchema(schemaInstance) : options.schema;
|
|
136
142
|
if (schemaInstance && documents.length > 0 && shouldValidateDocumentsAgainstSchema(skipDocumentsValidation)) {
|
|
137
143
|
const ignored = ['NoUnusedFragments', 'NoUnusedVariables', 'KnownDirectives'];
|
|
@@ -139,13 +145,13 @@ async function codegen(options) {
|
|
|
139
145
|
ignored.push(...asArray(skipDocumentsValidation.ignoreRules));
|
|
140
146
|
}
|
|
141
147
|
const extraFragments = pickFlag('externalFragments', options.config) || [];
|
|
142
|
-
const errors = await validateGraphQlDocuments(schemaInstance, [
|
|
148
|
+
const errors = await profiler.run(() => validateGraphQlDocuments(schemaInstance, [
|
|
143
149
|
...documents,
|
|
144
150
|
...extraFragments.map(f => ({
|
|
145
151
|
location: f.importFrom,
|
|
146
152
|
document: { kind: Kind.DOCUMENT, definitions: [f.node] },
|
|
147
153
|
})),
|
|
148
|
-
], specifiedRules.filter(rule => !ignored.some(ignoredRule => rule.name.startsWith(ignoredRule))));
|
|
154
|
+
], specifiedRules.filter(rule => !ignored.some(ignoredRule => rule.name.startsWith(ignoredRule)))), 'Validate documents against schema');
|
|
149
155
|
checkValidationErrors(errors);
|
|
150
156
|
}
|
|
151
157
|
const prepend = new Set();
|
|
@@ -160,7 +166,7 @@ async function codegen(options) {
|
|
|
160
166
|
...options.config,
|
|
161
167
|
...pluginConfig,
|
|
162
168
|
};
|
|
163
|
-
const result = await executePlugin({
|
|
169
|
+
const result = await profiler.run(() => executePlugin({
|
|
164
170
|
name,
|
|
165
171
|
config: execConfig,
|
|
166
172
|
parentConfig: options.config,
|
|
@@ -171,7 +177,8 @@ async function codegen(options) {
|
|
|
171
177
|
allPlugins: options.plugins,
|
|
172
178
|
skipDocumentsValidation: options.skipDocumentsValidation,
|
|
173
179
|
pluginContext: options.pluginContext,
|
|
174
|
-
|
|
180
|
+
profiler,
|
|
181
|
+
}, pluginPackage), `Plugin ${name}`);
|
|
175
182
|
if (typeof result === 'string') {
|
|
176
183
|
return result || '';
|
|
177
184
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0-alpha-c9cbc7d69.0",
|
|
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": "
|
|
8
|
+
"@graphql-codegen/plugin-helpers": "2.4.0-alpha-c9cbc7d69.0",
|
|
9
9
|
"@graphql-tools/schema": "^8.1.2",
|
|
10
10
|
"@graphql-tools/utils": "^8.1.1",
|
|
11
11
|
"tslib": "~2.3.0"
|