@apollo/client 3.8.8 → 3.8.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -3
- package/apollo-client.cjs +46 -42
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/core/core.cjs +1 -1
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +1 -1
- package/dev/dev.cjs +1 -1
- package/dev/dev.cjs.map +1 -1
- package/dev/dev.cjs.native.js +1 -1
- package/link/http/checkFetcher.d.ts +1 -1
- package/link/http/checkFetcher.js.map +1 -1
- package/link/http/http.cjs +0 -3
- package/link/http/http.cjs.map +1 -1
- package/link/http/http.cjs.native.js +0 -3
- package/link/http/parseAndCheckHttpResponse.js +0 -4
- package/link/http/parseAndCheckHttpResponse.js.map +1 -1
- package/link/http/selectHttpOptionsAndBody.d.ts +1 -1
- package/link/http/selectHttpOptionsAndBody.js.map +1 -1
- package/package.json +32 -32
- package/react/hooks/hooks.cjs +45 -38
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +45 -38
- package/react/hooks/internal/index.d.ts +1 -0
- package/react/hooks/internal/index.js +1 -0
- package/react/hooks/internal/index.js.map +1 -1
- package/react/hooks/internal/useLazyRef.d.ts +3 -0
- package/react/hooks/internal/useLazyRef.js +10 -0
- package/react/hooks/internal/useLazyRef.js.map +1 -0
- package/react/hooks/useFragment.js +20 -17
- package/react/hooks/useFragment.js.map +1 -1
- package/testing/core/core.cjs +4 -2
- package/testing/core/core.cjs.map +1 -1
- package/testing/core/core.cjs.native.js +4 -2
- package/testing/core/mocking/mockLink.js +8 -2
- package/testing/core/mocking/mockLink.js.map +1 -1
- package/utilities/globals/globals.cjs +1 -1
- package/utilities/globals/globals.cjs.map +1 -1
- package/utilities/globals/globals.cjs.native.js +1 -1
- package/version.js +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseAndChe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BACtB,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC;gBACpC,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,EACtC,CAAC;gBACD,aAAa;gBACb,gBAAgB,CACd,QAAQ,EACR,MAAM,EACN,iDACE,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;oBACzB,UAAU,CAAC,GAAG,CAAC,UAAC,EAAE,IAAK,OAAA,EAAE,CAAC,aAAa,EAAhB,CAAgB,CAAC;oBAC1C,CAAC,CAAC,UAAU,CAAC,aAAa,OACxB,CACL,CAAC;YACJ,CAAC;YACD,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC;IA7BJ,CA6BI,CAAC;AACT,CAAC","sourcesContent":["import { responseIterator } from \"./responseIterator.js\";\nimport type { Operation } from \"../core/index.js\";\nimport { throwServerError } from \"../utils/index.js\";\nimport { PROTOCOL_ERRORS_SYMBOL } from \"../../errors/index.js\";\nimport { isApolloPayloadResult } from \"../../utilities/common/incrementalResult.js\";\nimport type { SubscriptionObserver } from \"zen-observable-ts\";\n\nconst { hasOwnProperty } = Object.prototype;\n\nexport type ServerParseError = Error & {\n response: Response;\n statusCode: number;\n bodyText: string;\n};\n\nexport async function readMultipartBody<\n T extends object = Record<string, unknown>,\n>(response: Response, nextValue: (value: T) => void) {\n if (TextDecoder === undefined) {\n throw new Error(\n \"TextDecoder must be defined in the environment: please import a polyfill.\"\n );\n }\n const decoder = new TextDecoder(\"utf-8\");\n const contentType = response.headers?.get(\"content-type\");\n const delimiter = \"boundary=\";\n\n // parse boundary value and ignore any subsequent name/value pairs after ;\n // https://www.rfc-editor.org/rfc/rfc9110.html#name-parameters\n // e.g. multipart/mixed;boundary=\"graphql\";deferSpec=20220824\n // if no boundary is specified, default to -\n const boundaryVal =\n contentType?.includes(delimiter) ?\n contentType\n ?.substring(contentType?.indexOf(delimiter) + delimiter.length)\n .replace(/['\"]/g, \"\")\n .replace(/\\;(.*)/gm, \"\")\n .trim()\n : \"-\";\n\n const boundary = `\\r\\n--${boundaryVal}`;\n let buffer = \"\";\n const iterator = responseIterator(response);\n let running = true;\n\n while (running) {\n const { value, done } = await iterator.next();\n const chunk = typeof value === \"string\" ? value : decoder.decode(value);\n const searchFrom = buffer.length - boundary.length + 1;\n running = !done;\n buffer += chunk;\n let bi = buffer.indexOf(boundary, searchFrom);\n\n while (bi > -1) {\n let message: string;\n [message, buffer] = [\n buffer.slice(0, bi),\n buffer.slice(bi + boundary.length),\n ];\n const i = message.indexOf(\"\\r\\n\\r\\n\");\n const headers = parseHeaders(message.slice(0, i));\n const contentType = headers[\"content-type\"];\n if (\n contentType &&\n contentType.toLowerCase().indexOf(\"application/json\") === -1\n ) {\n throw new Error(\n \"Unsupported patch content type: application/json is required.\"\n );\n }\n // nb: Technically you'd want to slice off the beginning \"\\r\\n\" but since\n // this is going to be `JSON.parse`d there is no need.\n const body = message.slice(i);\n\n if (body) {\n const result = parseJsonBody<T>(response, body);\n if (\n Object.keys(result).length > 1 ||\n \"data\" in result ||\n \"incremental\" in result ||\n \"errors\" in result ||\n \"payload\" in result\n ) {\n if (isApolloPayloadResult(result)) {\n let next = {};\n if (\"payload\" in result) {\n next = { ...result.payload };\n }\n if (\"errors\" in result) {\n next = {\n ...next,\n extensions: {\n ...(\"extensions\" in next ? next.extensions : (null as any)),\n [PROTOCOL_ERRORS_SYMBOL]: result.errors,\n },\n };\n }\n nextValue(next as T);\n } else {\n // for the last chunk with only `hasNext: false`\n // we don't need to call observer.next as there is no data/errors\n nextValue(result);\n }\n } else if (\n // If the chunk contains only a \"hasNext: false\", we can call\n // observer.complete() immediately.\n Object.keys(result).length === 1 &&\n \"hasNext\" in result &&\n !result.hasNext\n ) {\n return;\n }\n }\n bi = buffer.indexOf(boundary);\n }\n }\n}\n\nexport function parseHeaders(headerText: string): Record<string, string> {\n const headersInit: Record<string, string> = {};\n headerText.split(\"\\n\").forEach((line) => {\n const i = line.indexOf(\":\");\n if (i > -1) {\n // normalize headers to lowercase\n const name = line.slice(0, i).trim().toLowerCase();\n const value = line.slice(i + 1).trim();\n headersInit[name] = value;\n }\n });\n return headersInit;\n}\n\nexport function parseJsonBody<T>(response: Response, bodyText: string): T {\n if (response.status >= 300) {\n // Network error\n const getResult = (): Record<string, unknown> | string => {\n try {\n return JSON.parse(bodyText);\n } catch (err) {\n return bodyText;\n }\n };\n throwServerError(\n response,\n getResult(),\n `Response not successful: Received status code ${response.status}`\n );\n }\n\n try {\n return JSON.parse(bodyText) as T;\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 throw parseError;\n }\n}\n\nexport function handleError(err: any, observer: SubscriptionObserver<any>) {\n // if it is a network error, BUT there is graphql result info fire\n // the next observer before calling error this gives apollo-client\n // (and react-apollo) the `graphqlErrors` and `networkErrors` to\n // pass to UI this should only happen if we *also* have data as\n // part of the response key per the spec\n if (err.result && err.result.errors && err.result.data) {\n // if we don't call next, the UI can only show networkError\n // because AC didn't get any graphqlErrors this is graphql\n // execution result info (i.e errors and possibly data) this is\n // 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\n // 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\nexport function parseAndCheckHttpResponse(operations: Operation | Operation[]) {\n return (response: Response) =>\n response\n .text()\n .then((bodyText) => parseJsonBody(response, bodyText))\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 if (\n !Array.isArray(result) &&\n !hasOwnProperty.call(result, \"data\") &&\n !hasOwnProperty.call(result, \"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"]}
|
|
1
|
+
{"version":3,"file":"parseAndCheckHttpResponse.js","sourceRoot":"","sources":["../../../src/link/http/parseAndCheckHttpResponse.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,6CAA6C,CAAC;AAG5E,IAAA,cAAc,GAAK,MAAM,CAAC,SAAS,eAArB,CAAsB;AAQ5C,MAAM,UAAgB,iBAAiB,CAErC,QAAkB,EAAE,SAA6B;;;;;;;;oBACjD,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;wBAC9B,MAAM,IAAI,KAAK,CACb,2EAA2E,CAC5E,CAAC;oBACJ,CAAC;oBACK,OAAO,GAAG,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC;oBACnC,WAAW,GAAG,MAAA,QAAQ,CAAC,OAAO,0CAAE,GAAG,CAAC,cAAc,CAAC,CAAC;oBACpD,SAAS,GAAG,WAAW,CAAC;oBAMxB,WAAW,GACf,CAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,QAAQ,CAAC,SAAS,CAAC,EAAC,CAAC;wBAChC,WAAW,aAAX,WAAW,uBAAX,WAAW,CACP,SAAS,CAAC,CAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,OAAO,CAAC,SAAS,CAAC,IAAG,SAAS,CAAC,MAAM,EAC7D,OAAO,CAAC,OAAO,EAAE,EAAE,EACnB,OAAO,CAAC,UAAU,EAAE,EAAE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;YAChB,IACE,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;gBACtB,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC;gBACpC,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,EACtC,CAAC;gBACD,aAAa;gBACb,gBAAgB,CACd,QAAQ,EACR,MAAM,EACN,iDACE,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;oBACzB,UAAU,CAAC,GAAG,CAAC,UAAC,EAAE,IAAK,OAAA,EAAE,CAAC,aAAa,EAAhB,CAAgB,CAAC;oBAC1C,CAAC,CAAC,UAAU,CAAC,aAAa,OACxB,CACL,CAAC;YACJ,CAAC;YACD,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC;IArBJ,CAqBI,CAAC;AACT,CAAC","sourcesContent":["import { responseIterator } from \"./responseIterator.js\";\nimport type { Operation } from \"../core/index.js\";\nimport { throwServerError } from \"../utils/index.js\";\nimport { PROTOCOL_ERRORS_SYMBOL } from \"../../errors/index.js\";\nimport { isApolloPayloadResult } from \"../../utilities/common/incrementalResult.js\";\nimport type { SubscriptionObserver } from \"zen-observable-ts\";\n\nconst { hasOwnProperty } = Object.prototype;\n\nexport type ServerParseError = Error & {\n response: Response;\n statusCode: number;\n bodyText: string;\n};\n\nexport async function readMultipartBody<\n T extends object = Record<string, unknown>,\n>(response: Response, nextValue: (value: T) => void) {\n if (TextDecoder === undefined) {\n throw new Error(\n \"TextDecoder must be defined in the environment: please import a polyfill.\"\n );\n }\n const decoder = new TextDecoder(\"utf-8\");\n const contentType = response.headers?.get(\"content-type\");\n const delimiter = \"boundary=\";\n\n // parse boundary value and ignore any subsequent name/value pairs after ;\n // https://www.rfc-editor.org/rfc/rfc9110.html#name-parameters\n // e.g. multipart/mixed;boundary=\"graphql\";deferSpec=20220824\n // if no boundary is specified, default to -\n const boundaryVal =\n contentType?.includes(delimiter) ?\n contentType\n ?.substring(contentType?.indexOf(delimiter) + delimiter.length)\n .replace(/['\"]/g, \"\")\n .replace(/\\;(.*)/gm, \"\")\n .trim()\n : \"-\";\n\n const boundary = `\\r\\n--${boundaryVal}`;\n let buffer = \"\";\n const iterator = responseIterator(response);\n let running = true;\n\n while (running) {\n const { value, done } = await iterator.next();\n const chunk = typeof value === \"string\" ? value : decoder.decode(value);\n const searchFrom = buffer.length - boundary.length + 1;\n running = !done;\n buffer += chunk;\n let bi = buffer.indexOf(boundary, searchFrom);\n\n while (bi > -1) {\n let message: string;\n [message, buffer] = [\n buffer.slice(0, bi),\n buffer.slice(bi + boundary.length),\n ];\n const i = message.indexOf(\"\\r\\n\\r\\n\");\n const headers = parseHeaders(message.slice(0, i));\n const contentType = headers[\"content-type\"];\n if (\n contentType &&\n contentType.toLowerCase().indexOf(\"application/json\") === -1\n ) {\n throw new Error(\n \"Unsupported patch content type: application/json is required.\"\n );\n }\n // nb: Technically you'd want to slice off the beginning \"\\r\\n\" but since\n // this is going to be `JSON.parse`d there is no need.\n const body = message.slice(i);\n\n if (body) {\n const result = parseJsonBody<T>(response, body);\n if (\n Object.keys(result).length > 1 ||\n \"data\" in result ||\n \"incremental\" in result ||\n \"errors\" in result ||\n \"payload\" in result\n ) {\n if (isApolloPayloadResult(result)) {\n let next = {};\n if (\"payload\" in result) {\n next = { ...result.payload };\n }\n if (\"errors\" in result) {\n next = {\n ...next,\n extensions: {\n ...(\"extensions\" in next ? next.extensions : (null as any)),\n [PROTOCOL_ERRORS_SYMBOL]: result.errors,\n },\n };\n }\n nextValue(next as T);\n } else {\n // for the last chunk with only `hasNext: false`\n // we don't need to call observer.next as there is no data/errors\n nextValue(result);\n }\n } else if (\n // If the chunk contains only a \"hasNext: false\", we can call\n // observer.complete() immediately.\n Object.keys(result).length === 1 &&\n \"hasNext\" in result &&\n !result.hasNext\n ) {\n return;\n }\n }\n bi = buffer.indexOf(boundary);\n }\n }\n}\n\nexport function parseHeaders(headerText: string): Record<string, string> {\n const headersInit: Record<string, string> = {};\n headerText.split(\"\\n\").forEach((line) => {\n const i = line.indexOf(\":\");\n if (i > -1) {\n // normalize headers to lowercase\n const name = line.slice(0, i).trim().toLowerCase();\n const value = line.slice(i + 1).trim();\n headersInit[name] = value;\n }\n });\n return headersInit;\n}\n\nexport function parseJsonBody<T>(response: Response, bodyText: string): T {\n if (response.status >= 300) {\n // Network error\n const getResult = (): Record<string, unknown> | string => {\n try {\n return JSON.parse(bodyText);\n } catch (err) {\n return bodyText;\n }\n };\n throwServerError(\n response,\n getResult(),\n `Response not successful: Received status code ${response.status}`\n );\n }\n\n try {\n return JSON.parse(bodyText) as T;\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 throw parseError;\n }\n}\n\nexport function handleError(err: any, observer: SubscriptionObserver<any>) {\n // if it is a network error, BUT there is graphql result info fire\n // the next observer before calling error this gives apollo-client\n // (and react-apollo) the `graphqlErrors` and `networkErrors` to\n // pass to UI this should only happen if we *also* have data as\n // part of the response key per the spec\n if (err.result && err.result.errors && err.result.data) {\n // if we don't call next, the UI can only show networkError\n // because AC didn't get any graphqlErrors this is graphql\n // execution result info (i.e errors and possibly data) this is\n // 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\n // 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\nexport function parseAndCheckHttpResponse(operations: Operation | Operation[]) {\n return (response: Response) =>\n response\n .text()\n .then((bodyText) => parseJsonBody(response, bodyText))\n .then((result: any) => {\n if (\n !Array.isArray(result) &&\n !hasOwnProperty.call(result, \"data\") &&\n !hasOwnProperty.call(result, \"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"]}
|
|
@@ -29,7 +29,7 @@ export interface HttpOptions {
|
|
|
29
29
|
/**
|
|
30
30
|
* A `fetch`-compatible API to use when making requests.
|
|
31
31
|
*/
|
|
32
|
-
fetch?:
|
|
32
|
+
fetch?: typeof fetch;
|
|
33
33
|
/**
|
|
34
34
|
* An object representing values to be sent as headers on the request.
|
|
35
35
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selectHttpOptionsAndBody.js","sourceRoot":"","sources":["../../../src/link/http/selectHttpOptionsAndBody.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAkGjD,IAAM,kBAAkB,GAAqB;IAC3C,YAAY,EAAE,IAAI;IAClB,iBAAiB,EAAE,KAAK;IACxB,kBAAkB,EAAE,KAAK;CAC1B,CAAC;AAEF,IAAM,cAAc,GAAG;IACrB,qEAAqE;IACrE,MAAM,EAAE,KAAK;IACb,6EAA6E;IAC7E,4EAA4E;IAC5E,8EAA8E;IAC9E,6EAA6E;IAC7E,2EAA2E;IAC3E,wEAAwE;IACxE,4EAA4E;IAC5E,6EAA6E;IAC7E,2EAA2E;IAC3E,iEAAiE;IACjE,6GAA6G;IAC7G,oBAAoB;IACpB,cAAc,EAAE,kBAAkB;CACnC,CAAC;AAEF,IAAM,cAAc,GAAG;IACrB,MAAM,EAAE,MAAM;CACf,CAAC;AAEF,MAAM,CAAC,IAAM,kBAAkB,GAAG;IAChC,IAAI,EAAE,kBAAkB;IACxB,OAAO,EAAE,cAAc;IACvB,OAAO,EAAE,cAAc;CACxB,CAAC;AAEF,MAAM,CAAC,IAAM,cAAc,GAAY,UAAC,GAAG,EAAE,OAAO,IAAK,OAAA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;QACnC,iBAAiB,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC;IAC5E,CAAC,CAAC,CAAC;IACH,OAAO,iBAAiB,CAAC;AAC3B,CAAC","sourcesContent":["import type { ASTNode } from \"graphql\";\nimport { print } from \"../../utilities/index.js\";\n\nimport type { Operation } from \"../core/index.js\";\n\nexport interface Printer {\n (node: ASTNode, originalPrint: typeof print): string;\n}\n\nexport interface UriFunction {\n (operation: Operation): string;\n}\n\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?:
|
|
1
|
+
{"version":3,"file":"selectHttpOptionsAndBody.js","sourceRoot":"","sources":["../../../src/link/http/selectHttpOptionsAndBody.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAkGjD,IAAM,kBAAkB,GAAqB;IAC3C,YAAY,EAAE,IAAI;IAClB,iBAAiB,EAAE,KAAK;IACxB,kBAAkB,EAAE,KAAK;CAC1B,CAAC;AAEF,IAAM,cAAc,GAAG;IACrB,qEAAqE;IACrE,MAAM,EAAE,KAAK;IACb,6EAA6E;IAC7E,4EAA4E;IAC5E,8EAA8E;IAC9E,6EAA6E;IAC7E,2EAA2E;IAC3E,wEAAwE;IACxE,4EAA4E;IAC5E,6EAA6E;IAC7E,2EAA2E;IAC3E,iEAAiE;IACjE,6GAA6G;IAC7G,oBAAoB;IACpB,cAAc,EAAE,kBAAkB;CACnC,CAAC;AAEF,IAAM,cAAc,GAAG;IACrB,MAAM,EAAE,MAAM;CACf,CAAC;AAEF,MA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AAI,CAAC;SACrB,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,IAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC9C,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,UAAC,IAAI;QACnC,iBAAiB,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC;IAC5E,CAAC,CAAC,CAAC;IACH,OAAO,iBAAiB,CAAC;AAC3B,CAAC","sourcesContent":["import type { ASTNode } from \"graphql\";\nimport { print } from \"../../utilities/index.js\";\n\nimport type { Operation } from \"../core/index.js\";\n\nexport interface Printer {\n (node: ASTNode, originalPrint: typeof print): string;\n}\n\nexport interface UriFunction {\n (operation: Operation): string;\n}\n\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?: typeof fetch;\n\n /**\n * An object representing values to be sent as headers on the request.\n */\n headers?: Record<string, string>;\n\n /**\n * If set to true, header names won't be automatically normalized to\n * lowercase. This allows for non-http-spec-compliant servers that might\n * expect capitalized header names.\n */\n preserveHeaderCase?: boolean;\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 /**\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 * If set to true, the default behavior of stripping unused variables\n * from the request will be disabled.\n *\n * Unused variables are likely to trigger server-side validation errors,\n * per https://spec.graphql.org/draft/#sec-All-Variables-Used, but this\n * includeUnusedVariables option can be useful if your server deviates\n * from the GraphQL specification by not strictly enforcing that rule.\n */\n includeUnusedVariables?: boolean;\n /**\n * A function to substitute for the default query print function. Can be\n * used to apply changes to the results of the print function.\n */\n print?: Printer;\n}\n\nexport interface HttpQueryOptions {\n includeQuery?: boolean;\n includeExtensions?: boolean;\n preserveHeaderCase?: boolean;\n}\n\nexport interface HttpConfig {\n http?: HttpQueryOptions;\n options?: any;\n headers?: Record<string, string>;\n credentials?: any;\n}\n\nconst defaultHttpOptions: HttpQueryOptions = {\n includeQuery: true,\n includeExtensions: false,\n preserveHeaderCase: false,\n};\n\nconst defaultHeaders = {\n // headers are case insensitive (https://stackoverflow.com/a/5259004)\n accept: \"*/*\",\n // The content-type header describes the type of the body of the request, and\n // so it typically only is sent with requests that actually have bodies. One\n // could imagine that Apollo Client would remove this header when constructing\n // a GET request (which has no body), but we historically have not done that.\n // This means that browsers will preflight all Apollo Client requests (even\n // GET requests). Apollo Server's CSRF prevention feature (introduced in\n // AS3.7) takes advantage of this fact and does not block requests with this\n // header. If you want to drop this header from GET requests, then you should\n // probably replace it with a `apollo-require-preflight` header, or servers\n // with CSRF prevention enabled might block your GET request. See\n // https://www.apollographql.com/docs/apollo-server/security/cors/#preventing-cross-site-request-forgery-csrf\n // for more details.\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 defaultPrinter: Printer = (ast, printer) => printer(ast);\n\nexport function selectHttpOptionsAndBody(\n operation: Operation,\n fallbackConfig: HttpConfig,\n ...configs: Array<HttpConfig>\n) {\n configs.unshift(fallbackConfig);\n return selectHttpOptionsAndBodyInternal(\n operation,\n defaultPrinter,\n ...configs\n );\n}\n\nexport function selectHttpOptionsAndBodyInternal(\n operation: Operation,\n printer: Printer,\n ...configs: HttpConfig[]\n) {\n let options = {} as HttpConfig & Record<string, any>;\n let http = {} as HttpQueryOptions;\n\n configs.forEach((config) => {\n options = {\n ...options,\n ...config.options,\n headers: {\n ...options.headers,\n ...config.headers,\n },\n };\n\n if (config.credentials) {\n options.credentials = config.credentials;\n }\n\n http = {\n ...http,\n ...config.http,\n };\n });\n\n if (options.headers) {\n options.headers = removeDuplicateHeaders(\n options.headers,\n http.preserveHeaderCase\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 = printer(query, print);\n\n return {\n options,\n body,\n };\n}\n\n// Remove potential duplicate header names, preserving last (by insertion order).\n// This is done to prevent unintentionally duplicating a header instead of\n// overwriting it (See #8447 and #8449).\nfunction removeDuplicateHeaders(\n headers: Record<string, string>,\n preserveHeaderCase: boolean | undefined\n): typeof headers {\n // If we're not preserving the case, just remove duplicates w/ normalization.\n if (!preserveHeaderCase) {\n const normalizedHeaders = Object.create(null);\n Object.keys(Object(headers)).forEach((name) => {\n normalizedHeaders[name.toLowerCase()] = headers[name];\n });\n return normalizedHeaders;\n }\n\n // If we are preserving the case, remove duplicates w/ normalization,\n // preserving the original name.\n // This allows for non-http-spec-compliant servers that expect intentionally\n // capitalized header names (See #6741).\n const headerData = Object.create(null);\n Object.keys(Object(headers)).forEach((name) => {\n headerData[name.toLowerCase()] = {\n originalName: name,\n value: headers[name],\n };\n });\n\n const normalizedHeaders = Object.create(null);\n Object.keys(headerData).forEach((name) => {\n normalizedHeaders[headerData[name].originalName] = headerData[name].value;\n });\n return normalizedHeaders;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apollo/client",
|
|
3
|
-
"version": "3.8.
|
|
3
|
+
"version": "3.8.9",
|
|
4
4
|
"description": "A fully-featured caching GraphQL client.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"keywords": [
|
|
@@ -65,41 +65,41 @@
|
|
|
65
65
|
"zen-observable-ts": "^1.2.5"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@arethetypeswrong/cli": "0.13.
|
|
69
|
-
"@babel/parser": "7.23.
|
|
70
|
-
"@changesets/changelog-github": "0.
|
|
71
|
-
"@changesets/cli": "2.
|
|
68
|
+
"@arethetypeswrong/cli": "0.13.5",
|
|
69
|
+
"@babel/parser": "7.23.6",
|
|
70
|
+
"@changesets/changelog-github": "0.5.0",
|
|
71
|
+
"@changesets/cli": "2.27.1",
|
|
72
72
|
"@graphql-tools/schema": "10.0.2",
|
|
73
|
-
"@microsoft/api-extractor": "7.
|
|
73
|
+
"@microsoft/api-extractor": "7.39.1",
|
|
74
74
|
"@rollup/plugin-node-resolve": "11.2.1",
|
|
75
|
-
"@size-limit/esbuild-why": "11.0.
|
|
76
|
-
"@size-limit/preset-small-lib": "11.0.
|
|
77
|
-
"@testing-library/jest-dom": "6.
|
|
75
|
+
"@size-limit/esbuild-why": "11.0.1",
|
|
76
|
+
"@size-limit/preset-small-lib": "11.0.1",
|
|
77
|
+
"@testing-library/jest-dom": "6.2.0",
|
|
78
78
|
"@testing-library/react": "14.1.2",
|
|
79
79
|
"@testing-library/react-12": "npm:@testing-library/react@^12",
|
|
80
|
-
"@testing-library/user-event": "14.5.
|
|
80
|
+
"@testing-library/user-event": "14.5.2",
|
|
81
81
|
"@tsconfig/node20": "20.1.2",
|
|
82
82
|
"@types/bytes": "3.1.4",
|
|
83
83
|
"@types/fetch-mock": "7.3.8",
|
|
84
84
|
"@types/glob": "8.1.0",
|
|
85
85
|
"@types/hoist-non-react-statics": "3.3.5",
|
|
86
|
-
"@types/jest": "29.5.
|
|
86
|
+
"@types/jest": "29.5.11",
|
|
87
87
|
"@types/lodash": "4.14.202",
|
|
88
|
-
"@types/node": "20.10.
|
|
89
|
-
"@types/node-fetch": "2.6.
|
|
90
|
-
"@types/react": "18.2.
|
|
91
|
-
"@types/react-dom": "18.2.
|
|
88
|
+
"@types/node": "20.10.7",
|
|
89
|
+
"@types/node-fetch": "2.6.10",
|
|
90
|
+
"@types/react": "18.2.47",
|
|
91
|
+
"@types/react-dom": "18.2.18",
|
|
92
92
|
"@types/use-sync-external-store": "0.0.6",
|
|
93
|
-
"@typescript-eslint/eslint-plugin": "6.
|
|
94
|
-
"@typescript-eslint/parser": "6.
|
|
95
|
-
"@typescript-eslint/rule-tester": "6.
|
|
96
|
-
"@typescript-eslint/types": "6.
|
|
97
|
-
"@typescript-eslint/utils": "6.
|
|
98
|
-
"acorn": "8.11.
|
|
93
|
+
"@typescript-eslint/eslint-plugin": "6.18.0",
|
|
94
|
+
"@typescript-eslint/parser": "6.18.0",
|
|
95
|
+
"@typescript-eslint/rule-tester": "6.18.0",
|
|
96
|
+
"@typescript-eslint/types": "6.18.0",
|
|
97
|
+
"@typescript-eslint/utils": "6.18.0",
|
|
98
|
+
"acorn": "8.11.3",
|
|
99
99
|
"blob-polyfill": "7.0.20220408",
|
|
100
100
|
"bytes": "3.1.2",
|
|
101
101
|
"cross-fetch": "4.0.0",
|
|
102
|
-
"eslint": "8.
|
|
102
|
+
"eslint": "8.56.0",
|
|
103
103
|
"eslint-import-resolver-typescript": "3.6.1",
|
|
104
104
|
"eslint-plugin-import": "npm:@phryneas/eslint-plugin-import@2.27.5-pr.2813.2817.199971c",
|
|
105
105
|
"eslint-plugin-local-rules": "2.0.1",
|
|
@@ -108,18 +108,18 @@
|
|
|
108
108
|
"fetch-mock": "9.11.0",
|
|
109
109
|
"glob": "8.1.0",
|
|
110
110
|
"graphql": "16.8.1",
|
|
111
|
-
"graphql-ws": "5.14.
|
|
111
|
+
"graphql-ws": "5.14.3",
|
|
112
112
|
"jest": "29.7.0",
|
|
113
113
|
"jest-environment-jsdom": "29.7.0",
|
|
114
114
|
"jest-junit": "16.0.0",
|
|
115
115
|
"lodash": "4.17.21",
|
|
116
116
|
"patch-package": "8.0.0",
|
|
117
|
-
"prettier": "3.1.
|
|
117
|
+
"prettier": "3.1.1",
|
|
118
118
|
"react": "18.2.0",
|
|
119
119
|
"react-17": "npm:react@^17",
|
|
120
120
|
"react-dom": "18.2.0",
|
|
121
121
|
"react-dom-17": "npm:react-dom@^17",
|
|
122
|
-
"react-error-boundary": "4.0.
|
|
122
|
+
"react-error-boundary": "4.0.12",
|
|
123
123
|
"recast": "0.23.4",
|
|
124
124
|
"resolve": "1.22.8",
|
|
125
125
|
"rimraf": "5.0.5",
|
|
@@ -127,19 +127,19 @@
|
|
|
127
127
|
"rollup-plugin-cleanup": "3.2.1",
|
|
128
128
|
"rollup-plugin-terser": "7.0.2",
|
|
129
129
|
"rxjs": "7.8.1",
|
|
130
|
-
"size-limit": "11.0.
|
|
130
|
+
"size-limit": "11.0.1",
|
|
131
131
|
"subscriptions-transport-ws": "0.11.0",
|
|
132
|
-
"terser": "5.
|
|
132
|
+
"terser": "5.26.0",
|
|
133
133
|
"ts-api-utils": "1.0.3",
|
|
134
134
|
"ts-jest": "29.1.1",
|
|
135
135
|
"ts-jest-resolver": "2.0.1",
|
|
136
|
-
"ts-morph": "
|
|
137
|
-
"ts-node": "10.9.
|
|
136
|
+
"ts-morph": "21.0.1",
|
|
137
|
+
"ts-node": "10.9.2",
|
|
138
138
|
"typedoc": "0.25.0",
|
|
139
|
-
"typescript": "5.3.
|
|
139
|
+
"typescript": "5.3.3",
|
|
140
140
|
"wait-for-observables": "1.0.3",
|
|
141
|
-
"web-streams-polyfill": "3.2
|
|
142
|
-
"whatwg-fetch": "3.6.
|
|
141
|
+
"web-streams-polyfill": "3.3.2",
|
|
142
|
+
"whatwg-fetch": "3.6.20"
|
|
143
143
|
},
|
|
144
144
|
"publishConfig": {
|
|
145
145
|
"access": "public"
|
package/react/hooks/hooks.cjs
CHANGED
|
@@ -691,44 +691,6 @@ function useReactiveVar(rv) {
|
|
|
691
691
|
}, [rv]), rv, rv);
|
|
692
692
|
}
|
|
693
693
|
|
|
694
|
-
function useFragment(options) {
|
|
695
|
-
var cache = useApolloClient().cache;
|
|
696
|
-
var fragment = options.fragment, fragmentName = options.fragmentName, from = options.from, _a = options.optimistic, optimistic = _a === void 0 ? true : _a, rest = tslib.__rest(options, ["fragment", "fragmentName", "from", "optimistic"]);
|
|
697
|
-
var diffOptions = tslib.__assign(tslib.__assign({}, rest), { returnPartialData: true, id: typeof from === "string" ? from : cache.identify(from), query: cache["getFragmentDoc"](fragment, fragmentName), optimistic: optimistic });
|
|
698
|
-
var resultRef = React__namespace.useRef();
|
|
699
|
-
var latestDiff = cache.diff(diffOptions);
|
|
700
|
-
var getSnapshot = function () {
|
|
701
|
-
var latestDiffToResult = diffToResult(latestDiff);
|
|
702
|
-
return (resultRef.current &&
|
|
703
|
-
equality.equal(resultRef.current.data, latestDiffToResult.data)) ?
|
|
704
|
-
resultRef.current
|
|
705
|
-
: (resultRef.current = latestDiffToResult);
|
|
706
|
-
};
|
|
707
|
-
return useSyncExternalStore(function (forceUpdate) {
|
|
708
|
-
var lastTimeout = 0;
|
|
709
|
-
var unsubcribe = cache.watch(tslib.__assign(tslib.__assign({}, diffOptions), { immediate: true, callback: function (diff) {
|
|
710
|
-
if (!equality.equal(diff, latestDiff)) {
|
|
711
|
-
resultRef.current = diffToResult((latestDiff = diff));
|
|
712
|
-
lastTimeout = setTimeout(forceUpdate);
|
|
713
|
-
}
|
|
714
|
-
} }));
|
|
715
|
-
return function () {
|
|
716
|
-
unsubcribe();
|
|
717
|
-
clearTimeout(lastTimeout);
|
|
718
|
-
};
|
|
719
|
-
}, getSnapshot, getSnapshot);
|
|
720
|
-
}
|
|
721
|
-
function diffToResult(diff) {
|
|
722
|
-
var result = {
|
|
723
|
-
data: diff.result,
|
|
724
|
-
complete: !!diff.complete,
|
|
725
|
-
};
|
|
726
|
-
if (diff.missing) {
|
|
727
|
-
result.missing = utilities.mergeDeepArray(diff.missing.map(function (error) { return error.missing; }));
|
|
728
|
-
}
|
|
729
|
-
return result;
|
|
730
|
-
}
|
|
731
|
-
|
|
732
694
|
function useDeepMemo(memoFn, deps) {
|
|
733
695
|
var ref = React__namespace.useRef();
|
|
734
696
|
if (!ref.current || !equality.equal(ref.current.deps, deps)) {
|
|
@@ -737,6 +699,15 @@ function useDeepMemo(memoFn, deps) {
|
|
|
737
699
|
return ref.current.value;
|
|
738
700
|
}
|
|
739
701
|
|
|
702
|
+
var INIT = {};
|
|
703
|
+
function useLazyRef(getInitialValue) {
|
|
704
|
+
var ref = React__namespace.useRef(INIT);
|
|
705
|
+
if (ref.current === INIT) {
|
|
706
|
+
ref.current = getInitialValue();
|
|
707
|
+
}
|
|
708
|
+
return ref;
|
|
709
|
+
}
|
|
710
|
+
|
|
740
711
|
var useKey = "use";
|
|
741
712
|
var realHook = React__namespace[useKey];
|
|
742
713
|
var __use = realHook ||
|
|
@@ -752,6 +723,42 @@ var __use = realHook ||
|
|
|
752
723
|
}
|
|
753
724
|
};
|
|
754
725
|
|
|
726
|
+
function useFragment(options) {
|
|
727
|
+
var cache = useApolloClient().cache;
|
|
728
|
+
var diffOptions = useDeepMemo(function () {
|
|
729
|
+
var fragment = options.fragment, fragmentName = options.fragmentName, from = options.from, _a = options.optimistic, optimistic = _a === void 0 ? true : _a, rest = tslib.__rest(options, ["fragment", "fragmentName", "from", "optimistic"]);
|
|
730
|
+
return tslib.__assign(tslib.__assign({}, rest), { returnPartialData: true, id: typeof from === "string" ? from : cache.identify(from), query: cache["getFragmentDoc"](fragment, fragmentName), optimistic: optimistic });
|
|
731
|
+
}, [options]);
|
|
732
|
+
var resultRef = useLazyRef(function () {
|
|
733
|
+
return diffToResult(cache.diff(diffOptions));
|
|
734
|
+
});
|
|
735
|
+
var getSnapshot = React__namespace.useCallback(function () { return resultRef.current; }, []);
|
|
736
|
+
return useSyncExternalStore(React__namespace.useCallback(function (forceUpdate) {
|
|
737
|
+
var lastTimeout = 0;
|
|
738
|
+
var unsubscribe = cache.watch(tslib.__assign(tslib.__assign({}, diffOptions), { immediate: true, callback: function (diff) {
|
|
739
|
+
if (!equality.equal(diff.result, resultRef.current.data)) {
|
|
740
|
+
resultRef.current = diffToResult(diff);
|
|
741
|
+
clearTimeout(lastTimeout);
|
|
742
|
+
lastTimeout = setTimeout(forceUpdate);
|
|
743
|
+
}
|
|
744
|
+
} }));
|
|
745
|
+
return function () {
|
|
746
|
+
unsubscribe();
|
|
747
|
+
clearTimeout(lastTimeout);
|
|
748
|
+
};
|
|
749
|
+
}, [cache, diffOptions]), getSnapshot, getSnapshot);
|
|
750
|
+
}
|
|
751
|
+
function diffToResult(diff) {
|
|
752
|
+
var result = {
|
|
753
|
+
data: diff.result,
|
|
754
|
+
complete: !!diff.complete,
|
|
755
|
+
};
|
|
756
|
+
if (diff.missing) {
|
|
757
|
+
result.missing = utilities.mergeDeepArray(diff.missing.map(function (error) { return error.missing; }));
|
|
758
|
+
}
|
|
759
|
+
return result;
|
|
760
|
+
}
|
|
761
|
+
|
|
755
762
|
var QUERY_REFERENCE_SYMBOL = Symbol();
|
|
756
763
|
function wrapQueryRef(internalQueryRef) {
|
|
757
764
|
var _a;
|