1 | {"version":3,"file":"ngApolloLinkHttp.js","sources":["../../src/http-link.ts","../../src/http-link-module.ts","../../src/ngApolloLinkHttp.ts"],"sourcesContent":["import {Injectable} from '@angular/core';\nimport {HttpClient} from '@angular/common/http';\nimport {\n ApolloLink,\n Observable as LinkObservable,\n Operation,\n FetchResult,\n} from 'apollo-link';\nimport {print} from 'graphql';\nimport {\n fetch,\n Options,\n Body,\n Request,\n Context,\n mergeHeaders,\n prioritize,\n} from 'apollo-angular-link-http-common';\nimport {extractFiles} from 'extract-files';\n\n// XXX find a better name for it\nexport class HttpLinkHandler extends ApolloLink {\n public requester: (\n operation: Operation,\n ) => LinkObservable<FetchResult> | null;\n\n constructor(private httpClient: HttpClient, private options: Options) {\n super();\n\n this.requester = (operation: Operation) =>\n new LinkObservable((observer: any) => {\n const context: Context = operation.getContext();\n\n // decides which value to pick, Context, Options or to just use the default\n const pick = <K extends keyof Context | keyof Options>(\n key: K,\n init?: Context[K] | Options[K],\n ): Context[K] | Options[K] => {\n return prioritize(context[key], this.options[key], init);\n };\n\n const includeQuery = pick('includeQuery', true);\n const includeExtensions = pick('includeExtensions', false);\n const method = pick('method', 'POST');\n const url = pick('uri', 'graphql');\n const withCredentials = pick('withCredentials');\n const useMultipart = pick('useMultipart');\n\n const req: Request = {\n method,\n url: typeof url === 'function' ? url(operation) : url,\n body: {\n operationName: operation.operationName,\n variables: operation.variables,\n },\n options: {\n withCredentials,\n useMultipart,\n headers: this.options.headers,\n },\n };\n\n if (includeExtensions) {\n (req.body as Body).extensions = operation.extensions;\n }\n\n if (includeQuery) {\n (req.body as Body).query = print(operation.query);\n }\n\n if (context.headers) {\n req.options.headers = mergeHeaders(\n req.options.headers,\n context.headers,\n );\n }\n\n const sub = fetch(req, this.httpClient, extractFiles).subscribe({\n next: (response) => {\n operation.setContext({response});\n observer.next(response.body);\n },\n error: (err) => observer.error(err),\n complete: () => observer.complete(),\n });\n\n return () => {\n if (!sub.closed) {\n sub.unsubscribe();\n }\n };\n });\n }\n\n public request(op: Operation): LinkObservable<FetchResult> | null {\n return this.requester(op);\n }\n}\n\n@Injectable()\nexport class HttpLink {\n constructor(private httpClient: HttpClient) {}\n\n public create(options: Options): HttpLinkHandler {\n return new HttpLinkHandler(this.httpClient, options);\n }\n}\n","import {NgModule} from '@angular/core';\n\nimport {HttpLink} from './http-link';\n\nexport const PROVIDERS = [HttpLink];\n\n@NgModule({\n providers: PROVIDERS,\n})\nexport class HttpLinkModule {}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":["LinkObservable"],"mappings":";;;;;;;AAoBA;MACa,eAAgB,SAAQ,UAAU;IAK7C,YAAoB,UAAsB,EAAU,OAAgB;QAClE,KAAK,EAAE,CAAC;QADU,eAAU,GAAV,UAAU,CAAY;QAAU,YAAO,GAAP,OAAO,CAAS;QAGlE,IAAI,CAAC,SAAS,GAAG,CAAC,SAAoB,KACpC,IAAIA,UAAc,CAAC,CAAC,QAAa;YAC/B,MAAM,OAAO,GAAY,SAAS,CAAC,UAAU,EAAE,CAAC;;YAGhD,MAAM,IAAI,GAAG,CACX,GAAM,EACN,IAA8B;gBAE9B,OAAO,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC;aAC1D,CAAC;YAEF,MAAM,YAAY,GAAG,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;YAChD,MAAM,iBAAiB,GAAG,IAAI,CAAC,mBAAmB,EAAE,KAAK,CAAC,CAAC;YAC3D,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;YACtC,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;YACnC,MAAM,eAAe,GAAG,IAAI,CAAC,iBAAiB,CAAC,CAAC;YAChD,MAAM,YAAY,GAAG,IAAI,CAAC,cAAc,CAAC,CAAC;YAE1C,MAAM,GAAG,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