1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | 'use strict';
|
11 |
|
12 | var _toConsumableArray2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/toConsumableArray"));
|
13 |
|
14 | var parseGraphQL = require("./GraphQLCompilerProfiler").instrument(require("graphql").parse, 'GraphQL.parse');
|
15 |
|
16 | var FIND_OPTIONS = {
|
17 | validateNames: true
|
18 | };
|
19 |
|
20 | module.exports = function (tagFinder) {
|
21 | var memoizedTagFinder = require("./RelayFindGraphQLTags").memoizedFind.bind(null, tagFinder);
|
22 |
|
23 | function parseFile(baseDir, file) {
|
24 | var result = parseFileWithSources(baseDir, file);
|
25 |
|
26 | if (result) {
|
27 | return result.document;
|
28 | }
|
29 | }
|
30 |
|
31 |
|
32 | function parseFileWithSources(baseDir, file) {
|
33 | var text = require("fs").readFileSync(require("path").join(baseDir, file.relPath), 'utf8');
|
34 |
|
35 | !(text.indexOf('graphql') >= 0) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelaySourceModuleParser: Files should be filtered before passed to the ' + 'parser, got unfiltered file `%s`.', file.relPath) : require("fbjs/lib/invariant")(false) : void 0;
|
36 | var astDefinitions = [];
|
37 | var sources = [];
|
38 | memoizedTagFinder(text, baseDir, file, FIND_OPTIONS).forEach(function (template) {
|
39 | var source = new (require("graphql").Source)(template, file.relPath);
|
40 | var ast = parseGraphQL(source);
|
41 | !ast.definitions.length ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelaySourceModuleParser: Expected GraphQL text to contain at least one ' + 'definition (fragment, mutation, query, subscription), got `%s`.', template) : require("fbjs/lib/invariant")(false) : void 0;
|
42 | sources.push(source.body);
|
43 | astDefinitions.push.apply(astDefinitions, (0, _toConsumableArray2["default"])(ast.definitions));
|
44 | });
|
45 | return {
|
46 | document: {
|
47 | kind: 'Document',
|
48 | definitions: astDefinitions
|
49 | },
|
50 | sources: sources
|
51 | };
|
52 | }
|
53 |
|
54 | function getParser(baseDir) {
|
55 | return new (require("./ASTCache"))({
|
56 | baseDir: baseDir,
|
57 | parse: parseFile
|
58 | });
|
59 | }
|
60 |
|
61 | function getFileFilter(baseDir) {
|
62 | return function (file) {
|
63 | var text = require("fs").readFileSync(require("path").join(baseDir, file.relPath), 'utf8');
|
64 |
|
65 | return text.indexOf('graphql') >= 0;
|
66 | };
|
67 | }
|
68 |
|
69 | return {
|
70 | getParser: getParser,
|
71 | getFileFilter: getFileFilter,
|
72 | parseFile: parseFile,
|
73 | parseFileWithSources: parseFileWithSources
|
74 | };
|
75 | }; |
\ | No newline at end of file |