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
17 KiB

{"version":3,"file":"batch-http.cjs","sources":["../utils/filterOperationVariables.js","batchHttpLink.js"],"sourcesContent":["import { __assign } from \"tslib\";\nimport { visit } from \"graphql\";\nexport function filterOperationVariables(variables, query) {\n var result = __assign({}, variables);\n var unusedNames = new Set(Object.keys(variables));\n visit(query, {\n Variable: function (node, _key, parent) {\n // A variable type definition at the top level of a query is not\n // enough to silence server-side errors about the variable being\n // unused, so variable definitions do not count as usage.\n // https://spec.graphql.org/draft/#sec-All-Variables-Used\n if (parent &&\n parent.kind !== \"VariableDefinition\") {\n unusedNames.delete(node.name.value);\n }\n },\n });\n unusedNames.forEach(function (name) {\n delete result[name];\n });\n return result;\n}\n//# sourceMappingURL=filterOperationVariables.js.map","import { __assign, __extends, __rest } from \"tslib\";\nimport { ApolloLink } from \"../core/index.js\";\nimport { Observable, hasDirectives, removeClientSetsFromDocument, } from \"../../utilities/index.js\";\nimport { fromError } from \"../utils/index.js\";\nimport { serializeFetchParameter, selectURI, parseAndCheckHttpResponse, checkFetcher, selectHttpOptionsAndBodyInternal, defaultPrinter, fallbackHttpConfig, } from \"../http/index.js\";\nimport { BatchLink } from \"../batch/index.js\";\nimport { filterOperationVariables } from \"../utils/filterOperationVariables.js\";\n/**\n * Transforms Operation for into HTTP results.\n * context can include the headers property, which will be passed to the fetch function\n */\nvar BatchHttpLink = /** @class */ (function (_super) {\n __extends(BatchHttpLink, _super);\n function BatchHttpLink(fetchParams) {\n var _this = _super.call(this) || this;\n var _a = fetchParams || {}, _b = _a.uri, uri = _b === void 0 ? \"/graphql\" : _b, \n // use default global fetch if nothing is passed in\n fetcher = _a.fetch, _c = _a.print, print = _c === void 0 ? defaultPrinter : _c, includeExtensions = _a.includeExtensions, preserveHeaderCase = _a.preserveHeaderCase, batchInterval = _a.batchInterval, batchDebounce = _a.batchDebounce, batchMax = _a.batchMax, batchKey = _a.batchKey, _d = _a.includeUnusedVariables, includeUnusedVariables = _d === void 0 ? false : _d, requestOptions = __rest(_a, [\"uri\", \"fetch\", \"print\", \"includeExtensions\", \"preserveHeaderCase\", \"batchInterval\", \"batchDebounce\", \"batchMax\", \"batchKey\", \"includeUnusedVariables\"]);\n // dev warnings to ensure fetch is present\n checkFetcher(fetcher);\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 var linkConfig = {\n http: { includeExtensions: includeExtensions, preserveHeaderCase: preserveHeaderCase },\n options: requestOptions.fetchOptions,\n credentials: requestOptions.credentials,\n headers: requestOptions.headers,\n };\n _this.batchDebounce = batchDebounce;\n _this.batchInterval = batchInterval || 10;\n _this.batchMax = batchMax || 10;\n var batchHandler = function (operations) {\n var chosenURI = selectURI(operations[0], uri);\n var context = operations[0].getContext();\n var clientAwarenessHeaders = {};\n if (context.clientAwareness) {\n var _a = context.clientAwareness, name_1 = _a.name, version = _a.version;\n if (name_1) {\n clientAwarenessHeaders[\"apollographql-client-name\"] = name_1;\n }\n if (version) {\n clientAwarenessHeaders[\"apollographql-client-version\"] = version;\n }\n }\n var contextConfig = {\n http: context.http,\n options: context.fetchOptions,\n credentials: context.credentials,\n headers: __assign(__assign({}, clientAwarenessHeaders), context.headers),\n };\n var queries = operations.map(function (_a) {\n var query = _a.query;\n if (hasDirectives([\"client\"], query)) {\n return removeClientSetsFromDocument(query);\n }\n return query;\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(function (query) { return !query; })) {\n return fromError(new Error(\"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 //uses fallback, link, and then context to build options\n var optsAndBody = operations.map(function (operation, index) {\n var result = selectHttpOptionsAndBodyInternal(__assign(__assign({}, operation), { query: queries[index] }), print, fallbackHttpConfig, linkConfig, contextConfig);\n if (result.body.variables && !includeUnusedVariables) {\n result.body.variables = filterOperationVariables(result.body.variables, operation.query);\n }\n return result;\n });\n var loadedBody = optsAndBody.map(function (_a) {\n var body = _a.body;\n return body;\n });\n var options = optsAndBody[0].options;\n // There's no spec for using GET with batches.\n if (options.method === \"GET\") {\n return fromError(new Error(\"apollo-link-batch-http does not support GET requests\"));\n }\n try {\n options.body = serializeFetchParameter(loadedBody, \"Payload\");\n }\n catch (parseError) {\n return fromError(parseError);\n }\n var controller;\n if (!options.signal && typeof AbortController !== \"undefined\") {\n controller = new AbortController();\n options.signal = controller.signal;\n }\n return new Observable(function (observer) {\n fetcher(chosenURI, options)\n .then(function (response) {\n // Make the raw response available in the context.\n operations.forEach(function (operation) {\n return operation.setContext({ response: response });\n });\n return response;\n })\n .then(parseAndCheckHttpResponse(operations))\n .then(function (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(function (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 observer.error(err);\n });\n return function () {\n // XXX support canceling this request\n // https://developers.google.com/web/updates/2017/09/abortable-fetch\n if (controller)\n controller.abort();\n };\n });\n };\n batchKey =\n batchKey ||\n (function (operation) {\n var context = operation.getContext();\n var contextConfig = {\n http: context.http,\n options: context.fetchOptions,\n credentials: context.credentials,\n headers: context.headers,\n };\n //may throw error if config not serializable\n return selectURI(operation, uri) + JSON.stringify(contextConfig);\n });\n _this.batcher = new BatchLink({\n batchDebounce: _this.batchDebounce,\n batchInterval: _this.batchInterval,\n batchMax: _this.batchMax,\n batchKey: batchKey,\n batchHandler: batchHandler,\n });\n return _this;\n }\n BatchHttpLink.prototype.request = function (operation) {\n return this.batcher.request(operation);\n };\n return BatchHttpLink;\n}(ApolloLink));\nexport { BatchHttpLink };\n//# sourceMappingURL=batchHttpLink.js.map"],"names":["__assign","visit","__extends","defaultPrinter","__rest","checkFetcher","selectURI","hasDirectives","removeClientSetsFromDocument","fromError","selectHttpOptionsAndBodyInternal","fallbackHttpConfig","serializeFetchParameter","Observable","parseAndCheckHttpResponse","BatchLink","ApolloLink"],"mappings":";;;;;;;;;;;;AAEO,SAAS,wBAAwB,CAAC,SAAS,EAAE,KAAK,EAAE;AAC3D,IAAI,IAAI,MAAM,GAAGA,cAAQ,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC;AACzC,IAAI,IAAI,WAAW,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;AACtD,IAAIC,aAAK,CAAC,KAAK,EAAE;AACjB,QAAQ,QAAQ,EAAE,UAAU,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE;AAKhD,YAAY,IAAI,MAAM;AACtB,gBAAgB,MAAM,CAAC,IAAI,KAAK,oBAAoB,EAAE;AACtD,gBAAgB,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACpD,aAAa;AACb,SAAS;AACT,KAAK,CAAC,CAAC;AACP,IAAI,WAAW,CAAC,OAAO,CAAC,UAAU,IAAI,EAAE;AACxC,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