UNPKG

apollo-angular

Version:

Use your GraphQL data in your Angular app, with the Apollo Client

2 lines 7.48 kB
!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,s){"use strict";function u(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var c=u(t),l=u(n),p=function(e,t){return(p=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)};function f(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}p(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}Object.create;Object.create;var d=function(e,t,n){var r,o=-1!==["POST","PUT","PATCH"].indexOf(e.method.toUpperCase()),i=e.body.length,s=e.options&&e.options.useMultipart;if(s){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"))}));s=!!(r=n(e.body)).files.size}var u={};if(i){if(!o)return new a.Observable((function(e){return e.error(new Error("Batching is not available for GET requests"))}));u={body:e.body}}else{var c=s?r.clone:e.body;if(o)u={body:c};else u={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(s&&o){var l=new FormData;l.append("operations",JSON.stringify(u.body));var p={},f=r.files,d=0;f.forEach((function(e){p[++d]=e})),l.append("map",JSON.stringify(p)),d=0,f.forEach((function(e,t){l.append(++d+"",t,t.name)})),u.body=l}return t.request(e.method,e.url,Object.assign(Object.assign({observe:"response",responseType:"json",reportProgress:!1},u),e.options))},h=function(e,t){return e&&t?t.keys().reduce((function(e,n){return e.set(n,t.getAll(n))}),e):t||e};function b(){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}function y(e){var t=e.headers&&e.headers instanceof n.HttpHeaders?e.headers:new n.HttpHeaders(e.headers);if(e.clientAwareness){var r=e.clientAwareness,o=r.name,i=r.version;o&&!t.has("apollographql-client-name")&&(t=t.set("apollographql-client-name",o)),i&&!t.has("apollographql-client-version")&&(t=t.set("apollographql-client-version",i))}return t}var v=function(e){function t(t,n){var a=e.call(this)||this;return a.httpClient=t,a.options=n,a.print=o.print,a.options.operationPrinter&&(a.print=a.options.operationPrinter),a.requester=function(e){return new r.Observable((function(t){var n=e.getContext(),r=function(e,t){return b(n[e],a.options[e],t)},o=r("includeQuery",!0),s=r("includeExtensions",!1),u=r("method","POST"),c=r("uri","graphql"),l=r("withCredentials"),p=r("useMultipart"),f={method:u,url:"function"==typeof c?c(e):c,body:{operationName:e.operationName,variables:e.variables},options:{withCredentials:l,useMultipart:p,headers:a.options.headers}};s&&(f.body.extensions=e.extensions),o&&(f.body.query=a.print(e.query));var v=y(n);f.options.headers=h(f.options.headers,v);var g=d(f,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(){g.closed||g.unsubscribe()}}))},a}return f(t,e),t.prototype.request=function(e){return this.requester(e)},t}(r.ApolloLink),g=function(){function e(e){this.httpClient=e}return e.prototype.create=function(e){return new v(this.httpClient,e)},e}();g.ɵprov=c.ɵɵdefineInjectable({factory:function(){return new g(c.ɵɵinject(l.HttpClient))},token:g,providedIn:"root"}),g.decorators=[{type:t.Injectable,args:[{providedIn:"root"}]}],g.ctorParameters=function(){return[{type:n.HttpClient}]};var w=10,m=10,x="graphql",O="POST",C=function(e){function t(t,n){var i=e.call(this)||this;i.httpClient=t,i.options=n,i.print=o.print,i.batchInterval=n.batchInterval||w,i.batchMax=n.batchMax||m,i.options.operationPrinter&&(i.print=i.options.operationPrinter);var a=n.batchKey||function(e){return i.createBatchKey(e)};return i.batcher=new s.BatchLink({batchInterval:i.batchInterval,batchMax:i.batchMax,batchKey:a,batchHandler:function(e){return new r.Observable((function(t){var n=i.createBody(e),r=i.createHeaders(e),o=i.createOptions(e),a=o.method,s=o.uri,u=o.withCredentials;if("function"==typeof s)throw new Error("Option 'uri' is a function, should be a string");var c=d({method:a,url:s,body:n,options:{withCredentials:u,headers:r}},i.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()}}))}}),i}return f(t,e),t.prototype.createOptions=function(e){var t=e[0].getContext();return{method:b(t.method,this.options.method,O),uri:b(t.uri,this.options.uri,x),withCredentials:b(t.withCredentials,this.options.withCredentials)}},t.prototype.createBody=function(e){var t=this;return e.map((function(e){var n=b(e.getContext().includeExtensions,t.options.includeExtensions,!1),r=b(e.getContext().includeQuery,t.options.includeQuery,!0),o={operationName:e.operationName,variables:e.variables};return n&&(o.extensions=e.extensions),r&&(o.query=t.print(e.query)),o}))},t.prototype.createHeaders=function(e){var t,n;return e.reduce((function(e,t){return h(e,t.getContext().headers)}),y({headers:this.options.headers,clientAwareness:null===(n=null===(t=e[0])||void 0===t?void 0:t.getContext())||void 0===n?void 0:n.clientAwareness}))},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 b(t.uri,this.options.uri)+r},t.prototype.request=function(e){return this.batcher.request(e)},t}(r.ApolloLink),q=function(){function e(e){this.httpClient=e}return e.prototype.create=function(e){return new C(this.httpClient,e)},e}();q.ɵprov=c.ɵɵdefineInjectable({factory:function(){return new q(c.ɵɵinject(l.HttpClient))},token:q,providedIn:"root"}),q.decorators=[{type:t.Injectable,args:[{providedIn:"root"}]}],q.ctorParameters=function(){return[{type:n.HttpClient}]},e.HttpBatchLink=q,e.HttpBatchLinkHandler=C,e.HttpLink=g,e.HttpLinkHandler=v,Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=ngApolloLinkHttp.umd.min.js.map