UNPKG

1.71 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.VueApolloVisitor = exports.validate = exports.plugin = void 0;
4const path_1 = require("path");
5const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
6const graphql_1 = require("graphql");
7const visitor_js_1 = require("./visitor.js");
8Object.defineProperty(exports, "VueApolloVisitor", { enumerable: true, get: function () { return visitor_js_1.VueApolloVisitor; } });
9const plugin = (schema, documents, config) => {
10 const allAst = (0, graphql_1.concatAST)(documents.map(s => s.document));
11 const allFragments = [
12 ...allAst.definitions.filter(d => d.kind === graphql_1.Kind.FRAGMENT_DEFINITION).map(fragmentDef => ({
13 node: fragmentDef,
14 name: fragmentDef.name.value,
15 onType: fragmentDef.typeCondition.name.value,
16 isExternal: false,
17 })),
18 ...(config.externalFragments || []),
19 ];
20 const visitor = new visitor_js_1.VueApolloVisitor(schema, allFragments, config, documents);
21 const visitorResult = (0, plugin_helpers_1.oldVisit)(allAst, { leave: visitor });
22 return {
23 prepend: visitor.getImports(),
24 content: [
25 visitor.fragments,
26 ...visitorResult.definitions.filter((definition) => typeof definition === 'string'),
27 ].join('\n'),
28 };
29};
30exports.plugin = plugin;
31const validate = (_schema, _documents, _config, outputFile) => {
32 if ((0, path_1.extname)(outputFile) !== '.ts' && (0, path_1.extname)(outputFile) !== '.tsx') {
33 throw new Error(`Plugin "typescript-vue-apollo-smart-ops" requires extension to be ".ts" or ".tsx"!`);
34 }
35};
36exports.validate = validate;