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