UNPKG

1.31 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var strip_comments_1 = require("./strip-comments");
4var graphql_codegen_core_1 = require("graphql-codegen-core");
5exports.extractDocumentStringFromCodeFile = function (fileContent) {
6 try {
7 var parsed = graphql_codegen_core_1.parse(fileContent);
8 if (parsed) {
9 return fileContent;
10 }
11 }
12 catch (e) {
13 try {
14 fileContent = strip_comments_1.default(fileContent, { sourceType: 'module' });
15 }
16 catch (e) {
17 try {
18 fileContent = strip_comments_1.default(fileContent);
19 }
20 catch (e) {
21 // nothing to to here
22 }
23 }
24 var matches = fileContent.match(/(gql|graphql)[(]?`([\s\S\n\r.]*?)`/gm);
25 if (matches === null) {
26 matches = fileContent.match(/(['"](query|subscription|fragment|mutation) .*?['"])/gm);
27 }
28 var result = (matches || [])
29 .map(function (item) { return item.replace(/\$\{.*?\}/g, '').replace(/(gql|graphql|[(]?`)/g, ''); })
30 .join();
31 if (!result || result === '') {
32 return null;
33 }
34 else {
35 return result;
36 }
37 }
38};
39//# sourceMappingURL=document-finder.js.map
\No newline at end of file