@apollo/client 3.7.13 → 3.7.15

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.
Files changed (39) hide show
  1. package/apollo-client.cjs +29 -18
  2. package/apollo-client.cjs.map +1 -1
  3. package/apollo-client.min.cjs +1 -1
  4. package/cache/cache.cjs +1 -1
  5. package/cache/cache.cjs.map +1 -1
  6. package/cache/cache.cjs.native.js +1 -1
  7. package/cache/inmemory/policies.js +1 -1
  8. package/cache/inmemory/policies.js.map +1 -1
  9. package/core/core.cjs +1 -1
  10. package/core/core.cjs.map +1 -1
  11. package/core/core.cjs.native.js +1 -1
  12. package/invariantErrorCodes.js +1 -1
  13. package/link/http/http.cjs +14 -13
  14. package/link/http/http.cjs.map +1 -1
  15. package/link/http/http.cjs.native.js +14 -13
  16. package/link/http/parseAndCheckHttpResponse.d.ts.map +1 -1
  17. package/link/http/parseAndCheckHttpResponse.js +14 -13
  18. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  19. package/link/persisted-queries/index.d.ts.map +1 -1
  20. package/link/persisted-queries/index.js +7 -3
  21. package/link/persisted-queries/index.js.map +1 -1
  22. package/link/persisted-queries/persisted-queries.cjs +7 -3
  23. package/link/persisted-queries/persisted-queries.cjs.map +1 -1
  24. package/link/persisted-queries/persisted-queries.cjs.native.js +7 -3
  25. package/link/utils/throwServerError.d.ts +1 -1
  26. package/link/utils/throwServerError.d.ts.map +1 -1
  27. package/link/utils/throwServerError.js.map +1 -1
  28. package/package.json +22 -19
  29. package/react/hooks/useFragment.d.ts +2 -1
  30. package/react/hooks/useFragment.d.ts.map +1 -1
  31. package/react/hooks/useFragment.js.map +1 -1
  32. package/testing/react/MockedProvider.d.ts +1 -1
  33. package/utilities/graphql/storeUtils.d.ts.map +1 -1
  34. package/utilities/graphql/storeUtils.js +13 -3
  35. package/utilities/graphql/storeUtils.js.map +1 -1
  36. package/utilities/utilities.cjs +13 -3
  37. package/utilities/utilities.cjs.map +1 -1
  38. package/utilities/utilities.cjs.native.js +13 -3
  39. package/version.js +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/link/persisted-queries/index.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAOhC,OAAO,EAAE,UAAU,EAAa,MAAM,SAAS,CAAC;AAChD,OAAO,EACL,UAAU,EAGV,OAAO,EACP,eAAe,GAChB,MAAM,iBAAiB,CAAC;AAIzB,MAAM,CAAC,IAAM,OAAO,GAAG,CAAC,CAAC;AAYzB,MAAM,KAAW,kBAAkB,CAiBlC;AAjBD,WAAiB,kBAAkB;IAIhC,CAAC;IAKD,CAAC;IAKD,CAAC;AAGJ,CAAC,EAjBgB,kBAAkB,KAAlB,kBAAkB,QAiBlC;AAED,SAAS,sBAAsB,CAC7B,aAAuD;IAEvD,IAAM,SAAS,GAA2B,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC9D,IAAI,eAAe,CAAC,aAAa,CAAC,EAAE;QAClC,aAAa,CAAC,OAAO,CAAC,UAAA,KAAK,IAAI,OAAA,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,KAAK,EAAhC,CAAgC,CAAC,CAAC;KAClE;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,IAAM,cAAc,GAAG;IACrB,OAAO,EAAE,UAAC,EAA2C;YAAzC,aAAa,mBAAA,EAAE,SAAS,eAAA;QAClC,IAAM,aAAa,GAAG,sBAAsB,CAAC,aAAa,CAAC,CAAC;QAG5D,IAAI,aAAa,CAAC,0BAA0B,EAAE;YAC5C,OAAO,IAAI,CAAC;SACb;QAED,IAAI,aAAa,CAAC,sBAAsB,EAAE;YACxC,OAAO,KAAK,CAAC;SACd;QAEO,IAAA,QAAQ,GAAK,SAAS,CAAC,UAAU,EAAE,SAA3B,CAA4B;QAG5C,I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from '../../utilities/globals';\n\nimport { print } from 'graphql';\nimport {\n DocumentNode,\n ExecutionResult,\n GraphQLError,\n} from 'graphql';\n\nimport { ApolloLink, Operation } from '../core';\nimport {\n Observable,\n Observer,\n ObservableSubscription,\n compact,\n isNonEmptyArray,\n} from '../../utilities';\nimport { NetworkError } from '../../errors';\nimport { ServerError } from '../utils';\n\nexport const VERSION = 1;\n\nexport interface ErrorResponse {\n graphQLErrors?: readonly GraphQLError[];\n networkError?: NetworkError;\n response?: ExecutionResult;\n operation: Operation;\n}\n\ntype SHA256Function = (...args: any[]) => string | PromiseLike<string>;\ntype GenerateHashFunction = (document: DocumentNode) => string | PromiseLike<string>;\n\nexport namespace PersistedQueryLink {\n interface BaseOptions {\n disable?: (error: ErrorResponse) => boolean;\n useGETForHashedQueries?: boolean;\n };\n\n interface SHA256Options extends BaseOptions {\n sha256: SHA256Function;\n generateHash?: never;\n };\n\n interface GenerateHashOptions extends BaseOptions {\n sha256?: never;\n generateHash: GenerateHashFunction;\n };\n\n export type Options = SHA256Options | GenerateHashOptions;\n}\n\nfunction collectErrorsByMessage<TError extends Error>(\n graphQLErrors: TError[] | readonly TError[] | undefined,\n): Record<string, TError> {\n const collected: Record<string, TError> = Object.create(null);\n if (isNonEmptyArray(graphQLErrors)) {\n graphQLErrors.forEach(error => collected[error.message] = error);\n }\n return collected;\n}\n\nconst defaultOptions = {\n disable: ({ graphQLErrors, operation }: ErrorResponse) => {\n const errorMessages = collectErrorsByMessage(graphQLErrors);\n\n // if the server doesn't support persisted queries, don't try anymore\n if (errorMessages.PersistedQueryNotSupported) {\n return true;\n }\n\n if (errorMessages.PersistedQueryNotFound) {\n return false;\n }\n\n const { response } = operation.getContext();\n // if the server responds with bad request\n // Apollo Server responds with 400 for GET and 500 for POST when no query is found\n if (\n response &&\n response.status &&\n (response.status === 400 || response.status === 500)\n ) {\n return true;\n }\n\n return false;\n },\n useGETForHashedQueries: false,\n};\n\nfunction operationDefinesMutation(operation: Operation) {\n return operation.query.definitions.some(\n d => d.kind === 'OperationDefinition' && d.operation === 'mutation');\n}\n\nexport const createPersistedQueryLink = (\n options: PersistedQueryLink.Options,\n) => {\n const hashesByQuery = new WeakMap<\n DocumentNode,\n Promise<string>\n >();\n // Ensure a SHA-256 hash function is provided, if a custom hash\n // generation function is not provided. We don't supply a SHA-256 hash\n // function by default, to avoid forcing one as a dependency. Developers\n // should pick the most appropriate SHA-256 function (sync or async) for\n // their needs/environment, or provide a fully custom hash generation\n // function (via the `generateHash` option) if they want to handle\n // hashing with something other than SHA-256.\n invariant(\n options && (\n typeof options.sha256 === 'function' ||\n typeof options.generateHash === 'function'\n ),\n 'Missing/invalid \"sha256\" or \"generateHash\" function. Please ' +\n 'configure one using the \"createPersistedQueryLink(options)\" options ' +\n 'parameter.'\n );\n\n const {\n sha256,\n // If both a `sha256` and `generateHash` option are provided, the\n // `sha256` option will be ignored. Developers can configure and\n // use any hashing approach they want in a custom `generateHash`\n // function; they aren't limited to SHA-256.\n generateHash = (query: DocumentNode) =>\n Promise.resolve<string>(sha256!(print(query))),\n disable,\n useGETForHashedQueries\n } = compact(defaultOptions, options);\n\n let supportsPersistedQueries = true;\n\n const getHashPromise = (query: DocumentNode) =>\n new Promise<string>(resolve => resolve(generateHash(query)));\n\n function getQueryHash(query: DocumentNode): Promise<string> {\n if (!query || typeof query !== 'object') {\n // If the query is not an object, we won't be able to store its hash as\n // a property of query[hashesKey], so we let generateHash(query) decide\n // what to do with the bogus query.\n return getHashPromise(query);\n }\n let hash = hashesByQuery.get(query)!;\n if (!hash) hashesByQuery.set(query, hash = getHashPromise(query));\n return hash;\n }\n\n return new ApolloLink((operation, forward) => {\n invariant(\n forward,\n 'PersistedQueryLink cannot be the last link in the chain.'\n );\n\n const { query } = operation;\n\n return new Observable((observer: Observer<ExecutionResult>) => {\n let subscription: ObservableSubscription;\n let retried = false;\n let originalFetchOptions: any;\n let setFetchOptions = false;\n const retry = (\n {\n response,\n networkError,\n }: { response?: ExecutionResult; networkError?: ServerError },\n cb: () => void,\n ) => {\n if (!retried && ((response && response.errors) || networkError)) {\n retried = true;\n\n const graphQLErrors: GraphQLError[] = [];\n\n const responseErrors = response && response.errors;\n if (isNonEmptyArray(responseErrors)) {\n graphQLErrors.push(...responseErrors);\n }\n\n // Network errors can return GraphQL errors on for example a 403\n const networkErrors =\n networkError &&\n networkError.result &&\n networkError.result.errors as GraphQLError[];\n if (isNonEmptyArray(networkErrors)) {\n graphQLErrors.push(...networkErrors);\n }\n\n const disablePayload = {\n response,\n networkError,\n operation,\n graphQLErrors: isNonEmptyArray(graphQLErrors) ? graphQLErrors : void 0,\n };\n\n // if the server doesn't support persisted queries, don't try anymore\n supportsPersistedQueries = !disable(disablePayload);\n\n // if its not found, we can try it again, otherwise just report the error\n if (\n collectErrorsByMessage(graphQLErrors).PersistedQueryNotFound ||\n !supportsPersistedQueries\n ) {\n // need to recall the link chain\n if (subscription) subscription.unsubscribe();\n // actually send the query this time\n operation.setContext({\n http: {\n includeQuery: true,\n includeExtensions: supportsPersistedQueries,\n },\n fetchOptions: {\n // Since we're including the full query, which may be\n // large, we should send it in the body of a POST request.\n // See issue #7456.\n method: 'POST',\n },\n });\n if (setFetchOptions) {\n operation.setContext({ fetchOptions: originalFetchOptions });\n }\n subscription = forward(operation).subscribe(handler);\n\n return;\n }\n }\n cb();\n };\n const handler = {\n next: (response: ExecutionResult) => {\n retry({ response }, () => observer.next!(response));\n },\n error: (networkError: ServerError) => {\n retry({ networkError }, () => observer.error!(networkError));\n },\n complete: observer.complete!.bind(observer),\n };\n\n // don't send the query the first time\n operation.setContext({\n http: {\n includeQuery: !supportsPersistedQueries,\n includeExtensions: supportsPersistedQueries,\n },\n });\n\n // If requested, set method to GET if there are no mutations. Remember the\n // original fetchOptions so we can restore them if we fall back to a\n // non-hashed request.\n if (\n useGETForHashedQueries &&\n supportsPersistedQueries &&\n !operationDefinesMutation(operation)\n ) {\n operation.setContext(\n ({ fetchOptions = {} }: { fetchOptions: Record<string, any> }) => {\n originalFetchOptions = fetchOptions;\n return {\n fetchOptions: {\n ...fetchOptions,\n method: 'GET',\n },\n };\n },\n );\n setFetchOptions = true;\n }\n\n if (supportsPersistedQueries) {\n getQueryHash(query).then((sha256Hash) => {\n operation.extensions.persistedQuery = {\n version: VERSION,\n sha256Hash,\n };\n subscription = forward(operation).subscribe(handler);\n }).catch(observer.error!.bind(observer));;\n } else {\n subscription = forward(operation).subscribe(handler);\n }\n\n return () => {\n if (subscription) subscription.unsubscribe();\n };\n });\n });\n};\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/link/persisted-queries/index.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAOhC,OAAO,EAAE,UAAU,EAAa,MAAM,SAAS,CAAC;AAChD,OAAO,EACL,UAAU,EAGV,OAAO,EACP,eAAe,GAChB,MAAM,iBAAiB,CAAC;AAIzB,MAAM,CAAC,IAAM,OAAO,GAAG,CAAC,CAAC;AAYzB,MAAM,KAAW,kBAAkB,CAiBlC;AAjBD,WAAiB,kBAAkB;IAIhC,CAAC;IAKD,CAAC;IAKD,CAAC;AAGJ,CAAC,EAjBgB,kBAAkB,KAAlB,kBAAkB,QAiBlC;AAED,SAAS,sBAAsB,CAC7B,aAAuD;IAEvD,IAAM,SAAS,GAA2B,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC9D,IAAI,eAAe,CAAC,aAAa,CAAC,EAAE;QAClC,aAAa,CAAC,OAAO,CAAC,UAAA,KAAK,IAAI,OAAA,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,KAAK,EAAhC,CAAgC,CAAC,CAAC;KAClE;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,IAAM,cAAc,GAAG;IACrB,OAAO,EAAE,UAAC,EAA2C;YAAzC,aAAa,mBAAA,EAAE,SAAS,eAAA;QAClC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AC,CAAC;gBACvD,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;gBAAA,CAAC;aAC3C;iBAAM;gBACL,YAAY,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;aACtD;YAED,OAAO;gBACL,IAAI,YAAY;oBAAE,YAAY,CAAC,WAAW,EAAE,CAAC;YAC/C,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["import { invariant } from '../../utilities/globals';\n\nimport { print } from 'graphql';\nimport {\n DocumentNode,\n ExecutionResult,\n GraphQLError,\n} from 'graphql';\n\nimport { ApolloLink, Operation } from '../core';\nimport {\n Observable,\n Observer,\n ObservableSubscription,\n compact,\n isNonEmptyArray,\n} from '../../utilities';\nimport { NetworkError } from '../../errors';\nimport { ServerError } from '../utils';\n\nexport const VERSION = 1;\n\nexport interface ErrorResponse {\n graphQLErrors?: readonly GraphQLError[];\n networkError?: NetworkError;\n response?: ExecutionResult;\n operation: Operation;\n}\n\ntype SHA256Function = (...args: any[]) => string | PromiseLike<string>;\ntype GenerateHashFunction = (document: DocumentNode) => string | PromiseLike<string>;\n\nexport namespace PersistedQueryLink {\n interface BaseOptions {\n disable?: (error: ErrorResponse) => boolean;\n useGETForHashedQueries?: boolean;\n };\n\n interface SHA256Options extends BaseOptions {\n sha256: SHA256Function;\n generateHash?: never;\n };\n\n interface GenerateHashOptions extends BaseOptions {\n sha256?: never;\n generateHash: GenerateHashFunction;\n };\n\n export type Options = SHA256Options | GenerateHashOptions;\n}\n\nfunction collectErrorsByMessage<TError extends Error>(\n graphQLErrors: TError[] | readonly TError[] | undefined,\n): Record<string, TError> {\n const collected: Record<string, TError> = Object.create(null);\n if (isNonEmptyArray(graphQLErrors)) {\n graphQLErrors.forEach(error => collected[error.message] = error);\n }\n return collected;\n}\n\nconst defaultOptions = {\n disable: ({ graphQLErrors, operation }: ErrorResponse) => {\n const errorMessages = collectErrorsByMessage(graphQLErrors);\n\n // if the server doesn't support persisted queries, don't try anymore\n if (errorMessages.PersistedQueryNotSupported) {\n return true;\n }\n\n if (errorMessages.PersistedQueryNotFound) {\n return false;\n }\n\n const { response } = operation.getContext();\n // if the server responds with bad request\n // Apollo Server responds with 400 for GET and 500 for POST when no query is found\n if (\n response &&\n response.status &&\n (response.status === 400 || response.status === 500)\n ) {\n return true;\n }\n\n return false;\n },\n useGETForHashedQueries: false,\n};\n\nfunction operationDefinesMutation(operation: Operation) {\n return operation.query.definitions.some(\n d => d.kind === 'OperationDefinition' && d.operation === 'mutation');\n}\n\nexport const createPersistedQueryLink = (\n options: PersistedQueryLink.Options,\n) => {\n const hashesByQuery = new WeakMap<\n DocumentNode,\n Promise<string>\n >();\n // Ensure a SHA-256 hash function is provided, if a custom hash\n // generation function is not provided. We don't supply a SHA-256 hash\n // function by default, to avoid forcing one as a dependency. Developers\n // should pick the most appropriate SHA-256 function (sync or async) for\n // their needs/environment, or provide a fully custom hash generation\n // function (via the `generateHash` option) if they want to handle\n // hashing with something other than SHA-256.\n invariant(\n options && (\n typeof options.sha256 === 'function' ||\n typeof options.generateHash === 'function'\n ),\n 'Missing/invalid \"sha256\" or \"generateHash\" function. Please ' +\n 'configure one using the \"createPersistedQueryLink(options)\" options ' +\n 'parameter.'\n );\n\n const {\n sha256,\n // If both a `sha256` and `generateHash` option are provided, the\n // `sha256` option will be ignored. Developers can configure and\n // use any hashing approach they want in a custom `generateHash`\n // function; they aren't limited to SHA-256.\n generateHash = (query: DocumentNode) =>\n Promise.resolve<string>(sha256!(print(query))),\n disable,\n useGETForHashedQueries\n } = compact(defaultOptions, options);\n\n let supportsPersistedQueries = true;\n\n const getHashPromise = (query: DocumentNode) =>\n new Promise<string>(resolve => resolve(generateHash(query)));\n\n function getQueryHash(query: DocumentNode): Promise<string> {\n if (!query || typeof query !== 'object') {\n // If the query is not an object, we won't be able to store its hash as\n // a property of query[hashesKey], so we let generateHash(query) decide\n // what to do with the bogus query.\n return getHashPromise(query);\n }\n let hash = hashesByQuery.get(query)!;\n if (!hash) hashesByQuery.set(query, hash = getHashPromise(query));\n return hash;\n }\n\n return new ApolloLink((operation, forward) => {\n invariant(\n forward,\n 'PersistedQueryLink cannot be the last link in the chain.'\n );\n\n const { query } = operation;\n\n return new Observable((observer: Observer<ExecutionResult>) => {\n let subscription: ObservableSubscription;\n let retried = false;\n let originalFetchOptions: any;\n let setFetchOptions = false;\n const retry = (\n {\n response,\n networkError,\n }: { response?: ExecutionResult; networkError?: ServerError },\n cb: () => void,\n ) => {\n if (!retried && ((response && response.errors) || networkError)) {\n retried = true;\n\n const graphQLErrors: GraphQLError[] = [];\n\n const responseErrors = response && response.errors;\n if (isNonEmptyArray(responseErrors)) {\n graphQLErrors.push(...responseErrors);\n }\n\n // Network errors can return GraphQL errors on for example a 403\n let networkErrors;\n if (typeof networkError?.result !== 'string') {\n networkErrors =\n networkError &&\n networkError.result &&\n networkError.result.errors as GraphQLError[];\n }\n if (isNonEmptyArray(networkErrors)) {\n graphQLErrors.push(...networkErrors);\n }\n\n const disablePayload = {\n response,\n networkError,\n operation,\n graphQLErrors: isNonEmptyArray(graphQLErrors) ? graphQLErrors : void 0,\n };\n\n // if the server doesn't support persisted queries, don't try anymore\n supportsPersistedQueries = !disable(disablePayload);\n\n // if its not found, we can try it again, otherwise just report the error\n if (\n collectErrorsByMessage(graphQLErrors).PersistedQueryNotFound ||\n !supportsPersistedQueries\n ) {\n // need to recall the link chain\n if (subscription) subscription.unsubscribe();\n // actually send the query this time\n operation.setContext({\n http: {\n includeQuery: true,\n includeExtensions: supportsPersistedQueries,\n },\n fetchOptions: {\n // Since we're including the full query, which may be\n // large, we should send it in the body of a POST request.\n // See issue #7456.\n method: 'POST',\n },\n });\n if (setFetchOptions) {\n operation.setContext({ fetchOptions: originalFetchOptions });\n }\n subscription = forward(operation).subscribe(handler);\n\n return;\n }\n }\n cb();\n };\n const handler = {\n next: (response: ExecutionResult) => {\n retry({ response }, () => observer.next!(response));\n },\n error: (networkError: ServerError) => {\n retry({ networkError }, () => observer.error!(networkError));\n },\n complete: observer.complete!.bind(observer),\n };\n\n // don't send the query the first time\n operation.setContext({\n http: {\n includeQuery: !supportsPersistedQueries,\n includeExtensions: supportsPersistedQueries,\n },\n });\n\n // If requested, set method to GET if there are no mutations. Remember the\n // original fetchOptions so we can restore them if we fall back to a\n // non-hashed request.\n if (\n useGETForHashedQueries &&\n supportsPersistedQueries &&\n !operationDefinesMutation(operation)\n ) {\n operation.setContext(\n ({ fetchOptions = {} }: { fetchOptions: Record<string, any> }) => {\n originalFetchOptions = fetchOptions;\n return {\n fetchOptions: {\n ...fetchOptions,\n method: 'GET',\n },\n };\n },\n );\n setFetchOptions = true;\n }\n\n if (supportsPersistedQueries) {\n getQueryHash(query).then((sha256Hash) => {\n operation.extensions.persistedQuery = {\n version: VERSION,\n sha256Hash,\n };\n subscription = forward(operation).subscribe(handler);\n }).catch(observer.error!.bind(observer));;\n } else {\n subscription = forward(operation).subscribe(handler);\n }\n\n return () => {\n if (subscription) subscription.unsubscribe();\n };\n });\n });\n};\n"]}
@@ -82,9 +82,13 @@ var createPersistedQueryLink = function (options) {
82
82
  if (utilities.isNonEmptyArray(responseErrors)) {
83
83
  graphQLErrors.push.apply(graphQLErrors, responseErrors);
84
84
  }
85
- var networkErrors = networkError &&
86
- networkError.result &&
87
- networkError.result.errors;
85
+ var networkErrors = void 0;
86
+ if (typeof (networkError === null || networkError === void 0 ? void 0 : networkError.result) !== 'string') {
87
+ networkErrors =
88
+ networkError &&
89
+ networkError.result &&
90
+ networkError.result.errors;
91
+ }
88
92
  if (utilities.isNonEmptyArray(networkErrors)) {
89
93
  graphQLErrors.push.apply(graphQLErrors, networkErrors);
90
94
  }
@@ -1 +1 @@
1
- {"version":3,"file":"persisted-queries.cjs","sources":["index.js"],"sourcesContent":["import { __assign } from \"tslib\";\nimport { invariant } from '../../utilities/globals';\nimport { print } from 'graphql';\nimport { ApolloLink } from '../core';\nimport { Observable, compact, isNonEmptyArray, } from '../../utilities';\nexport var VERSION = 1;\nexport var PersistedQueryLink;\n(function (PersistedQueryLink) {\n ;\n ;\n ;\n})(PersistedQueryLink || (PersistedQueryLink = {}));\nfunction collectErrorsByMessage(graphQLErrors) {\n var collected = Object.create(null);\n if (isNonEmptyArray(graphQLErrors)) {\n graphQLErrors.forEach(function (error) { return collected[error.message] = error; });\n }\n return collected;\n}\nvar defaultOptions = {\n disable: function (_a) {\n var graphQLErrors = _a.graphQLErrors, operation = _a.operation;\n var errorMessages = collectErrorsByMessage(graphQLErrors);\n if (errorMessages.PersistedQueryNotSupported) {\n return true;\n }\n if (errorMessages.PersistedQueryNotFound) {\n return false;\n }\n var response = operation.getContext().response;\n if (response &&\n response.status &&\n (response.status === 400 || response.status === 500)) {\n return true;\n }\n return false;\n },\n useGETForHashedQueries: false,\n};\nfunction operationDefinesMutation(operation) {\n return operation.query.definitions.some(function (d) { return d.kind === 'OperationDefinition' && d.operation === 'mutation'; });\n}\nexport var createPersistedQueryLink = function (options) {\n var hashesByQuery = new WeakMap();\n __DEV__ ? invariant(options && (typeof options.sha256 === 'function' ||\n typeof options.generateHash === 'function'), 'Missing/invalid \"sha256\" or \"generateHash\" function. Please ' +\n 'configure one using the \"createPersistedQueryLink(options)\" options ' +\n 'parameter.') : invariant(options && (typeof options.sha256 === 'function' ||\n typeof options.generateHash === 'function'), 25);\n var _a = compact(defaultOptions, options), sha256 = _a.sha256, _b = _a.generateHash, generateHash = _b === void 0 ? function (query) {\n return Promise.resolve(sha256(print(query)));\n } : _b, disable = _a.disable, useGETForHashedQueries = _a.useGETForHashedQueries;\n var supportsPersistedQueries = true;\n var getHashPromise = function (query) {\n return new Promise(function (resolve) { return resolve(generateHash(query)); });\n };\n function getQueryHash(query) {\n if (!query || typeof query !== 'object') {\n return getHashPromise(query);\n }\n var hash = hashesByQuery.get(query);\n if (!hash)\n hashesByQuery.set(query, hash = getHashPromise(query));\n return hash;\n }\n return new ApolloLink(function (operation, forward) {\n __DEV__ ? invariant(forward, 'PersistedQueryLink cannot be the last link in the chain.') : invariant(forward, 26);\n var query = operation.query;\n return new Observable(function (observer) {\n var subscription;\n var retried = false;\n var originalFetchOptions;\n var setFetchOptions = false;\n var retry = function (_a, cb) {\n var response = _a.response, networkError = _a.networkError;\n if (!retried && ((response && response.errors) || networkError)) {\n retried = true;\n var graphQLErrors = [];\n var responseErrors = response && response.errors;\n if (isNonEmptyArray(responseErrors)) {\n graphQLErrors.push.apply(graphQLErrors, responseErrors);\n }\n var networkErrors = networkError &&\n networkError.result &&\n networkError.result.errors;\n if (isNonEmptyArray(networkErrors)) {\n graphQLErrors.push.apply(graphQLErrors, networkErrors);\n }\n var disablePayload = {\n response: response,\n networkError: networkError,\n operation: operation,\n graphQLErrors: isNonEmptyArray(graphQLErrors) ? graphQLErrors : void 0,\n };\n supportsPersistedQueries = !disable(disablePayload);\n if (collectErrorsByMessage(graphQLErrors).PersistedQueryNotFound ||\n !supportsPersistedQueries) {\n if (subscription)\n subscription.unsubscribe();\n operation.setContext({\n http: {\n includeQuery: true,\n includeExtensions: supportsPersistedQueries,\n },\n fetchOptions: {\n method: 'POST',\n },\n });\n if (setFetchOptions) {\n operation.setContext({ fetchOptions: originalFetchOptions });\n }\n subscription = forward(operation).subscribe(handler);\n return;\n }\n }\n cb();\n };\n var handler = {\n next: function (response) {\n retry({ response: response }, function () { return observer.next(response); });\n },\n error: function (networkError) {\n retry({ networkError: networkError }, function () { return observer.error(networkError); });\n },\n complete: observer.complete.bind(observer),\n };\n operation.setContext({\n http: {\n includeQuery: !supportsPersistedQueries,\n includeExtensions: supportsPersistedQueries,\n },\n });\n if (useGETForHashedQueries &&\n supportsPersistedQueries &&\n !operationDefinesMutation(operation)) {\n operation.setContext(function (_a) {\n var _b = _a.fetchOptions, fetchOptions = _b === void 0 ? {} : _b;\n originalFetchOptions = fetchOptions;\n return {\n fetchOptions: __assign(__assign({}, fetchOptions), { method: 'GET' }),\n };\n });\n setFetchOptions = true;\n }\n if (supportsPersistedQueries) {\n getQueryHash(query).then(function (sha256Hash) {\n operation.extensions.persistedQuery = {\n version: VERSION,\n sha256Hash: sha256Hash,\n };\n subscription = forward(operation).subscribe(handler);\n }).catch(observer.error.bind(observer));\n ;\n }\n else {\n subscription = forward(operation).subscribe(handler);\n }\n return function () {\n if (subscription)\n subscription.unsubscribe();\n };\n });\n });\n};\n//# sourceMappingURL=index.js.map"],"names":["PersistedQueryLink","isNonEmptyArray","invariant","compact","print","ApolloLink","Observable","__assign"],"mappings":";;;;;;;;;;AAKU,IAAC,OAAO,GAAG,EAAE;AACZA,oCAAmB;AAC9B,CAAC,UAAU,kBAAkB,EAAE;AAI/B,CAAC,EAAEA,0BAAkB,KAAKA,0BAAkB,GAAG,EAAE,CAAC,CAAC,CAAC;AACpD,SAAS,sBAAsB,CAAC,aAAa,EAAE;AAC/C,IAAI,IAAI,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AACxC,IAAI,IAAIC,yBAAe,CAAC,aAAa,CAAC,EAAE;AACxC,QAAQ,aAAa,CAAC,OAAO,CAAC,UAAU,KAAK,EAAE,EAAE,OAAO,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC;AAC7F,KAAK;AACL,IAAI,OAAO,SAAS,CAAC;AACrB,CAAC;AACD,IAAI,cAAc,GAAG;AACrB,IAAI,OAAO,EAAE,UAAU,EAAE,EAAE;AAC3B,QAAQ,IAAI,aAAa,GAAG,EAAE,CAAC,aAAa,EAAE,SAAS,GAAG,EAAE,CAAC,SAAS,CAAC;AACvE,QAAQ,IAAI,aAAa,GAAG,sBAAsB,CAAC,aAAa,CAAC,CAAC;AAClE,QAAQ,IAAI,aAAa,CAAC,0BAA0B,EAAE;AACtD,YAAY,OAAO,IAAI,CAAC;AACxB,SAAS;AACT,QAAQ,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C,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;AAExD,aAAa;AACb,iBAAiB;AACjB,gBAAgB,YAAY,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;AACrE,aAAa;AACb,YAAY,OAAO,YAAY;AAC/B,gBAAgB,IAAI,YAAY;AAChC,oBAAoB,YAAY,CAAC,WAAW,EAAE,CAAC;AAC/C,aAAa,CAAC;AACd,SAAS,CAAC,CAAC;AACX,KAAK,CAAC,CAAC;AACP;;;;;"}
1
+ {"version":3,"file":"persisted-queries.cjs","sources":["index.js"],"sourcesContent":["import { __assign } from \"tslib\";\nimport { invariant } from '../../utilities/globals';\nimport { print } from 'graphql';\nimport { ApolloLink } from '../core';\nimport { Observable, compact, isNonEmptyArray, } from '../../utilities';\nexport var VERSION = 1;\nexport var PersistedQueryLink;\n(function (PersistedQueryLink) {\n ;\n ;\n ;\n})(PersistedQueryLink || (PersistedQueryLink = {}));\nfunction collectErrorsByMessage(graphQLErrors) {\n var collected = Object.create(null);\n if (isNonEmptyArray(graphQLErrors)) {\n graphQLErrors.forEach(function (error) { return collected[error.message] = error; });\n }\n return collected;\n}\nvar defaultOptions = {\n disable: function (_a) {\n var graphQLErrors = _a.graphQLErrors, operation = _a.operation;\n var errorMessages = collectErrorsByMessage(graphQLErrors);\n if (errorMessages.PersistedQueryNotSupported) {\n return true;\n }\n if (errorMessages.PersistedQueryNotFound) {\n return false;\n }\n var response = operation.getContext().response;\n if (response &&\n response.status &&\n (response.status === 400 || response.status === 500)) {\n return true;\n }\n return false;\n },\n useGETForHashedQueries: false,\n};\nfunction operationDefinesMutation(operation) {\n return operation.query.definitions.some(function (d) { return d.kind === 'OperationDefinition' && d.operation === 'mutation'; });\n}\nexport var createPersistedQueryLink = function (options) {\n var hashesByQuery = new WeakMap();\n __DEV__ ? invariant(options && (typeof options.sha256 === 'function' ||\n typeof options.generateHash === 'function'), 'Missing/invalid \"sha256\" or \"generateHash\" function. Please ' +\n 'configure one using the \"createPersistedQueryLink(options)\" options ' +\n 'parameter.') : invariant(options && (typeof options.sha256 === 'function' ||\n typeof options.generateHash === 'function'), 25);\n var _a = compact(defaultOptions, options), sha256 = _a.sha256, _b = _a.generateHash, generateHash = _b === void 0 ? function (query) {\n return Promise.resolve(sha256(print(query)));\n } : _b, disable = _a.disable, useGETForHashedQueries = _a.useGETForHashedQueries;\n var supportsPersistedQueries = true;\n var getHashPromise = function (query) {\n return new Promise(function (resolve) { return resolve(generateHash(query)); });\n };\n function getQueryHash(query) {\n if (!query || typeof query !== 'object') {\n return getHashPromise(query);\n }\n var hash = hashesByQuery.get(query);\n if (!hash)\n hashesByQuery.set(query, hash = getHashPromise(query));\n return hash;\n }\n return new ApolloLink(function (operation, forward) {\n __DEV__ ? invariant(forward, 'PersistedQueryLink cannot be the last link in the chain.') : invariant(forward, 26);\n var query = operation.query;\n return new Observable(function (observer) {\n var subscription;\n var retried = false;\n var originalFetchOptions;\n var setFetchOptions = false;\n var retry = function (_a, cb) {\n var response = _a.response, networkError = _a.networkError;\n if (!retried && ((response && response.errors) || networkError)) {\n retried = true;\n var graphQLErrors = [];\n var responseErrors = response && response.errors;\n if (isNonEmptyArray(responseErrors)) {\n graphQLErrors.push.apply(graphQLErrors, responseErrors);\n }\n var networkErrors = void 0;\n if (typeof (networkError === null || networkError === void 0 ? void 0 : networkError.result) !== 'string') {\n networkErrors =\n networkError &&\n networkError.result &&\n networkError.result.errors;\n }\n if (isNonEmptyArray(networkErrors)) {\n graphQLErrors.push.apply(graphQLErrors, networkErrors);\n }\n var disablePayload = {\n response: response,\n networkError: networkError,\n operation: operation,\n graphQLErrors: isNonEmptyArray(graphQLErrors) ? graphQLErrors : void 0,\n };\n supportsPersistedQueries = !disable(disablePayload);\n if (collectErrorsByMessage(graphQLErrors).PersistedQueryNotFound ||\n !supportsPersistedQueries) {\n if (subscription)\n subscription.unsubscribe();\n operation.setContext({\n http: {\n includeQuery: true,\n includeExtensions: supportsPersistedQueries,\n },\n fetchOptions: {\n method: 'POST',\n },\n });\n if (setFetchOptions) {\n operation.setContext({ fetchOptions: originalFetchOptions });\n }\n subscription = forward(operation).subscribe(handler);\n return;\n }\n }\n cb();\n };\n var handler = {\n next: function (response) {\n retry({ response: response }, function () { return observer.next(response); });\n },\n error: function (networkError) {\n retry({ networkError: networkError }, function () { return observer.error(networkError); });\n },\n complete: observer.complete.bind(observer),\n };\n operation.setContext({\n http: {\n includeQuery: !supportsPersistedQueries,\n includeExtensions: supportsPersistedQueries,\n },\n });\n if (useGETForHashedQueries &&\n supportsPersistedQueries &&\n !operationDefinesMutation(operation)) {\n operation.setContext(function (_a) {\n var _b = _a.fetchOptions, fetchOptions = _b === void 0 ? {} : _b;\n originalFetchOptions = fetchOptions;\n return {\n fetchOptions: __assign(__assign({}, fetchOptions), { method: 'GET' }),\n };\n });\n setFetchOptions = true;\n }\n if (supportsPersistedQueries) {\n getQueryHash(query).then(function (sha256Hash) {\n operation.extensions.persistedQuery = {\n version: VERSION,\n sha256Hash: sha256Hash,\n };\n subscription = forward(operation).subscribe(handler);\n }).catch(observer.error.bind(observer));\n ;\n }\n else {\n subscription = forward(operation).subscribe(handler);\n }\n return function () {\n if (subscription)\n subscription.unsubscribe();\n };\n });\n });\n};\n//# sourceMappingURL=index.js.map"],"names":["PersistedQueryLink","isNonEmptyArray","invariant","compact","print","ApolloLink","Observable","__assign"],"mappings":";;;;;;;;;;AAKU,IAAC,OAAO,GAAG,EAAE;AACZA,oCAAmB;AAC9B,CAAC,UAAU,kBAAkB,EAAE;AAI/B,CAAC,EAAEA,0BAAkB,KAAKA,0BAAkB,GAAG,EAAE,CAAC,CAAC,CAAC;AACpD,SAAS,sBAAsB,CAAC,aAAa,EAAE;AAC/C,IAAI,IAAI,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AACxC,IAAI,IAAIC,yBAAe,CAAC,aAAa,CAAC,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AAG,EAAE,CAAC,YAAY,EAAE,YAAY,GAAG,EAAE,KAAK,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC;AACrF,oBAAoB,oBAAoB,GAAG,YAAY,CAAC;AACxD,oBAAoB,OAAO;AAC3B,wBAAwB,YAAY,EAAEM,cAAQ,CAACA,cAAQ,CAAC,EAAE,EAAE,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;AAC7F,qBAAqB,CAAC;AACtB,iBAAiB,CAAC,CAAC;AACnB,gBAAgB,eAAe,GAAG,IAAI,CAAC;AACvC,aAAa;AACb,YAAY,IAAI,wBAAwB,EAAE;AAC1C,gBAAgB,YAAY,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,UAAU,UAAU,EAAE;AAC/D,oBAAoB,SAAS,CAAC,UAAU,CAAC,cAAc,GAAG;AAC1D,wBAAwB,OAAO,EAAE,OAAO;AACxC,wBAAwB,UAAU,EAAE,UAAU;AAC9C,qBAAqB,CAAC;AACtB,oBAAoB,YAAY,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;AACzE,iBAAiB,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;AAExD,aAAa;AACb,iBAAiB;AACjB,gBAAgB,YAAY,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;AACrE,aAAa;AACb,YAAY,OAAO,YAAY;AAC/B,gBAAgB,IAAI,YAAY;AAChC,oBAAoB,YAAY,CAAC,WAAW,EAAE,CAAC;AAC/C,aAAa,CAAC;AACd,SAAS,CAAC,CAAC;AACX,KAAK,CAAC,CAAC;AACP;;;;;"}
@@ -82,9 +82,13 @@ var createPersistedQueryLink = function (options) {
82
82
  if (utilities.isNonEmptyArray(responseErrors)) {
83
83
  graphQLErrors.push.apply(graphQLErrors, responseErrors);
84
84
  }
85
- var networkErrors = networkError &&
86
- networkError.result &&
87
- networkError.result.errors;
85
+ var networkErrors = void 0;
86
+ if (typeof (networkError === null || networkError === void 0 ? void 0 : networkError.result) !== 'string') {
87
+ networkErrors =
88
+ networkError &&
89
+ networkError.result &&
90
+ networkError.result.errors;
91
+ }
88
92
  if (utilities.isNonEmptyArray(networkErrors)) {
89
93
  graphQLErrors.push.apply(graphQLErrors, networkErrors);
90
94
  }
@@ -1,6 +1,6 @@
1
1
  export type ServerError = Error & {
2
2
  response: Response;
3
- result: Record<string, any>;
3
+ result: Record<string, any> | string;
4
4
  statusCode: number;
5
5
  };
6
6
  export declare const throwServerError: (response: Response, result: any, message: string) => never;
@@ -1 +1 @@
1
- {"version":3,"file":"throwServerError.d.ts","sourceRoot":"","sources":["../../../src/link/utils/throwServerError.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG;IAChC,QAAQ,EAAE,QAAQ,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,gBAAgB,aACjB,QAAQ,UACV,GAAG,WACF,MAAM,UAQhB,CAAC"}
1
+ {"version":3,"file":"throwServerError.d.ts","sourceRoot":"","sources":["../../../src/link/utils/throwServerError.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG;IAChC,QAAQ,EAAE,QAAQ,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC;IACrC,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,gBAAgB,aACjB,QAAQ,UACV,GAAG,WACF,MAAM,UAQhB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"throwServerError.js","sourceRoot":"","sources":["../../../src/link/utils/throwServerError.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,IAAM,gBAAgB,GAAG,UAC9B,QAAkB,EAClB,MAAW,EACX,OAAe;IAEf,IAAM,KAAK,GAAG,IAAI,KAAK,CAAC,OAAO,CAAgB,CAAC;IAChD,KAAK,CAAC,IAAI,GAAG,aAAa,CAAC;IAC3B,KAAK,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC1B,KAAK,CAAC,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC;IACnC,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC;IACtB,MAAM,KAAK,CAAC;AACd,CAAC,CAAC","sourcesContent":["export type ServerError = Error & {\n response: Response;\n result: Record<string, any>;\n statusCode: number;\n};\n\nexport const throwServerError = (\n response: Response,\n result: any,\n message: string\n) => {\n const error = new Error(message) as ServerError;\n error.name = 'ServerError';\n error.response = response;\n error.statusCode = response.status;\n error.result = result;\n throw error;\n};\n"]}
1
+ {"version":3,"file":"throwServerError.js","sourceRoot":"","sources":["../../../src/link/utils/throwServerError.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,IAAM,gBAAgB,GAAG,UAC9B,QAAkB,EAClB,MAAW,EACX,OAAe;IAEf,IAAM,KAAK,GAAG,IAAI,KAAK,CAAC,OAAO,CAAgB,CAAC;IAChD,KAAK,CAAC,IAAI,GAAG,aAAa,CAAC;IAC3B,KAAK,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC1B,KAAK,CAAC,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC;IACnC,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC;IACtB,MAAM,KAAK,CAAC;AACd,CAAC,CAAC","sourcesContent":["export type ServerError = Error & {\n response: Response;\n result: Record<string, any> | string;\n statusCode: number;\n};\n\nexport const throwServerError = (\n response: Response,\n result: any,\n message: string\n) => {\n const error = new Error(message) as ServerError;\n error.name = 'ServerError';\n error.response = response;\n error.statusCode = response.status;\n error.result = result;\n throw error;\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apollo/client",
3
- "version": "3.7.13",
3
+ "version": "3.7.15",
4
4
  "description": "A fully-featured caching GraphQL client.",
5
5
  "private": false,
6
6
  "keywords": [
@@ -54,7 +54,7 @@
54
54
  "@graphql-typed-document-node/core": "^3.1.1",
55
55
  "@wry/context": "^0.7.0",
56
56
  "@wry/equality": "^0.5.0",
57
- "@wry/trie": "^0.3.0",
57
+ "@wry/trie": "^0.4.0",
58
58
  "graphql-tag": "^2.12.6",
59
59
  "hoist-non-react-statics": "^3.3.2",
60
60
  "optimism": "^0.16.2",
@@ -66,11 +66,13 @@
66
66
  "zen-observable-ts": "^1.2.5"
67
67
  },
68
68
  "devDependencies": {
69
- "@babel/parser": "7.21.4",
69
+ "@babel/parser": "7.21.8",
70
70
  "@changesets/changelog-github": "0.4.8",
71
71
  "@changesets/cli": "2.26.1",
72
72
  "@graphql-tools/schema": "9.0.19",
73
73
  "@rollup/plugin-node-resolve": "11.2.1",
74
+ "@size-limit/esbuild-why": "8.2.4",
75
+ "@size-limit/preset-small-lib": "8.2.4",
74
76
  "@testing-library/react": "14.0.0",
75
77
  "@testing-library/react-12": "npm:@testing-library/react@^12",
76
78
  "@testing-library/user-event": "14.4.3",
@@ -80,43 +82,44 @@
80
82
  "@types/hoist-non-react-statics": "3.3.1",
81
83
  "@types/jest": "29.5.1",
82
84
  "@types/lodash": "4.14.194",
83
- "@types/node": "18.16.0",
84
- "@types/node-fetch": "2.6.3",
85
- "@types/react": "18.2.0",
86
- "@types/react-dom": "18.0.11",
85
+ "@types/node": "20.2.3",
86
+ "@types/node-fetch": "2.6.4",
87
+ "@types/react": "18.2.6",
88
+ "@types/react-dom": "18.2.4",
87
89
  "@types/use-sync-external-store": "0.0.3",
88
- "@typescript-eslint/eslint-plugin": "5.59.0",
89
- "@typescript-eslint/parser": "5.59.1",
90
+ "@typescript-eslint/eslint-plugin": "5.59.6",
91
+ "@typescript-eslint/parser": "5.59.7",
90
92
  "acorn": "8.8.2",
91
93
  "blob-polyfill": "7.0.20220408",
92
94
  "bytes": "3.1.2",
93
- "cross-fetch": "3.1.5",
94
- "eslint": "8.39.0",
95
- "eslint-plugin-testing-library": "5.10.3",
95
+ "cross-fetch": "3.1.6",
96
+ "eslint": "8.41.0",
97
+ "eslint-plugin-testing-library": "5.11.0",
96
98
  "fetch-mock": "9.11.0",
97
99
  "glob": "8.1.0",
98
100
  "graphql": "16.6.0",
99
- "graphql-ws": "5.12.1",
101
+ "graphql-ws": "5.13.1",
100
102
  "jest": "29.5.0",
101
103
  "jest-environment-jsdom": "29.5.0",
102
104
  "jest-junit": "16.0.0",
103
105
  "lodash": "4.17.21",
104
- "patch-package": "6.5.1",
106
+ "patch-package": "7.0.0",
105
107
  "react": "18.2.0",
106
108
  "react-17": "npm:react@^17",
107
109
  "react-dom": "18.2.0",
108
110
  "react-dom-17": "npm:react-dom@^17",
109
- "recast": "0.22.0",
111
+ "recast": "0.23.2",
110
112
  "resolve": "1.22.3",
111
- "rimraf": "5.0.0",
113
+ "rimraf": "5.0.1",
112
114
  "rollup": "2.79.1",
113
115
  "rollup-plugin-terser": "7.0.2",
114
- "rxjs": "7.8.0",
116
+ "rxjs": "7.8.1",
117
+ "size-limit": "8.2.4",
115
118
  "subscriptions-transport-ws": "0.11.0",
116
- "terser": "5.17.1",
119
+ "terser": "5.17.4",
117
120
  "ts-jest": "29.1.0",
118
121
  "ts-node": "10.9.1",
119
- "typedoc": "0.22.18",
122
+ "typedoc": "0.24.7",
120
123
  "typescript": "5.0.4",
121
124
  "wait-for-observables": "1.0.3",
122
125
  "web-streams-polyfill": "3.2.1",
@@ -1,8 +1,9 @@
1
1
  import { Cache, Reference, StoreObject, MissingTree } from "../../cache";
2
2
  import { OperationVariables } from "../../core";
3
- export interface UseFragmentOptions<TData, TVars> extends Omit<Cache.DiffOptions<TData, TVars>, "id" | "query" | "optimistic" | "previousResult">, Omit<Cache.ReadFragmentOptions<TData, TVars>, "id"> {
3
+ export interface UseFragmentOptions<TData, TVars> extends Omit<Cache.DiffOptions<TData, TVars>, "id" | "query" | "optimistic" | "previousResult" | "returnPartialData">, Omit<Cache.ReadFragmentOptions<TData, TVars>, "id" | "returnPartialData"> {
4
4
  from: StoreObject | Reference | string;
5
5
  optimistic?: boolean;
6
+ returnPartialData?: boolean;
6
7
  }
7
8
  export interface UseFragmentResult<TData> {
8
9
  data: TData | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"useFragment.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useFragment.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,KAAK,EACL,SAAS,EACT,WAAW,EACX,WAAW,EACZ,MAAM,aAAa,CAAC;AAIrB,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEhD,MAAM,WAAW,kBAAkB,CAAC,KAAK,EAAE,KAAK,CAChD,SAAQ,IAAI,CACV,KAAK,CAAC,WAAW,CAAC,KAAK,EAAE,KAAK,CAAC,EAC7B,IAAI,GACJ,OAAO,GACP,YAAY,GACZ,gBAAgB,CACnB,EAAE,IAAI,CACL,KAAK,CAAC,mBAAmB,CAAC,KAAK,EAAE,KAAK,CAAC,EACrC,IAAI,CACP;IACC,IAAI,EAAE,WAAW,GAAG,SAAS,GAAG,MAAM,CAAC;IAEvC,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAgBD,MAAM,WAAW,iBAAiB,CAAC,KAAK;IACtC,IAAI,EAAE,KAAK,GAAG,SAAS,CAAC;IACxB,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,WAAW,CAAC;CACvB;AAED,wBAAgB,wBAAwB,CACtC,KAAK,GAAG,GAAG,EACX,KAAK,GAAG,kBAAkB,EAE1B,OAAO,EAAE,kBAAkB,CAAC,KAAK,EAAE,KAAK,CAAC,GACxC,iBAAiB,CAAC,KAAK,CAAC,CA8C1B"}
1
+ {"version":3,"file":"useFragment.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useFragment.ts"],"names":[],"mappings":"AAIA,OAAO,E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CAAC,CAAC;oBACtD,WAAW,EAAE,CAAC;iBACf;YACH,CAAC,IACD,CAAC;IACL,CAAC,EACD,WAAW,EACX,WAAW,CACZ,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CACnB,IAA6B;IAE7B,IAAM,MAAM,GAA6B;QACvC,IAAI,EAAE,IAAI,CAAC,MAAM;QACjB,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ;KAC1B,CAAC;IAEF,IAAI,IAAI,CAAC,OAAO,EAAE;QAChB,MAAM,CAAC,OAAO,GAAG,cAAc,CAC7B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,OAAO,EAAb,CAAa,CAAC,CACzC,CAAC;KACH;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { useRef } from \"react\";\nimport { equal } from \"@wry/equality\";\n\nimport { mergeDeepArray } from \"../../utilities\";\nimport {\n Cache,\n Reference,\n StoreObject,\n MissingTree,\n} from \"../../cache\";\n\nimport { useApolloClient } from \"./useApolloClient\";\nimport { useSyncExternalStore } from \"./useSyncExternalStore\";\nimport { OperationVariables } from \"../../core\";\n\nexport interface UseFragmentOptions<TData, TVars>\nextends Omit<\n Cache.DiffOptions<TData, TVars>,\n | \"id\"\n | \"query\"\n | \"optimistic\"\n | \"previousResult\"\n>, Omit<\n Cache.ReadFragmentOptions<TData, TVars>,\n | \"id\"\n> {\n from: StoreObject | Reference | string;\n // Override this field to make it optional (default: true).\n optimistic?: boolean;\n}\n\n// Since the above definition of UseFragmentOptions can be hard to parse without\n// help from TypeScript/VSCode, here are the intended fields and their types.\n// Uncomment this code to check that it's consistent with the definition above.\n//\n// export interface UseFragmentOptions<TData, TVars> {\n// from: string | StoreObject | Reference;\n// fragment: DocumentNode | TypedDocumentNode<TData, TVars>;\n// fragmentName?: string;\n// optimistic?: boolean;\n// variables?: TVars;\n// returnPartialData?: boolean;\n// canonizeResults?: boolean;\n// }\n\nexport interface UseFragmentResult<TData> {\n data: TData | undefined;\n complete: boolean;\n missing?: MissingTree;\n}\n\nexport function useFragment_experimental<\n TData = any,\n TVars = OperationVariables\n>(\n options: UseFragmentOptions<TData, TVars>,\n): UseFragmentResult<TData> {\n const { cache } = useApolloClient();\n\n const {\n fragment,\n fragmentName,\n from,\n optimistic = true,\n ...rest\n } = options;\n\n const diffOptions: Cache.DiffOptions<TData, TVars> = {\n ...rest,\n id: typeof from === \"string\" ? from : cache.identify(from),\n query: cache[\"getFragmentDoc\"](fragment, fragmentName),\n optimistic,\n };\n\n const resultRef = useRef<UseFragmentResult<TData>>();\n let latestDiff = cache.diff<TData>(diffOptions);\n\n // Used for both getSnapshot and getServerSnapshot\n const getSnapshot = () => {\n const latestDiffToResult = diffToResult(latestDiff);\n return resultRef.current &&\n equal(resultRef.current.data, latestDiffToResult.data)\n ? resultRef.current\n : (resultRef.current = latestDiffToResult);\n };\n\n return useSyncExternalStore(\n (forceUpdate) => {\n return cache.watch({\n ...diffOptions,\n immediate: true,\n callback(diff) {\n if (!equal(diff, latestDiff)) {\n resultRef.current = diffToResult((latestDiff = diff));\n forceUpdate();\n }\n },\n });\n },\n getSnapshot,\n getSnapshot\n );\n}\n\nfunction diffToResult<TData>(\n diff: Cache.DiffResult<TData>,\n): UseFragmentResult<TData> {\n const result: UseFragmentResult<TData> = {\n data: diff.result,\n complete: !!diff.complete,\n };\n\n if (diff.missing) {\n result.missing = mergeDeepArray(\n diff.missing.map(error => error.missing),\n );\n }\n\n return result;\n}\n"]}
1
+ {"version":3,"file":"useFragment.js","sourceRoot":"","sources":["../../../src/react/hooks/useFragment.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAQjD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,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OAAO,GAAG,YAAY,CAAC,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC,CAAC;oBACtD,WAAW,EAAE,CAAC;iBACf;YACH,CAAC,IACD,CAAC;IACL,CAAC,EACD,WAAW,EACX,WAAW,CACZ,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CACnB,IAA6B;IAE7B,IAAM,MAAM,GAA6B;QACvC,IAAI,EAAE,IAAI,CAAC,MAAM;QACjB,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ;KAC1B,CAAC;IAEF,IAAI,IAAI,CAAC,OAAO,EAAE;QAChB,MAAM,CAAC,OAAO,GAAG,cAAc,CAC7B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,OAAO,EAAb,CAAa,CAAC,CACzC,CAAC;KACH;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { useRef } from \"react\";\nimport { equal } from \"@wry/equality\";\n\nimport { mergeDeepArray } from \"../../utilities\";\nimport {\n Cache,\n Reference,\n StoreObject,\n MissingTree,\n} from \"../../cache\";\n\nimport { useApolloClient } from \"./useApolloClient\";\nimport { useSyncExternalStore } from \"./useSyncExternalStore\";\nimport { OperationVariables } from \"../../core\";\n\nexport interface UseFragmentOptions<TData, TVars>\nextends Omit<\n Cache.DiffOptions<TData, TVars>,\n | \"id\"\n | \"query\"\n | \"optimistic\"\n | \"previousResult\"\n | \"returnPartialData\"\n>, Omit<Cache.ReadFragmentOptions<TData, TVars>,\n | \"id\"\n | \"returnPartialData\"\n> {\n from: StoreObject | Reference | string;\n // Override this field to make it optional (default: true).\n optimistic?: boolean;\n\n /**\n * Whether to return incomplete data rather than null.\n * Defaults to `true`.\n * @deprecated This option will be removed in Apollo Client 3.8.\n * Please check `result.missing` instead.\n */\n returnPartialData?: boolean;\n}\n\n// Since the above definition of UseFragmentOptions can be hard to parse without\n// help from TypeScript/VSCode, here are the intended fields and their types.\n// Uncomment this code to check that it's consistent with the definition above.\n//\n// export interface UseFragmentOptions<TData, TVars> {\n// from: string | StoreObject | Reference;\n// fragment: DocumentNode | TypedDocumentNode<TData, TVars>;\n// fragmentName?: string;\n// optimistic?: boolean;\n// variables?: TVars;\n// returnPartialData?: boolean;\n// canonizeResults?: boolean;\n// }\n\nexport interface UseFragmentResult<TData> {\n data: TData | undefined;\n complete: boolean;\n missing?: MissingTree;\n}\n\nexport function useFragment_experimental<\n TData = any,\n TVars = OperationVariables\n>(\n options: UseFragmentOptions<TData, TVars>,\n): UseFragmentResult<TData> {\n const { cache } = useApolloClient();\n\n const {\n fragment,\n fragmentName,\n from,\n optimistic = true,\n ...rest\n } = options;\n\n const diffOptions: Cache.DiffOptions<TData, TVars> = {\n ...rest,\n id: typeof from === \"string\" ? from : cache.identify(from),\n query: cache[\"getFragmentDoc\"](fragment, fragmentName),\n optimistic,\n };\n\n const resultRef = useRef<UseFragmentResult<TData>>();\n let latestDiff = cache.diff<TData>(diffOptions);\n\n // Used for both getSnapshot and getServerSnapshot\n const getSnapshot = () => {\n const latestDiffToResult = diffToResult(latestDiff);\n return resultRef.current &&\n equal(resultRef.current.data, latestDiffToResult.data)\n ? resultRef.current\n : (resultRef.current = latestDiffToResult);\n };\n\n return useSyncExternalStore(\n (forceUpdate) => {\n return cache.watch({\n ...diffOptions,\n immediate: true,\n callback(diff) {\n if (!equal(diff, latestDiff)) {\n resultRef.current = diffToResult((latestDiff = diff));\n forceUpdate();\n }\n },\n });\n },\n getSnapshot,\n getSnapshot\n );\n}\n\nfunction diffToResult<TData>(\n diff: Cache.DiffResult<TData>,\n): UseFragmentResult<TData> {\n const result: UseFragmentResult<TData> = {\n data: diff.result,\n complete: !!diff.complete,\n };\n\n if (diff.missing) {\n result.missing = mergeDeepArray(\n diff.missing.map(error => error.missing),\n );\n }\n\n return result;\n}\n"]}
@@ -21,7 +21,7 @@ export interface MockedProviderState {
21
21
  export declare class MockedProvider extends React.Component<MockedProviderProps, MockedProviderState> {
22
22
  static defaultProps: MockedProviderProps;
23
23
  constructor(props: MockedProviderProps);
24
- render(): JSX.Element | null;
24
+ render(): React.JSX.Element | null;
25
25
  componentWillUnmount(): void;
26
26
  }
27
27
  //# sourceMappingURL=MockedProvider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"storeUtils.d.ts","sourceRoot":"","sources":["../../../src/utilities/graphql/storeUtils.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,aAAa,EACb,SAAS,EAST,YAAY,EACZ,kBAAkB,EAClB,SAAS,EACT,aAAa,EACb,QAAQ,EACR,gBAAgB,EAChB,YAAY,EACb,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,WAAW,EAA4B,MAAM,aAAa,CAAC;AAEpE,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,CAEnD;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,SAAS,CAEtD;AAED,MAAM,MAAM,UAAU,GAClB,MAAM,GACN,MAAM,GACN,MAAM,EAAE,GACR,SAAS,GACT,SAAS,EAAE,GACX,IAAI,GACJ,SAAS,GACT,IAAI,GACJ,MAAM,CAAC;AAEX,MAAM,WAAW,WAAW;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,CAAC,cAAc,EAAE,MAAM,GAAG,UAAU,CAAC;CACtC;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,YAAY,CAMhE;AAsCD,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,GAAG,EACX,IAAI,EAAE,QAAQ,EACd,KAAK,EAAE,SAAS,EAChB,SAAS,CAAC,EAAE,MAAM,QAqCnB;AAED,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,SAAS,EAChB,SAAS,CAAC,EAAE,MAAM,GACjB,MAAM,CA6BR;AAED,MAAM,MA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G,CAAC,GAC9B,MAAM,GAAG,IAAI,CASf;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAE/D;AAED,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC3B,YAAY,EAAE,gBAAgB,EAC9B,WAAW,CAAC,EAAE,WAAW,GACxB,MAAM,GAAG,SAAS,CA4BpB;AAED,wBAAgB,OAAO,CAAC,SAAS,EAAE,aAAa,GAAG,SAAS,IAAI,SAAS,CAExE;AAED,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,aAAa,GACvB,SAAS,IAAI,kBAAkB,CAEjC;AAED,MAAM,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE,YAAY,KAAK,GAAG,CAAC"}
@@ -181,9 +181,7 @@ export function resultKeyNameFromField(field) {
181
181
  return field.alias ? field.alias.value : field.name.value;
182
182
  }
183
183
  export function getTypenameFromResult(result, selectionSet, fragmentMap) {
184
- if (typeof result.__typename === 'string') {
185
- return result.__typename;
186
- }
184
+ var fragments;
187
185
  for (var _i = 0, _a = selectionSet.selections; _i < _a.length; _i++) {
188
186
  var selection = _a[_i];
189
187
  if (isField(selection)) {
@@ -191,7 +189,19 @@ export function getTypenameFromResult(result, selectionSet, fragmentMap) {
191
189
  return result[resultKeyNameFromField(selection)];
192
190
  }
193
191
  }
192
+ else if (fragments) {
193
+ fragments.push(selection);
194
+ }
194
195
  else {
196
+ fragments = [selection];
197
+ }
198
+ }
199
+ if (typeof result.__typename === 'string') {
200
+ return result.__typename;
201
+ }
202
+ if (fragments) {
203
+ for (var _b = 0, fragments_1 = fragments; _b < fragments_1.length; _b++) {
204
+ var selection = fragments_1[_b];
195
205
  var typename = getTypenameFromResult(result, getFragmentFromSelection(selection, fragmentMap).selectionSet, fragmentMap);
196
206
  if (typeof typename === 'string') {
197
207
  return typename;
@@ -1 +1 @@
1
- {"version":3,"file":"storeUtils.js","sourceRoot":"","sources":["../../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AAvB,IAAuB,EAAE;QAA5C,IAAM,SAAS,SAAA;QAClB,IAAI,OAAO,CAAC,SAAS,CAAC,EAAE;YACtB,IAAI,SAAS,CAAC,IAAI,CAAC,KAAK,KAAK,YAAY,EAAE;gBACzC,OAAO,MAAM,CAAC,sBAAsB,CAAC,SAAS,CAAC,CAAC,CAAC;aAClD;SACF;aAAM;YACL,IAAM,QAAQ,GAAG,qBAAqB,CACpC,MAAM,EACN,wBAAwB,CAAC,SAAS,EAAE,WAAW,CAAE,CAAC,YAAY,EAC9D,WAAW,CACZ,CAAC;YACF,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;gBAChC,OAAO,QAAQ,CAAC;aACjB;SACF;KACF;AACH,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,SAAwB;IAC9C,OAAO,SAAS,CAAC,IAAI,KAAK,OAAO,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,gBAAgB,CAC9B,SAAwB;IAExB,OAAO,SAAS,CAAC,IAAI,KAAK,gBAAgB,CAAC;AAC7C,CAAC","sourcesContent":["import { InvariantError } from '../globals';\n\nimport {\n DirectiveNode,\n FieldNode,\n IntValueNode,\n FloatValueNode,\n StringValueNode,\n BooleanValueNode,\n ObjectValueNode,\n ListValueNode,\n EnumValueNode,\n NullValueNode,\n VariableNode,\n InlineFragmentNode,\n ValueNode,\n SelectionNode,\n NameNode,\n SelectionSetNode,\n DocumentNode,\n} from 'graphql';\n\nimport { isNonNullObject } from '../common/objects';\nimport { FragmentMap, getFragmentFromSelection } from './fragments';\n\nexport interface Reference {\n readonly __ref: string;\n}\n\nexport function makeReference(id: string): Reference {\n return { __ref: String(id) };\n}\n\nexport function isReference(obj: any): obj is Reference {\n return Boolean(obj && typeof obj === 'object' && typeof obj.__ref === 'string');\n}\n\nexport type StoreValue =\n | number\n | string\n | string[]\n | Reference\n | Reference[]\n | null\n | undefined\n | void\n | Object;\n\nexport interface StoreObject {\n __typename?: string;\n [storeFieldName: string]: StoreValue;\n}\n\nexport function isDocumentNode(value: any): value is DocumentNode {\n return (\n isNonNullObject(value) &&\n (value as DocumentNode).kind === \"Document\" &&\n Array.isArray((value as DocumentNode).definitions)\n );\n}\n\nfunction isStringValue(value: ValueNode): value is StringValueNode {\n return value.kind === 'StringValue';\n}\n\nfunction isBooleanValue(value: ValueNode): value is BooleanValueNode {\n return value.kind === 'BooleanValue';\n}\n\nfunction isIntValue(value: ValueNode): value is IntValueNode {\n return value.kind === 'IntValue';\n}\n\nfunction isFloatValue(value: ValueNode): value is FloatValueNode {\n return value.kind === 'FloatValue';\n}\n\nfunction isVariable(value: ValueNode): value is VariableNode {\n return value.kind === 'Variable';\n}\n\nfunction isObjectValue(value: ValueNode): value is ObjectValueNode {\n return value.kind === 'ObjectValue';\n}\n\nfunction isListValue(value: ValueNode): value is ListValueNode {\n return value.kind === 'ListValue';\n}\n\nfunction isEnumValue(value: ValueNode): value is EnumValueNode {\n return value.kind === 'EnumValue';\n}\n\nfunction isNullValue(value: ValueNode): value is NullValueNode {\n return value.kind === 'NullValue';\n}\n\nexport function valueToObjectRepresentation(\n argObj: any,\n name: NameNode,\n value: ValueNode,\n variables?: Object,\n) {\n if (isIntValue(value) || isFloatValue(value)) {\n argObj[name.value] = Number(value.value);\n } else if (isBooleanValue(value) || isStringValue(value)) {\n argObj[name.value] = value.value;\n } else if (isObjectValue(value)) {\n const nestedArgObj = {};\n value.fields.map(obj =>\n valueToObjectRepresentation(nestedArgObj, obj.name, obj.value, variables),\n );\n argObj[name.value] = nestedArgObj;\n } else if (isVariable(value)) {\n const variableValue = (variables || ({} as any))[value.name.value];\n argObj[name.value] = variableValue;\n } else if (isListValue(value)) {\n argObj[name.value] = value.values.map(listValue => {\n const nestedArgArrayObj = {};\n valueToObjectRepresentation(\n nestedArgArrayObj,\n name,\n listValue,\n variables,\n );\n return (nestedArgArrayObj as any)[name.value];\n });\n } else if (isEnumValue(value)) {\n argObj[name.value] = (value as EnumValueNode).value;\n } else if (isNullValue(value)) {\n argObj[name.value] = null;\n } else {\n throw new InvariantError(\n `The inline argument \"${name.value}\" of kind \"${(value as any).kind}\"` +\n 'is not supported. Use variables instead of inline arguments to ' +\n 'overcome this limitation.',\n );\n }\n}\n\nexport function storeKeyNameFromField(\n field: FieldNode,\n variables?: Object,\n): string {\n let directivesObj: any = null;\n if (field.directives) {\n directivesObj = {};\n field.directives.forEach(directive => {\n directivesObj[directive.name.value] = {};\n\n if (directive.arguments) {\n directive.arguments.forEach(({ name, value }) =>\n valueToObjectRepresentation(\n directivesObj[directive.name.value],\n name,\n value,\n variables,\n ),\n );\n }\n });\n }\n\n let argObj: any = null;\n if (field.arguments && field.arguments.length) {\n argObj = {};\n field.arguments.forEach(({ name, value }) =>\n valueToObjectRepresentation(argObj, name, value, variables),\n );\n }\n\n return getStoreKeyName(field.name.value, argObj, directivesObj);\n}\n\nexport type Directives = {\n [directiveName: string]: {\n [argName: string]: any;\n };\n};\n\nconst KNOWN_DIRECTIVES: string[] = [\n 'connection',\n 'include',\n 'skip',\n 'client',\n 'rest',\n 'export',\n];\n\nexport const getStoreKeyName = Object.assign(function (\n fieldName: string,\n args?: Record<string, any> | null,\n directives?: Directives,\n): string {\n if (\n args &&\n directives &&\n directives['connection'] &&\n directives['connection']['key']\n ) {\n if (\n directives['connection']['filter'] &&\n (directives['connection']['filter'] as string[]).length > 0\n ) {\n const filterKeys = directives['connection']['filter']\n ? (directives['connection']['filter'] as string[])\n : [];\n filterKeys.sort();\n\n const filteredArgs = {} as { [key: string]: any };\n filterKeys.forEach(key => {\n filteredArgs[key] = args[key];\n });\n\n return `${directives['connection']['key']}(${stringify(\n filteredArgs,\n )})`;\n } else {\n return directives['connection']['key'];\n }\n }\n\n let completeFieldName: string = fieldName;\n\n if (args) {\n // We can't use `JSON.stringify` here since it's non-deterministic,\n // and can lead to different store key names being created even though\n // the `args` object used during creation has the same properties/values.\n const stringifiedArgs: string = stringify(args);\n completeFieldName += `(${stringifiedArgs})`;\n }\n\n if (directives) {\n Object.keys(directives).forEach(key => {\n if (KNOWN_DIRECTIVES.indexOf(key) !== -1) return;\n if (directives[key] && Object.keys(directives[key]).length) {\n completeFieldName += `@${key}(${stringify(directives[key])})`;\n } else {\n completeFieldName += `@${key}`;\n }\n });\n }\n\n return completeFieldName;\n}, {\n setStringify(s: typeof stringify) {\n const previous = stringify;\n stringify = s;\n return previous;\n },\n});\n\n// Default stable JSON.stringify implementation. Can be updated/replaced with\n// something better by calling getStoreKeyName.setStringify.\nlet stringify = function defaultStringify(value: any): string {\n return JSON.stringify(value, stringifyReplacer);\n};\n\nfunction stringifyReplacer(_key: string, value: any): any {\n if (isNonNullObject(value) && !Array.isArray(value)) {\n value = Object.keys(value).sort().reduce((copy, key) => {\n copy[key] = value[key];\n return copy;\n }, {} as Record<string, any>);\n }\n return value;\n}\n\nexport function argumentsObjectFromField(\n field: FieldNode | DirectiveNode,\n variables?: Record<string, any>,\n): Object | null {\n if (field.arguments && field.arguments.length) {\n const argObj: Object = {};\n field.arguments.forEach(({ name, value }) =>\n valueToObjectRepresentation(argObj, name, value, variables),\n );\n return argObj;\n }\n return null;\n}\n\nexport function resultKeyNameFromField(field: FieldNode): string {\n return field.alias ? field.alias.value : field.name.value;\n}\n\nexport function getTypenameFromResult(\n result: Record<string, any>,\n selectionSet: SelectionSetNode,\n fragmentMap?: FragmentMap,\n): string | undefined {\n if (typeof result.__typename === 'string') {\n return result.__typename;\n }\n\n for (const selection of selectionSet.selections) {\n if (isField(selection)) {\n if (selection.name.value === '__typename') {\n return result[resultKeyNameFromField(selection)];\n }\n } else {\n const typename = getTypenameFromResult(\n result,\n getFragmentFromSelection(selection, fragmentMap)!.selectionSet,\n fragmentMap,\n );\n if (typeof typename === 'string') {\n return typename;\n }\n }\n }\n}\n\nexport function isField(selection: SelectionNode): selection is FieldNode {\n return selection.kind === 'Field';\n}\n\nexport function isInlineFragment(\n selection: SelectionNode,\n): selection is InlineFragmentNode {\n return selection.kind === 'InlineFragment';\n}\n\nexport type VariableValue = (node: Vari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B,EAAE;QAA5C,IAAM,SAAS,SAAA;QAClB,IAAI,OAAO,CAAC,SAAS,CAAC,EAAE;YACtB,IAAI,SAAS,CAAC,IAAI,CAAC,KAAK,KAAK,YAAY,EAAE;gBACzC,OAAO,MAAM,CAAC,sBAAsB,CAAC,SAAS,CAAC,CAAC,CAAC;aAClD;SACF;aAAM,IAAI,SAAS,EAAE;YACpB,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;SAC3B;aAAM;YACL,SAAS,GAAG,CAAC,SAAS,CAAC,CAAC;SACzB;KACF;IACD,IAAI,OAAO,MAAM,CAAC,UAAU,KAAK,QAAQ,EAAE;QACzC,OAAO,MAAM,CAAC,UAAU,CAAC;KAC1B;IACD,IAAI,SAAS,EAAE;QACb,KAAwB,UAAS,EAAT,uBAAS,EAAT,uBAAS,EAAT,IAAS,EAAE;YAA9B,IAAM,SAAS,kBAAA;YAClB,IAAM,QAAQ,GAAG,qBAAqB,CACpC,MAAM,EACN,wBAAwB,CAAC,SAAS,EAAE,WAAW,CAAE,CAAC,YAAY,EAC9D,WAAW,CACZ,CAAC;YACF,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;gBAChC,OAAO,QAAQ,CAAC;aACjB;SACF;KACF;AACH,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,SAAwB;IAC9C,OAAO,SAAS,CAAC,IAAI,KAAK,OAAO,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,gBAAgB,CAC9B,SAAwB;IAExB,OAAO,SAAS,CAAC,IAAI,KAAK,gBAAgB,CAAC;AAC7C,CAAC","sourcesContent":["import { InvariantError } from '../globals';\n\nimport {\n DirectiveNode,\n FieldNode,\n IntValueNode,\n FloatValueNode,\n StringValueNode,\n BooleanValueNode,\n ObjectValueNode,\n ListValueNode,\n EnumValueNode,\n NullValueNode,\n VariableNode,\n InlineFragmentNode,\n ValueNode,\n SelectionNode,\n NameNode,\n SelectionSetNode,\n DocumentNode,\n FragmentSpreadNode,\n} from 'graphql';\n\nimport { isNonNullObject } from '../common/objects';\nimport { FragmentMap, getFragmentFromSelection } from './fragments';\n\nexport interface Reference {\n readonly __ref: string;\n}\n\nexport function makeReference(id: string): Reference {\n return { __ref: String(id) };\n}\n\nexport function isReference(obj: any): obj is Reference {\n return Boolean(obj && typeof obj === 'object' && typeof obj.__ref === 'string');\n}\n\nexport type StoreValue =\n | number\n | string\n | string[]\n | Reference\n | Reference[]\n | null\n | undefined\n | void\n | Object;\n\nexport interface StoreObject {\n __typename?: string;\n [storeFieldName: string]: StoreValue;\n}\n\nexport function isDocumentNode(value: any): value is DocumentNode {\n return (\n isNonNullObject(value) &&\n (value as DocumentNode).kind === \"Document\" &&\n Array.isArray((value as DocumentNode).definitions)\n );\n}\n\nfunction isStringValue(value: ValueNode): value is StringValueNode {\n return value.kind === 'StringValue';\n}\n\nfunction isBooleanValue(value: ValueNode): value is BooleanValueNode {\n return value.kind === 'BooleanValue';\n}\n\nfunction isIntValue(value: ValueNode): value is IntValueNode {\n return value.kind === 'IntValue';\n}\n\nfunction isFloatValue(value: ValueNode): value is FloatValueNode {\n return value.kind === 'FloatValue';\n}\n\nfunction isVariable(value: ValueNode): value is VariableNode {\n return value.kind === 'Variable';\n}\n\nfunction isObjectValue(value: ValueNode): value is ObjectValueNode {\n return value.kind === 'ObjectValue';\n}\n\nfunction isListValue(value: ValueNode): value is ListValueNode {\n return value.kind === 'ListValue';\n}\n\nfunction isEnumValue(value: ValueNode): value is EnumValueNode {\n return value.kind === 'EnumValue';\n}\n\nfunction isNullValue(value: ValueNode): value is NullValueNode {\n return value.kind === 'NullValue';\n}\n\nexport function valueToObjectRepresentation(\n argObj: any,\n name: NameNode,\n value: ValueNode,\n variables?: Object,\n) {\n if (isIntValue(value) || isFloatValue(value)) {\n argObj[name.value] = Number(value.value);\n } else if (isBooleanValue(value) || isStringValue(value)) {\n argObj[name.value] = value.value;\n } else if (isObjectValue(value)) {\n const nestedArgObj = {};\n value.fields.map(obj =>\n valueToObjectRepresentation(nestedArgObj, obj.name, obj.value, variables),\n );\n argObj[name.value] = nestedArgObj;\n } else if (isVariable(value)) {\n const variableValue = (variables || ({} as any))[value.name.value];\n argObj[name.value] = variableValue;\n } else if (isListValue(value)) {\n argObj[name.value] = value.values.map(listValue => {\n const nestedArgArrayObj = {};\n valueToObjectRepresentation(\n nestedArgArrayObj,\n name,\n listValue,\n variables,\n );\n return (nestedArgArrayObj as any)[name.value];\n });\n } else if (isEnumValue(value)) {\n argObj[name.value] = (value as EnumValueNode).value;\n } else if (isNullValue(value)) {\n argObj[name.value] = null;\n } else {\n throw new InvariantError(\n `The inline argument \"${name.value}\" of kind \"${(value as any).kind}\"` +\n 'is not supported. Use variables instead of inline arguments to ' +\n 'overcome this limitation.',\n );\n }\n}\n\nexport function storeKeyNameFromField(\n field: FieldNode,\n variables?: Object,\n): string {\n let directivesObj: any = null;\n if (field.directives) {\n directivesObj = {};\n field.directives.forEach(directive => {\n directivesObj[directive.name.value] = {};\n\n if (directive.arguments) {\n directive.arguments.forEach(({ name, value }) =>\n valueToObjectRepresentation(\n directivesObj[directive.name.value],\n name,\n value,\n variables,\n ),\n );\n }\n });\n }\n\n let argObj: any = null;\n if (field.arguments && field.arguments.length) {\n argObj = {};\n field.arguments.forEach(({ name, value }) =>\n valueToObjectRepresentation(argObj, name, value, variables),\n );\n }\n\n return getStoreKeyName(field.name.value, argObj, directivesObj);\n}\n\nexport type Directives = {\n [directiveName: string]: {\n [argName: string]: any;\n };\n};\n\nconst KNOWN_DIRECTIVES: string[] = [\n 'connection',\n 'include',\n 'skip',\n 'client',\n 'rest',\n 'export',\n];\n\nexport const getStoreKeyName = Object.assign(function (\n fieldName: string,\n args?: Record<string, any> | null,\n directives?: Directives,\n): string {\n if (\n args &&\n directives &&\n directives['connection'] &&\n directives['connection']['key']\n ) {\n if (\n directives['connection']['filter'] &&\n (directives['connection']['filter'] as string[]).length > 0\n ) {\n const filterKeys = directives['connection']['filter']\n ? (directives['connection']['filter'] as string[])\n : [];\n filterKeys.sort();\n\n const filteredArgs = {} as { [key: string]: any };\n filterKeys.forEach(key => {\n filteredArgs[key] = args[key];\n });\n\n return `${directives['connection']['key']}(${stringify(\n filteredArgs,\n )})`;\n } else {\n return directives['connection']['key'];\n }\n }\n\n let completeFieldName: string = fieldName;\n\n if (args) {\n // We can't use `JSON.stringify` here since it's non-deterministic,\n // and can lead to different store key names being created even though\n // the `args` object used during creation has the same properties/values.\n const stringifiedArgs: string = stringify(args);\n completeFieldName += `(${stringifiedArgs})`;\n }\n\n if (directives) {\n Object.keys(directives).forEach(key => {\n if (KNOWN_DIRECTIVES.indexOf(key) !== -1) return;\n if (directives[key] && Object.keys(directives[key]).length) {\n completeFieldName += `@${key}(${stringify(directives[key])})`;\n } else {\n completeFieldName += `@${key}`;\n }\n });\n }\n\n return completeFieldName;\n}, {\n setStringify(s: typeof stringify) {\n const previous = stringify;\n stringify = s;\n return previous;\n },\n});\n\n// Default stable JSON.stringify implementation. Can be updated/replaced with\n// something better by calling getStoreKeyName.setStringify.\nlet stringify = function defaultStringify(value: any): string {\n return JSON.stringify(value, stringifyReplacer);\n};\n\nfunction stringifyReplacer(_key: string, value: any): any {\n if (isNonNullObject(value) && !Array.isArray(value)) {\n value = Object.keys(value).sort().reduce((copy, key) => {\n copy[key] = value[key];\n return copy;\n }, {} as Record<string, any>);\n }\n return value;\n}\n\nexport function argumentsObjectFromField(\n field: FieldNode | DirectiveNode,\n variables?: Record<string, any>,\n): Object | null {\n if (field.arguments && field.arguments.length) {\n const argObj: Object = {};\n field.arguments.forEach(({ name, value }) =>\n valueToObjectRepresentation(argObj, name, value, variables),\n );\n return argObj;\n }\n return null;\n}\n\nexport function resultKeyNameFromField(field: FieldNode): string {\n return field.alias ? field.alias.value : field.name.value;\n}\n\nexport function getTypenameFromResult(\n result: Record<string, any>,\n selectionSet: SelectionSetNode,\n fragmentMap?: FragmentMap,\n): string | undefined {\n let fragments: undefined | Array<InlineFragmentNode | FragmentSpreadNode>;\n for (const selection of selectionSet.selections) {\n if (isField(selection)) {\n if (selection.name.value === '__typename') {\n return result[resultKeyNameFromField(selection)];\n }\n } else if (fragments) {\n fragments.push(selection);\n } else {\n fragments = [selection];\n }\n }\n if (typeof result.__typename === 'string') {\n return result.__typename;\n }\n if (fragments) {\n for (const selection of fragments) {\n const typename = getTypenameFromResult(\n result,\n getFragmentFromSelection(selection, fragmentMap)!.selectionSet,\n fragmentMap,\n );\n if (typeof typename === 'string') {\n return typename;\n }\n }\n }\n}\n\nexport function isField(selection: SelectionNode): selection is FieldNode {\n return selection.kind === 'Field';\n}\n\nexport function isInlineFragment(\n selection: SelectionNode,\n): selection is InlineFragmentNode {\n return selection.kind === 'InlineFragment';\n}\n\nexport type VariableValue = (node: VariableNode) => any;\n"]}
@@ -324,9 +324,7 @@ function resultKeyNameFromField(field) {
324
324
  return field.alias ? field.alias.value : field.name.value;
325
325
  }
326
326
  function getTypenameFromResult(result, selectionSet, fragmentMap) {
327
- if (typeof result.__typename === 'string') {
328
- return result.__typename;
329
- }
327
+ var fragments;
330
328
  for (var _i = 0, _a = selectionSet.selections; _i < _a.length; _i++) {
331
329
  var selection = _a[_i];
332
330
  if (isField(selection)) {
@@ -334,7 +332,19 @@ function getTypenameFromResult(result, selectionSet, fragmentMap) {
334
332
  return result[resultKeyNameFromField(selection)];
335
333
  }
336
334
  }
335
+ else if (fragments) {
336
+ fragments.push(selection);
337
+ }
337
338
  else {
339
+ fragments = [selection];
340
+ }
341
+ }
342
+ if (typeof result.__typename === 'string') {
343
+ return result.__typename;
344
+ }
345
+ if (fragments) {
346
+ for (var _b = 0, fragments_1 = fragments; _b < fragments_1.length; _b++) {
347
+ var selection = fragments_1[_b];
338
348
  var typename = getTypenameFromResult(result, getFragmentFromSelection(selection, fragmentMap).selectionSet, fragmentMap);
339
349
  if (typeof typename === 'string') {
340
350
  return typename;