apollo-link-reactive-schema
Advanced tools
Comparing version 2.0.3 to 2.1.0
@@ -17,3 +17,23 @@ "use strict"; | ||
var apollo_link_1 = require("apollo-link"); | ||
var graphql_1 = require("graphql"); | ||
var reactive_graphql_1 = require("reactive-graphql"); | ||
var rxjs_1 = require("rxjs"); | ||
var operators_1 = require("rxjs/operators"); | ||
// will transform the errors of the execution results provided by | ||
// reactive-graphql in proper GraphQLErrors | ||
function normalizeErrorsField(results) { | ||
var _results = {}; | ||
_results.data = results.data; | ||
if (results.errors) { | ||
_results.errors = results.errors.map(function (message) { | ||
// @ts-ignore just to be sure, message could be an instance of error | ||
if (typeof message.message === 'string') { | ||
// @ts-ignore | ||
return new graphql_1.GraphQLError(message.message); | ||
} | ||
return new graphql_1.GraphQLError(message); | ||
}); | ||
} | ||
return _results; | ||
} | ||
var ReactiveSchemaLink = /** @class */ (function (_super) { | ||
@@ -33,6 +53,9 @@ __extends(ReactiveSchemaLink, _super); | ||
var context = typeof _this.context === 'function' ? _this.context(operation) : _this.context || {}; | ||
return reactive_graphql_1.graphql(_this.schema, operation.query, null, context, operation.variables).subscribe(observer); | ||
return reactive_graphql_1.graphql(_this.schema, operation.query, null, context, operation.variables) | ||
.pipe(operators_1.catchError(function (error) { return rxjs_1.of({ errors: [new graphql_1.GraphQLError(error.message)] }); })) | ||
.pipe(operators_1.map(normalizeErrorsField)) | ||
.subscribe(observer); | ||
} | ||
catch (e) { | ||
observer.error(e); | ||
observer.next({ errors: [new graphql_1.GraphQLError(e.mesage)] }); | ||
} | ||
@@ -39,0 +62,0 @@ }); |
{ | ||
"name": "apollo-link-reactive-schema", | ||
"version": "2.0.3", | ||
"version": "2.1.0", | ||
"description": "Apollo Link that provides a reactive-graphql execution environment to perform operations on a provided reactive schema.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
9653
130