UNPKG

1.53 kBJavaScriptView Raw
1/**
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 *
8 * @format
9 */
10'use strict';
11
12var ASTCache =
13/*#__PURE__*/
14function () {
15 function ASTCache(config) {
16 this._documents = new Map();
17 this._baseDir = config.baseDir;
18 this._parse = require("./GraphQLCompilerProfiler").instrument(config.parse, 'ASTCache.parseFn');
19 } // Short-term: we don't do subscriptions/delta updates, instead always use all definitions
20
21
22 var _proto = ASTCache.prototype;
23
24 _proto.documents = function documents() {
25 return require("immutable").Map(this._documents);
26 }; // parse should return the set of changes
27
28
29 _proto.parseFiles = function parseFiles(files) {
30 var _this = this;
31
32 var documents = require("immutable").Map();
33
34 files.forEach(function (file) {
35 if (!file.exists) {
36 _this._documents["delete"](file.relPath);
37
38 return;
39 }
40
41 var doc = function () {
42 try {
43 return _this._parse(_this._baseDir, file);
44 } catch (error) {
45 throw new Error("Parse error: ".concat(error, " in \"").concat(file.relPath, "\""));
46 }
47 }();
48
49 if (!doc) {
50 _this._documents["delete"](file.relPath);
51
52 return;
53 }
54
55 documents = documents.set(file.relPath, doc);
56
57 _this._documents.set(file.relPath, doc);
58 });
59 return documents;
60 };
61
62 return ASTCache;
63}();
64
65module.exports = ASTCache;
\No newline at end of file