UNPKG

7.26 kBJavaScriptView Raw
1!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/common/http"),require("@apollo/client/core"),require("graphql"),require("extract-files"),require("rxjs"),require("@apollo/client/link/batch")):"function"==typeof define&&define.amd?define("apollo-angular/http",["exports","@angular/core","@angular/common/http","@apollo/client/core","graphql","extract-files","rxjs","@apollo/client/link/batch"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).ngApollo=e.ngApollo||{},e.ngApollo.http={}),e.ng.core,e.ng.common.http,e.core,e.graphql,e.extractFiles,e.rxjs,e.batch)}(this,(function(e,t,n,r,o,i,a,u){"use strict";
2/*! *****************************************************************************
3 Copyright (c) Microsoft Corporation.
4
5 Permission to use, copy, modify, and/or distribute this software for any
6 purpose with or without fee is hereby granted.
7
8 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9 REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10 AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11 INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12 LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13 OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14 PERFORMANCE OF THIS SOFTWARE.
15 ***************************************************************************** */var s=function(e,t){return(s=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function c(e,t){function n(){this.constructor=e}s(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}Object.create;Object.create;var l=function(e,t,n){var r,o=-1!==["POST","PUT","PATCH"].indexOf(e.method.toUpperCase()),i=e.body.length,u=e.options&&e.options.useMultipart;if(u){if(i)return new a.Observable((function(e){return e.error(new Error("File upload is not available when combined with Batching"))}));if(!o)return new a.Observable((function(e){return e.error(new Error("File upload is not available when GET is used"))}));u=!!(r=n(e.body)).files.size}var s={};if(i){if(!o)return new a.Observable((function(e){return e.error(new Error("Batching is not available for GET requests"))}));s={body:e.body}}else{var c=u?r.clone:e.body;if(o)s={body:c};else s={params:Object.keys(e.body).reduce((function(t,n){var r=e.body[n];return t[n]=function(e){return-1!==["variables","extensions"].indexOf(e.toLowerCase())}(n)?JSON.stringify(r):r,t}),{})}}if(u&&o){var l=new FormData;l.append("operations",JSON.stringify(s.body));var p={},h=r.files,d=0;h.forEach((function(e){p[++d]=e})),l.append("map",JSON.stringify(p)),d=0,h.forEach((function(e,t){l.append(++d+"",t,t.name)})),s.body=l}return t.request(e.method,e.url,Object.assign(Object.assign({observe:"response",responseType:"json",reportProgress:!1},s),e.options))},p=function(e,t){return e&&t?t.keys().reduce((function(e,n){return e.set(n,t.getAll(n))}),e):t||e};function h(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=e.find((function(e){return void 0!==e}));return void 0===n?e[e.length-1]:n}var d=function(e){function t(t,n){var a=e.call(this)||this;return a.httpClient=t,a.options=n,a.requester=function(e){return new r.Observable((function(t){var n=e.getContext(),r=function(e,t){return h(n[e],a.options[e],t)},u=r("includeQuery",!0),s=r("includeExtensions",!1),c=r("method","POST"),d=r("uri","graphql"),f=r("withCredentials"),b=r("useMultipart"),y={method:c,url:"function"==typeof d?d(e):d,body:{operationName:e.operationName,variables:e.variables},options:{withCredentials:f,useMultipart:b,headers:a.options.headers}};s&&(y.body.extensions=e.extensions),u&&(y.body.query=o.print(e.query)),n.headers&&(y.options.headers=p(y.options.headers,n.headers));var v=l(y,a.httpClient,i.extractFiles).subscribe({next:function(n){e.setContext({response:n}),t.next(n.body)},error:function(e){return t.error(e)},complete:function(){return t.complete()}});return function(){v.closed||v.unsubscribe()}}))},a}return c(t,e),t.prototype.request=function(e){return this.requester(e)},t}(r.ApolloLink),f=function(){function e(e){this.httpClient=e}return e.prototype.create=function(e){return new d(this.httpClient,e)},e}();f.ɵprov=t.ɵɵdefineInjectable({factory:function(){return new f(t.ɵɵinject(n.HttpClient))},token:f,providedIn:"root"}),f.decorators=[{type:t.Injectable,args:[{providedIn:"root"}]}],f.ctorParameters=function(){return[{type:n.HttpClient}]};var b=10,y=10,v="graphql",g="POST",x=function(e){function t(t,n){var o=e.call(this)||this;o.httpClient=t,o.options=n,o.batchInterval=n.batchInterval||b,o.batchMax=n.batchMax||y;var i=n.batchKey||function(e){return o.createBatchKey(e)};return o.batcher=new u.BatchLink({batchInterval:o.batchInterval,batchMax:o.batchMax,batchKey:i,batchHandler:function(e){return new r.Observable((function(t){var n=o.createBody(e),r=o.createHeaders(e),i=o.createOptions(e),a=i.method,u=i.uri,s=i.withCredentials;if("function"==typeof u)throw new Error("Option 'uri' is a function, should be a string");var c=l({method:a,url:u,body:n,options:{withCredentials:s,headers:r}},o.httpClient,(function(){throw new Error("File upload is not available when combined with Batching")})).subscribe({next:function(e){return t.next(e.body)},error:function(e){return t.error(e)},complete:function(){return t.complete()}});return function(){c.closed||c.unsubscribe()}}))}}),o}return c(t,e),t.prototype.createOptions=function(e){var t=e[0].getContext();return{method:h(t.method,this.options.method,g),uri:h(t.uri,this.options.uri,v),withCredentials:h(t.withCredentials,this.options.withCredentials)}},t.prototype.createBody=function(e){var t=this;return e.map((function(e){var n=h(e.getContext().includeExtensions,t.options.includeExtensions,!1),r=h(e.getContext().includeQuery,t.options.includeQuery,!0),i={operationName:e.operationName,variables:e.variables};return n&&(i.extensions=e.extensions),r&&(i.query=o.print(e.query)),i}))},t.prototype.createHeaders=function(e){return e.reduce((function(e,t){return p(e,t.getContext().headers)}),this.options.headers)},t.prototype.createBatchKey=function(e){var t=e.getContext();if(t.skipBatching)return Math.random().toString(36).substr(2,9);var n=t.headers&&t.headers.keys().map((function(e){return t.headers.get(e)})),r=JSON.stringify({includeQuery:t.includeQuery,includeExtensions:t.includeExtensions,headers:n});return h(t.uri,this.options.uri)+r},t.prototype.request=function(e){return this.batcher.request(e)},t}(r.ApolloLink),m=function(){function e(e){this.httpClient=e}return e.prototype.create=function(e){return new x(this.httpClient,e)},e}();m.ɵprov=t.ɵɵdefineInjectable({factory:function(){return new m(t.ɵɵinject(n.HttpClient))},token:m,providedIn:"root"}),m.decorators=[{type:t.Injectable,args:[{providedIn:"root"}]}],m.ctorParameters=function(){return[{type:n.HttpClient}]},e.HttpBatchLink=m,e.HttpBatchLinkHandler=x,e.HttpLink=f,e.HttpLinkHandler=d,Object.defineProperty(e,"__esModule",{value:!0})}));
16//# sourceMappingURL=ngApolloLinkHttp.umd.min.js.map
\No newline at end of file