1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.validate = exports.plugin = void 0;
|
4 | const graphql_1 = require("graphql");
|
5 | const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
|
6 | const path_1 = require("path");
|
7 | const visitor_plugin_common_1 = require("@graphql-codegen/visitor-plugin-common");
|
8 | const plugin = async (schema, _documents, pluginConfig) => {
|
9 | const cleanSchema = pluginConfig.federation ? (0, plugin_helpers_1.removeFederation)(schema) : schema;
|
10 | const descriptions = (0, visitor_plugin_common_1.getConfigValue)(pluginConfig.descriptions, true);
|
11 | const directiveIsRepeatable = (0, visitor_plugin_common_1.getConfigValue)(pluginConfig.directiveIsRepeatable, true);
|
12 | const schemaDescription = (0, visitor_plugin_common_1.getConfigValue)(pluginConfig.schemaDescription, undefined);
|
13 | const specifiedByUrl = (0, visitor_plugin_common_1.getConfigValue)(pluginConfig.specifiedByUrl, undefined);
|
14 | const introspection = (0, graphql_1.introspectionFromSchema)(cleanSchema, {
|
15 | descriptions,
|
16 | directiveIsRepeatable,
|
17 | schemaDescription,
|
18 | specifiedByUrl,
|
19 | });
|
20 | return pluginConfig.minify ? JSON.stringify(introspection) : JSON.stringify(introspection, null, 2);
|
21 | };
|
22 | exports.plugin = plugin;
|
23 | const validate = async (schema, documents, config, outputFile) => {
|
24 | if ((0, path_1.extname)(outputFile) !== '.json') {
|
25 | throw new Error(`Plugin "introspection" requires extension to be ".json"!`);
|
26 | }
|
27 | };
|
28 | exports.validate = validate;
|