@adpt/core
Version:
AdaptJS core library
53 lines • 2 kB
JavaScript
;
/*
* Copyright 2018-2019 Unbounded Systems, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("@adpt/utils");
const graphql_1 = require("graphql");
const jsx_1 = require("../jsx");
class Observer extends jsx_1.Component {
constructor(props) {
super(props);
const ccd = jsx_1.getComponentConstructorData();
this.mgr = ccd.observerManager;
}
async build() {
let result;
try {
result = await this.mgr.executeQuery(this.props.observer, this.props.query, this.props.variables);
}
catch (err) {
return this.props.build(err, undefined);
}
let err = null;
let needsData = false;
if (result.errors) {
const badErrors = result.errors.filter((e) => !e.message.startsWith("Adapt Observer Needs Data:"));
if (badErrors.length !== 0) {
const msgs = badErrors.map((e) => e.originalError ? e.stack : graphql_1.printError(e)).join("\n");
err = new Error(msgs);
err.originalErrors = badErrors;
}
else {
needsData = true;
}
}
return this.props.build(err, needsData ? undefined : result.data);
}
}
Observer.defaultProps = { isEqual: utils_1.isEqualUnorderedArrays };
exports.Observer = Observer;
//# sourceMappingURL=Observer.js.map