Odoo GraphQL Subscription using Node, Express JS for Sample
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

1 lines
14 KiB

{"version":3,"file":"batchHttpLink.js","sourceRoot":"","sources":["../../../src/link/batch-http/batchHttpLink.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EACL,UAAU,EACV,aAAa,EACb,4BAA4B,GAC7B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,OAAO,EACL,uBAAuB,EACvB,SAAS,EACT,yBAAyB,EACzB,YAAY,EACZ,gCAAgC,EAChC,cAAc,EACd,kBAAkB,GACnB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAUhF;;;GAGG;AACH;IAAmC,iCAAU;IAM3C,uBAAY,WAAmC;QAC7C,YAAA,MAAK,WAAE,SAAC;QAER,IAAI,KAaA,WAAW,IAAK,EAA4B,EAZ9C,WAAgB,EAAhB,GAAG,mBAAG,UAAU,KAAA;QAChB,mDAAmD;QAC5C,OAAO,WAAA,EACd,aAAsB,EAAtB,KAAK,mBAAG,cAAc,KAAA,EACtB,iBAAiB,uBAAA,EACjB,kBAAkB,wBAAA,EAClB,aAAa,mBAAA,EACb,aAAa,mBAAA,EACb,QAAQ,cAAA,EACR,QAAQ,cAAA,EACR,8BAA8B,EAA9B,sBAAsB,mBAAG,KAAK,KAAA,EAC3B,cAAc,cAZf,wJAaH,CAA+C,CAAC;QAEjD,0CAA0C;QAC1C,YAAY,CAAC,OAAO,CAAC,CAAC;QAEtB,sEAAsE;QACtE,4EAA4E;QAC5E,kBAAkB;QAClB,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,GAAG,KAAK,CAAC;QAClB,CAAC;QA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Aa,EAAE,KAAI,CAAC,aAAa;YACjC,QAAQ,EAAE,KAAI,CAAC,QAAQ;YACvB,QAAQ,UAAA;YACR,YAAY,cAAA;SACb,CAAC,CAAC;;IACL,CAAC;IAEM,+BAAO,GAAd,UAAe,SAAoB;QACjC,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACzC,CAAC;IACH,oBAAC;AAAD,CAAC,AAjOD,CAAmC,UAAU,GAiO5C","sourcesContent":["import type { Operation, FetchResult } from \"../core/index.js\";\nimport { ApolloLink } from \"../core/index.js\";\nimport {\n Observable,\n hasDirectives,\n removeClientSetsFromDocument,\n} from \"../../utilities/index.js\";\nimport { fromError } from \"../utils/index.js\";\nimport type { HttpOptions } from \"../http/index.js\";\nimport {\n serializeFetchParameter,\n selectURI,\n parseAndCheckHttpResponse,\n checkFetcher,\n selectHttpOptionsAndBodyInternal,\n defaultPrinter,\n fallbackHttpConfig,\n} from \"../http/index.js\";\nimport { BatchLink } from \"../batch/index.js\";\nimport { filterOperationVariables } from \"../utils/filterOperationVariables.js\";\n\nexport namespace BatchHttpLink {\n export type Options = Pick<\n BatchLink.Options,\n \"batchMax\" | \"batchDebounce\" | \"batchInterval\" | \"batchKey\"\n > &\n Omit<HttpOptions, \"useGETForQueries\">;\n}\n\n/**\n * Transforms Operation for into HTTP results.\n * context can include the headers property, which will be passed to the fetch function\n */\nexport class BatchHttpLink extends ApolloLink {\n private batchDebounce?: boolean;\n private batchInterval: number;\n private batchMax: number;\n private batcher: ApolloLink;\n\n constructor(fetchParams?: BatchHttpLink.Options) {\n super();\n\n let {\n uri = \"/graphql\",\n // use default global fetch if nothing is passed in\n fetch: fetcher,\n print = defaultPrinter,\n includeExtensions,\n preserveHeaderCase,\n batchInterval,\n batchDebounce,\n batchMax,\n batchKey,\n includeUnusedVariables = false,\n ...requestOptions\n } = fetchParams || ({} as BatchHttpLink.Options);\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, preserveHeaderCase },\n options: requestOptions.fetchOptions,\n credentials: requestOptions.credentials,\n headers: requestOptions.headers,\n };\n\n this.batchDebounce = batchDebounce;\n this.batchInterval = batchInterval || 10;\n this.batchMax = batchMax || 10;\n\n const batchHandler = (operations: Operation[]) => {\n const chosenURI = selectURI(operations[0], uri);\n\n const context = operations[0].getContext();\n\n const clientAwarenessHeaders: {\n \"apollographql-client-name\"?: string;\n \"apollographql-client-version\"?: string;\n } = {};\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 contextConfig = {\n http: context.http,\n options: context.fetchOptions,\n credentials: context.credentials,\n headers: { ...clientAwarenessHeaders, ...context.headers },\n };\n\n const queries = operations.map(({ query }) => {\n if (hasDirectives([\"client\"], query)) {\n return removeClientSetsFromDocument(query);\n }\n\n return query;\n });\n\n // If we have a query that returned `null` after removing client-only\n // fields, it indicates a query that is using all client-only fields.\n if (queries.some((query) => !query)) {\n return fromError<FetchResult[]>(\n new Error(\n \"BatchHttpLink: Trying to send a client-only query to the server. To send to the server, ensure a non-client field is added to the query or enable the `transformOptions.removeClientFields` option.\"\n )\n );\n }\n\n //uses fallback, link, and then context to build options\n const optsAndBody = operations.map((operation, index) => {\n const result = selectHttpOptionsAndBodyInternal(\n { ...operation, query: queries[index]! },\n print,\n fallbackHttpConfig,\n linkConfig,\n contextConfig\n );\n\n if (result.body.variables && !includeUnusedVariables) {\n result.body.variables = filterOperationVariables(\n result.body.variables,\n operation.query\n );\n }\n\n return result;\n });\n\n const loadedBody = optsAndBody.map(({ body }) => body);\n const options = optsAndBody[0].options;\n\n // There's no spec for using GET with batches.\n if (options.method === \"GET\") {\n return fromError<FetchResult[]>(\n new Error(\"apollo-link-batch-http does not support GET requests\")\n );\n }\n\n try {\n (options as any).body = serializeFetchParameter(loadedBody, \"Payload\");\n } catch (parseError) {\n return fromError<FetchResult[]>(parseError);\n }\n\n let controller: AbortController | undefined;\n if (!options.signal && typeof AbortController !== \"undefined\") {\n controller = new AbortController();\n options.signal = controller.signal;\n }\n\n return new Observable<FetchResult[]>((observer) => {\n fetcher!(chosenURI, options)\n .then((response) => {\n // Make the raw response available in the context.\n operations.forEach((operation) =>\n operation.setContext({ response })\n );\n return response;\n })\n .then(parseAndCheckHttpResponse(operations))\n .then((result) => {\n controller = undefined;\n // we have data and can send it to back up the link chain\n observer.next(result);\n observer.complete();\n return result;\n })\n .catch((err) => {\n controller = undefined;\n // if it is a network error, BUT there is graphql result info\n // fire the next observer before calling error\n // this gives apollo-client (and react-apollo) the `graphqlErrors` and `networkErrors`\n // to pass to UI\n // this should only happen if we *also* have data as part of the response key per\n // the spec\n if (err.result && err.result.errors && err.result.data) {\n // if we dont' call next, the UI can only show networkError because AC didn't\n // get andy graphqlErrors\n // this is graphql execution result info (i.e errors and possibly data)\n // this is because there is no formal spec how errors should translate to\n // http status codes. So an auth error (401) could have both data\n // from a public field, errors from a private field, and a status of 401\n // {\n // user { // this will have errors\n // firstName\n // }\n // products { // this is public so will have data\n // cost\n // }\n // }\n //\n // the result of above *could* look like this:\n // {\n // data: { products: [{ cost: \"$10\" }] },\n // errors: [{\n // message: 'your session has timed out',\n // path: []\n // }]\n // }\n // status code of above would be a 401\n // in the UI you want to show data where you can, errors as data where you can\n // and use correct http status codes\n observer.next(err.result);\n }\n\n observer.error(err);\n });\n\n return () => {\n // XXX support canceling this request\n // https://developers.google.com/web/updates/2017/09/abortable-fetch\n if (controller) controller.abort();\n };\n });\n };\n\n batchKey =\n batchKey ||\n ((operation: Operation) => {\n const context = operation.getContext();\n\n const contextConfig = {\n http: context.http,\n options: context.fetchOptions,\n credentials: context.credentials,\n headers: context.headers,\n };\n\n //may throw error if config not serializable\n return selectURI(operation, uri) + JSON.stringify(contextConfig);\n });\n\n this.batcher = new BatchLink({\n batchDebounce: this.batchDebounce,\n batchInterval: this.batchInterval,\n batchMax: this.batchMax,\n batchKey,\n batchHandler,\n });\n }\n\n public request(operation: Operation): Observable<FetchResult> | null {\n return this.batcher.request(operation);\n }\n}\n"]}