import{a as I,c as q,d as T}from"./chunk-GVZRBRU2.js";import{a as x,h as M}from"./chunk-GELY5MSG.js";import{La as E,Qa as O,a as g,h as u,p as m}from"./chunk-WNE7PXNE.js";var B=(e,t,s)=>{let r=["POST","PUT","PATCH"].indexOf(e.method.toUpperCase())!==-1,i=n=>["variables","extensions"].indexOf(n.toLowerCase())!==-1,f=e.body.length,d=e.options&&e.options.useMultipart,o;if(d){if(f)return new m(n=>n.error(new Error("File upload is not available when combined with Batching")));if(!r)return new m(n=>n.error(new Error("File upload is not available when GET is used")));if(!s)return new m(n=>n.error(new Error(`To use File upload you need to pass "extractFiles" function from "extract-files" library to HttpLink's options`)));o=s(e.body),d=!!o.files.size}let c={};if(f){if(!r)return new m(n=>n.error(new Error("Batching is not available for GET requests")));c={body:e.body}}else{let n=d?o.clone:e.body;r?c={body:n}:c={params:Object.keys(e.body).reduce((h,l)=>{let p=e.body[l];return h[l]=i(l)?JSON.stringify(p):p,h},{})}}if(d&&r){let n=new FormData;n.append("operations",JSON.stringify(c.body));let b={},h=o.files,l=0;h.forEach(p=>{b[++l]=p}),n.append("map",JSON.stringify(b)),l=0,h.forEach((p,w)=>{n.append(++l+"",w,w.name)}),c.body=n}return t.request(e.method,e.url,g(g({observe:"response",responseType:"json",reportProgress:!1},c),e.options))},S=(e,t)=>e&&t?t.keys().reduce((r,i)=>r.set(i,t.getAll(i)),e):t||e;function A(...e){let t=e.find(s=>typeof s<"u");return typeof t>"u"?e[e.length-1]:t}function N(e){let t=e.headers&&e.headers instanceof x?e.headers:new x(e.headers);if(e.clientAwareness){let{name:s,version:r}=e.clientAwareness;s&&!t.has("apollographql-client-name")&&(t=t.set("apollographql-client-name",s)),r&&!t.has("apollographql-client-version")&&(t=t.set("apollographql-client-version",r))}return t}var C=class extends T{constructor(s,r){super();u(this,"httpClient");u(this,"options");u(this,"requester");u(this,"print",I);this.httpClient=s,this.options=r,this.options.operationPrinter&&(this.print=this.options.operationPrinter),this.requester=i=>new q(f=>{let d=i.getContext(),o=(a,Q)=>A(d[a],this.options[a],Q),c=o("method","POST"),n=o("includeQuery",!0),b=o("includeExtensions",!1),h=o("uri","graphql"),l=o("withCredentials"),p=o("useMultipart"),w=this.options.useGETForQueries===!0,P=i.query.definitions.some(a=>a.kind==="OperationDefinition"&&a.operation==="query");w&&P&&(c="GET");let y={method:c,url:typeof h=="function"?h(i):h,body:{operationName:i.operationName,variables:i.variables},options:{withCredentials:l,useMultipart:p,headers:this.options.headers}};b&&(y.body.extensions=i.extensions),n&&(y.body.query=this.print(i.query));let F=N(d);y.options.headers=S(y.options.headers,F);let v=B(y,this.httpClient,this.options.extractFiles).subscribe({next:a=>{i.setContext({response:a}),f.next(a.body)},error:a=>f.error(a),complete:()=>f.complete()});return()=>{v.closed||v.unsubscribe()}})}request(s){return this.requester(s)}},K=(()=>{let t=class t{constructor(r){u(this,"httpClient");this.httpClient=r}create(r){return new C(this.httpClient,r)}};u(t,"\u0275fac",function(i){return new(i||t)(O(M))}),u(t,"\u0275prov",E({token:t,factory:t.\u0275fac,providedIn:"root"}));let e=t;return e})();export{K as a};