MessagesForMacintosh/JS/node_modules/apollo-link-http/lib/bundle.esm.js.map

1 line
13 KiB
Plaintext
Raw Normal View History

{"version":3,"file":"bundle.esm.js","sources":["../src/httpLink.ts"],"sourcesContent":["/* tslint:disable */\n\nimport { ApolloLink, Observable, RequestHandler, fromError } from 'apollo-link';\nimport {\n serializeFetchParameter,\n selectURI,\n parseAndCheckHttpResponse,\n checkFetcher,\n selectHttpOptionsAndBody,\n createSignalIfSupported,\n fallbackHttpConfig,\n Body,\n HttpOptions,\n UriFunction as _UriFunction,\n} from 'apollo-link-http-common';\nimport { DefinitionNode } from 'graphql';\n\nexport namespace HttpLink {\n //TODO Would much rather be able to export directly\n export interface UriFunction extends _UriFunction {}\n export interface Options extends HttpOptions {\n /**\n * If set to true, use the HTTP GET method for query operations. Mutations\n * will still use the method specified in fetchOptions.method (which defaults\n * to POST).\n */\n useGETForQueries?: boolean;\n }\n}\n\n// For backwards compatibility.\nexport import FetchOptions = HttpLink.Options;\nexport import UriFunction = HttpLink.UriFunction;\n\nexport const createHttpLink = (linkOptions: HttpLink.Options = {}) => {\n let {\n uri = '/graphql',\n // use default global fetch if nothing passed in\n fetch: fetcher,\n includeExtensions,\n useGETForQueries,\n ...requestOptions\n } = linkOptions;\n\n // dev warnings to ensure fetch is present\n checkFetcher(fetcher);\n\n //fetcher is set here rather than the destructuring to ensure fetch is\n //declared before referencing it. Reference in the destructuring would cause\n //a ReferenceError\n if (!fetcher) {\n fetcher = fetch;\n }\n\n const linkConfig = {\n http: { includeExtensions },\n options: requestOptions.fetchOptions,\n credentials: requestOptions.credentials,\n headers: requestOptions.headers,\n };\n\n return new ApolloLink(operation => {\n let chosenURI = selectURI(operation, uri);\n\n const context = operation.getContext();\n\n // `apollographql-client-*` headers are automatically set if a\n // `clientAwareness` object is found in the context. These headers are\n // set first, followed by the rest of the headers pulled from\n // `context.headers`. If desired, `apollographql-client-*` headers set by\n // the `clientAwareness` object can be overridden by\n // `apollographql-client-*` headers set in `context.headers`.\n const clientAwarenessHeaders = {};\n if (context.clientAwareness) {\n const { name, version } = context.clientAwareness;\n if (name) {\n clientAwarenessHeaders['apollographql-client-name'] = name;\n }\n if (version) {\n clientAwarenessHeaders['apollographql-client-version'] = version;\n }\n }\n\n const contextHeaders = { ...clientAwarenessHeaders, ...context.headers };\n\n const contextConfig = {\n http: context.http,\n options: context.fetchOptions,\n credentials: context.credentials,\n headers: contextHeaders,\n };\n\n //uses fallback, link, and then context to build options\n const { options, body } = selectHttpOptionsAndBody(\n operation,\n fallbackHttpConfig,\n linkConfig,\n contextConfig,\n );\n\n let controller;\n if (!(options as any).signal) {\n const { controller: _controller, signal } = createSignalIfSupported();\n controller = _controller;\n if (controller) (options as any).signal = signal;\n }\n\n // If requested, set method to GET if there are no mutations.\n const definitionIsMutation = (d: DefinitionNode) => {\n return d.kind === 'OperationDefinition' && d.operation === 'mutation';\n };\n if (\n useGETForQueries &&\n !operation.query.definitions.some(definitionIsMutation)\n ) {\n options.method = 'GET';\n }\n\n if (options.method === 'GET') {\n const { newURI, parseError } = rewriteURIForGET(chosenURI, body);\n if (parseError) {\n return fromError(parseError);\n }\n chosenURI = newURI;\n } else {\n try {\n (options as any).body = serializeFetchParame