1 | "use strict";
|
2 | var __extends = (this && this.__extends) || (function () {
|
3 | var extendStatics = Object.setPrototypeOf ||
|
4 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
5 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
6 | return function (d, b) {
|
7 | extendStatics(d, b);
|
8 | function __() { this.constructor = d; }
|
9 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
10 | };
|
11 | })();
|
12 | var __assign = (this && this.__assign) || Object.assign || function(t) {
|
13 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
14 | s = arguments[i];
|
15 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
16 | t[p] = s[p];
|
17 | }
|
18 | return t;
|
19 | };
|
20 | var __rest = (this && this.__rest) || function (s, e) {
|
21 | var t = {};
|
22 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
23 | t[p] = s[p];
|
24 | if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
25 | for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
|
26 | t[p[i]] = s[p[i]];
|
27 | return t;
|
28 | };
|
29 | Object.defineProperty(exports, "__esModule", { value: true });
|
30 | var apollo_link_1 = require("apollo-link");
|
31 | var graphql_1 = require("graphql");
|
32 | var index_1 = require("./index");
|
33 | var HTTPLinkDataloader = (function (_super) {
|
34 | __extends(HTTPLinkDataloader, _super);
|
35 | function HTTPLinkDataloader(options) {
|
36 | return _super.call(this, HTTPLinkDataloader.createBatchedHttpRequest(options)) || this;
|
37 | }
|
38 | HTTPLinkDataloader.createBatchedHttpRequest = function (options) {
|
39 | var uri = options.uri, rest = __rest(options, ["uri"]);
|
40 | var client = new index_1.BatchedGraphQLClient(uri, rest);
|
41 | return function (operation) {
|
42 | return new apollo_link_1.Observable(function (observer) {
|
43 | var _a = operation.getContext(), headers = _a.headers, contextURI = _a.uri;
|
44 | var operationName = operation.operationName, variables = operation.variables, query = operation.query;
|
45 | if (contextURI) {
|
46 | client.uri = contextURI;
|
47 | }
|
48 | if (headers) {
|
49 | client.options = __assign({}, client.options, { headers: __assign({}, client.options.headers, headers) });
|
50 | }
|
51 | client
|
52 | .request(graphql_1.print(query), variables, operationName)
|
53 | .then(function (response) {
|
54 | operation.setContext({ response: response });
|
55 | observer.next({ data: response });
|
56 | observer.complete();
|
57 | return response;
|
58 | })
|
59 | .catch(function (err) {
|
60 | if (err.name === 'AbortError') {
|
61 | return;
|
62 | }
|
63 | observer.error(err);
|
64 | });
|
65 | });
|
66 | };
|
67 | };
|
68 | return HTTPLinkDataloader;
|
69 | }(apollo_link_1.ApolloLink));
|
70 | exports.HTTPLinkDataloader = HTTPLinkDataloader;
|
71 |
|
\ | No newline at end of file |