Odoo GraphQL Subscription using Node, Express JS for Sample
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
2.0 KiB

4 months ago
import { __extends } from "tslib";
import { validate, execute } from "graphql";
import { ApolloLink } from "../core/index.js";
import { Observable } from "../../utilities/index.js";
var SchemaLink = /** @class */ (function (_super) {
__extends(SchemaLink, _super);
function SchemaLink(options) {
var _this = _super.call(this) || this;
_this.schema = options.schema;
_this.rootValue = options.rootValue;
_this.context = options.context;
_this.validate = !!options.validate;
return _this;
}
SchemaLink.prototype.request = function (operation) {
var _this = this;
return new Observable(function (observer) {
new Promise(function (resolve) {
return resolve(typeof _this.context === "function" ?
_this.context(operation)
: _this.context);
})
.then(function (context) {
if (_this.validate) {
var validationErrors = validate(_this.schema, operation.query);
if (validationErrors.length > 0) {
return { errors: validationErrors };
}
}
return execute({
schema: _this.schema,
document: operation.query,
rootValue: _this.rootValue,
contextValue: context,
variableValues: operation.variables,
operationName: operation.operationName,
});
})
.then(function (data) {
if (!observer.closed) {
observer.next(data);
observer.complete();
}
})
.catch(function (error) {
if (!observer.closed) {
observer.error(error);
}
});
});
};
return SchemaLink;
}(ApolloLink));
export { SchemaLink };
//# sourceMappingURL=index.js.map