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

1 line
11 KiB
Plaintext

{"version":3,"file":"bundle.esm.js","sources":["../src/index.ts"],"sourcesContent":["import { Operation } from 'apollo-link';\nimport { print } from 'graphql/language/printer';\nimport { InvariantError } from 'ts-invariant';\n\n/*\n * Http Utilities: shared across links that make http requests\n */\n\n// XXX replace with actual typings when available\ndeclare var AbortController: any;\n\n//Used for any Error for data from the server\n//on a request with a Status >= 300\n//response contains no data or errors\nexport type ServerError = Error & {\n response: Response;\n result: Record<string, any>;\n statusCode: number;\n};\n\n//Thrown when server's resonse is cannot be parsed\nexport type ServerParseError = Error & {\n response: Response;\n statusCode: number;\n bodyText: string;\n};\n\nexport type ClientParseError = InvariantError & {\n parseError: Error;\n};\n\nexport interface HttpQueryOptions {\n includeQuery?: boolean;\n includeExtensions?: boolean;\n}\n\nexport interface HttpConfig {\n http?: HttpQueryOptions;\n options?: any;\n headers?: any; //overrides headers in options\n credentials?: any;\n}\n\nexport interface UriFunction {\n (operation: Operation): string;\n}\n\n// The body of a GraphQL-over-HTTP-POST request.\nexport interface Body {\n query?: string;\n operationName?: string;\n variables?: Record<string, any>;\n extensions?: Record<string, any>;\n}\n\nexport interface HttpOptions {\n /**\n * The URI to use when fetching operations.\n *\n * Defaults to '/graphql'.\n */\n uri?: string | UriFunction;\n\n /**\n * Passes the extensions field to your graphql server.\n *\n * Defaults to false.\n */\n includeExtensions?: boolean;\n\n /**\n * A `fetch`-compatible API to use when making requests.\n */\n fetch?: WindowOrWorkerGlobalScope['fetch'];\n\n /**\n * An object representing values to be sent as headers on the request.\n */\n headers?: any;\n\n /**\n * The credentials policy you want to use for the fetch call.\n */\n credentials?: string;\n\n /**\n * Any overrides of the fetch options argument to pass to the fetch call.\n */\n fetchOptions?: any;\n}\n\nconst defaultHttpOptions: HttpQueryOptions = {\n includeQuery: true,\n includeExtensions: false,\n};\n\nconst defaultHeaders = {\n // headers are case insensitive (https://stackoverflow.com/a/5259004)\n accept: '*/*',\n 'content-type': 'application/json',\n};\n\nconst defaultOptions = {\n method: 'POST',\n};\n\nexport const fallbackHttpConfig = {\n http: defaultHttpOptions,\n headers: defaultHeaders,\n options: defaultOptions,\n};\n\nexport const throwServerError = (response, result, message) => {\n const error = new Error(message) as ServerError;\n\n error.name = 'ServerError';\n error.response = response;\n error.statusCode = response.status;\n error.result = result;\n\n throw error;\n};\n\n//TODO: when conditional types come in ts 2.8, operations should be a generic type that extends Operation | Array<Operation>\nexport const parseAndCheckHttpResponse = operations => (response: Response) => {\n return (\n response\n .text()\n .then(bodyText => {\n try {\n return JSON.parse(bodyText);\n } catch (err) {\n const parseError = err as ServerParseError;\n parseError.name = 'ServerParseError';\n parseError.response = response;\n parseError.statusCode = response.status;\n parseError.bodyText = bodyText;\n return Promise.reject(parseError);\n }\n })\n //TODO: when conditional types come out then result should be T extends Array ? Array<FetchResult> : FetchResult\n .then((result: any) => {\n if (response.status >= 300) {\n //Network error\n throwServerError(\n response,\n result,\n `Response not successful: Received status code ${response.status}`,\n );\n }\n //TODO should really error per response in a Batch based on properties\n // - could be done in a validation link\n if (\n !Array.isArray(result) &&\n !result.hasOwnProperty('data') &&\n !result.hasOwnProperty('errors')\n ) {\n //Data error\n throwServerError(\n response,\n result,\n `Server response was missing for query '${\n Array.isArray(operations)\n ? operations.map(op => op.operationName)\n : operations.operationName\n }'.`,\n );\n }\n return result;\n })\n );\n};\n\nexport const checkFetcher = (fetcher: WindowOrWorkerGlobalScope['fetch']) => {\n if (!fetcher && typeof fetch === 'undefined') {\n let library: string = 'unfetch';\n if (typeof window === 'undefined') library = 'node-fetch';\n throw new InvariantError(`\nfetch is not found globally and no fetcher passed, to fix pass a fetch for\nyour environment like https://www.npmjs.com/package/${library}.\n\nFor example:\nimport fetch from '${library}';\nimport { createHttpLink } from 'apollo-link-http';\n\nconst link = createHttpLink({ uri: '/graphql', fetch: fetch });`);\n }\n};\n\nexport const createSignalIfSupported = () => {\n if (typeof AbortController === 'undefined')\n return { controller: false, signal: false };\n\n const controller = new AbortController();\n const signal = controller.signal;\n return { controller, signal };\n};\n\nexport const selectHttpOptionsAndBody = (\n operation: Operation,\n fallbackConfig: HttpConfig,\n ...configs: Array<HttpConfig>\n) => {\n let options: HttpConfig & Record<string, any> = {\n ...fallbackConfig.options,\n headers: fallbackConfig.headers,\n credentials: fallbackConfig.credentials,\n };\n let http: HttpQueryOptions = fallbackConfig.http;\n\n /*\n * use the rest of the configs to populate the options\n * configs later in the list will overwrite earlier fields\n */\n configs.forEach(config => {\n options = {\n ...options,\n ...config.options,\n headers: {\n ...options.headers,\n ...config.headers,\n },\n };\n if (config.credentials) options.credentials = config.credentials;\n\n http = {\n ...http,\n ...config.http,\n };\n });\n\n //The body depends on the http options\n const { operationName, extensions, variables, query } = operation;\n const body: Body = { operationName, variables };\n\n if (http.includeExtensions) (body as any).extensions = extensions;\n\n // not sending the query (i.e persisted queries)\n if (http.includeQuery) (body as any).query = print(query);\n\n return {\n options,\n body,\n };\n};\n\nexport const serializeFetchParameter = (p, label) => {\n let serialized;\n try {\n serialized = JSON.stringify(p);\n } catch (e) {\n const parseError = new InvariantError(\n `Network request failed. ${label} is not serializable: ${e.message}`,\n ) as ClientParseError;\n parseError.parseError = e;\n throw parseError;\n }\n return serialized;\n};\n\n//selects \"/graphql\" by default\nexport const selectURI = (\n operation,\n fallbackURI?: string | ((operation: Operation) => string),\n) => {\n const context = operation.getContext();\n const contextURI = context.uri;\n\n if (contextURI) {\n return contextURI;\n } else if (typeof fallbackURI === 'function') {\n return fallbackURI(operation);\n } else {\n return (fallbackURI as string) || '/graphql';\n }\n};\n"],"names":[],"mappings":";;;;AA2FA,IAAM,kBAAkB,GAAqB;IAC3C,YAAY,EAAE,IAAI;IAClB,iBAAiB,EAAE,KAAK;CACzB,CAAC;AAEF,IAAM,cAAc,GAAG;IAErB,MAAM,EAAE,KAAK;IACb,cAAc,EAAE,kBAAkB;CACnC,CAAC;AAEF,IAAM,cAAc,GAAG;IACrB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