1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var strip_comments_1 = require("./strip-comments");
|
4 | var graphql_codegen_core_1 = require("graphql-codegen-core");
|
5 | exports.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 |
|
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 |
|
\ | No newline at end of file |