@apollo/client 3.7.11 → 3.7.13
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/apollo-client.cjs +41 -25
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/core/ObservableQuery.d.ts.map +1 -1
- package/core/ObservableQuery.js.map +1 -1
- package/core/core.cjs +1 -1
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +1 -1
- package/invariantErrorCodes.js +1 -1
- package/link/http/http.cjs +16 -11
- package/link/http/http.cjs.map +1 -1
- package/link/http/http.cjs.native.js +16 -11
- package/link/http/parseAndCheckHttpResponse.d.ts.map +1 -1
- package/link/http/parseAndCheckHttpResponse.js +16 -11
- package/link/http/parseAndCheckHttpResponse.js.map +1 -1
- package/link/persisted-queries/index.d.ts.map +1 -1
- package/link/persisted-queries/index.js +5 -10
- package/link/persisted-queries/index.js.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs +5 -10
- package/link/persisted-queries/persisted-queries.cjs.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs.native.js +5 -10
- package/package.json +19 -19
- package/react/hooks/hooks.cjs +24 -13
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +24 -13
- package/react/hooks/useSubscription.d.ts.map +1 -1
- package/react/hooks/useSubscription.js +25 -13
- package/react/hooks/useSubscription.js.map +1 -1
- package/version.js +1 -1
|
@@ -40,10 +40,8 @@ var defaultOptions = {
|
|
|
40
40
|
function operationDefinesMutation(operation) {
|
|
41
41
|
return operation.query.definitions.some(function (d) { return d.kind === 'OperationDefinition' && d.operation === 'mutation'; });
|
|
42
42
|
}
|
|
43
|
-
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
44
|
-
var hashesByQuery = new WeakMap();
|
|
45
|
-
var nextHashesChildKey = 0;
|
|
46
43
|
export var createPersistedQueryLink = function (options) {
|
|
44
|
+
var hashesByQuery = new WeakMap();
|
|
47
45
|
__DEV__ ? invariant(options && (typeof options.sha256 === 'function' ||
|
|
48
46
|
typeof options.generateHash === 'function'), 'Missing/invalid "sha256" or "generateHash" function. Please ' +
|
|
49
47
|
'configure one using the "createPersistedQueryLink(options)" options ' +
|
|
@@ -53,7 +51,6 @@ export var createPersistedQueryLink = function (options) {
|
|
|
53
51
|
return Promise.resolve(sha256(print(query)));
|
|
54
52
|
} : _b, disable = _a.disable, useGETForHashedQueries = _a.useGETForHashedQueries;
|
|
55
53
|
var supportsPersistedQueries = true;
|
|
56
|
-
var hashesChildKey = 'forLink' + nextHashesChildKey++;
|
|
57
54
|
var getHashPromise = function (query) {
|
|
58
55
|
return new Promise(function (resolve) { return resolve(generateHash(query)); });
|
|
59
56
|
};
|
|
@@ -61,12 +58,10 @@ export var createPersistedQueryLink = function (options) {
|
|
|
61
58
|
if (!query || typeof query !== 'object') {
|
|
62
59
|
return getHashPromise(query);
|
|
63
60
|
}
|
|
64
|
-
var
|
|
65
|
-
if (!
|
|
66
|
-
hashesByQuery.set(query,
|
|
67
|
-
return
|
|
68
|
-
? hashes[hashesChildKey]
|
|
69
|
-
: hashes[hashesChildKey] = getHashPromise(query);
|
|
61
|
+
var hash = hashesByQuery.get(query);
|
|
62
|
+
if (!hash)
|
|
63
|
+
hashesByQuery.set(query, hash = getHashPromise(query));
|
|
64
|
+
return hash;
|
|
70
65
|
}
|
|
71
66
|
return new ApolloLink(function (operation, forward) {
|
|
72
67
|
__DEV__ ? invariant(forward, 'PersistedQueryLink cannot be the last link in the chain.') : invariant(forward, 26);
|
|
@@ -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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C","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\nconst { hasOwnProperty } = Object.prototype;\n\nconst hashesByQuery = new WeakMap<\n DocumentNode,\n Record<string, Promise<string>>\n>();\n\nlet nextHashesChildKey = 0;\n\nexport const createPersistedQueryLink = (\n options: PersistedQueryLink.Options,\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 hashesChildKey = 'forLink' + nextHashesChildKey++;\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 hashes = hashesByQuery.get(query)!;\n if (!hashes) hashesByQuery.set(query, hashes = Object.create(null));\n return hasOwnProperty.call(hashes, hashesChildKey)\n ? hashes[hashesChildKey]\n : hashes[hashesChildKey] = getHashPromise(query);\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,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AAC;oBACF,YAAY,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,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 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"]}
|
|
@@ -42,10 +42,8 @@ var defaultOptions = {
|
|
|
42
42
|
function operationDefinesMutation(operation) {
|
|
43
43
|
return operation.query.definitions.some(function (d) { return d.kind === 'OperationDefinition' && d.operation === 'mutation'; });
|
|
44
44
|
}
|
|
45
|
-
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
46
|
-
var hashesByQuery = new WeakMap();
|
|
47
|
-
var nextHashesChildKey = 0;
|
|
48
45
|
var createPersistedQueryLink = function (options) {
|
|
46
|
+
var hashesByQuery = new WeakMap();
|
|
49
47
|
__DEV__ ? globals.invariant(options && (typeof options.sha256 === 'function' ||
|
|
50
48
|
typeof options.generateHash === 'function'), 'Missing/invalid "sha256" or "generateHash" function. Please ' +
|
|
51
49
|
'configure one using the "createPersistedQueryLink(options)" options ' +
|
|
@@ -55,7 +53,6 @@ var createPersistedQueryLink = function (options) {
|
|
|
55
53
|
return Promise.resolve(sha256(graphql.print(query)));
|
|
56
54
|
} : _b, disable = _a.disable, useGETForHashedQueries = _a.useGETForHashedQueries;
|
|
57
55
|
var supportsPersistedQueries = true;
|
|
58
|
-
var hashesChildKey = 'forLink' + nextHashesChildKey++;
|
|
59
56
|
var getHashPromise = function (query) {
|
|
60
57
|
return new Promise(function (resolve) { return resolve(generateHash(query)); });
|
|
61
58
|
};
|
|
@@ -63,12 +60,10 @@ var createPersistedQueryLink = function (options) {
|
|
|
63
60
|
if (!query || typeof query !== 'object') {
|
|
64
61
|
return getHashPromise(query);
|
|
65
62
|
}
|
|
66
|
-
var
|
|
67
|
-
if (!
|
|
68
|
-
hashesByQuery.set(query,
|
|
69
|
-
return
|
|
70
|
-
? hashes[hashesChildKey]
|
|
71
|
-
: hashes[hashesChildKey] = getHashPromise(query);
|
|
63
|
+
var hash = hashesByQuery.get(query);
|
|
64
|
+
if (!hash)
|
|
65
|
+
hashesByQuery.set(query, hash = getHashPromise(query));
|
|
66
|
+
return hash;
|
|
72
67
|
}
|
|
73
68
|
return new core.ApolloLink(function (operation, forward) {
|
|
74
69
|
__DEV__ ? globals.invariant(forward, 'PersistedQueryLink cannot be the last link in the chain.') : globals.invariant(forward, 26);
|
|
@@ -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}\nvar hasOwnProperty = Object.prototype.hasOwnProperty;\nvar hashesByQuery = new WeakMap();\nvar nextHashesChildKey = 0;\nexport var createPersistedQueryLink = function (options) {\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 hashesChildKey = 'forLink' + nextHashesChildKey++;\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 hashes = hashesByQuery.get(query);\n if (!hashes)\n hashesByQuery.set(query, hashes = Object.create(null));\n return hasOwnProperty.call(hashes, hashesChildKey)\n ? hashes[hashesChildKey]\n : hashes[hashesChildKey] = getHashPromise(query);\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,IAAI,aAAa,CAAC,sBAAsB,EAAE;AAClD,YAAY,OAAO,KAAK,CAAC;AACzB,SAAS;AACT,QAAQ,IAAI,QAAQ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,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;;;;;"}
|
|
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;AAC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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;;;;;"}
|
|
@@ -42,10 +42,8 @@ var defaultOptions = {
|
|
|
42
42
|
function operationDefinesMutation(operation) {
|
|
43
43
|
return operation.query.definitions.some(function (d) { return d.kind === 'OperationDefinition' && d.operation === 'mutation'; });
|
|
44
44
|
}
|
|
45
|
-
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
46
|
-
var hashesByQuery = new WeakMap();
|
|
47
|
-
var nextHashesChildKey = 0;
|
|
48
45
|
var createPersistedQueryLink = function (options) {
|
|
46
|
+
var hashesByQuery = new WeakMap();
|
|
49
47
|
__DEV__ ? globals.invariant(options && (typeof options.sha256 === 'function' ||
|
|
50
48
|
typeof options.generateHash === 'function'), 'Missing/invalid "sha256" or "generateHash" function. Please ' +
|
|
51
49
|
'configure one using the "createPersistedQueryLink(options)" options ' +
|
|
@@ -55,7 +53,6 @@ var createPersistedQueryLink = function (options) {
|
|
|
55
53
|
return Promise.resolve(sha256(graphql.print(query)));
|
|
56
54
|
} : _b, disable = _a.disable, useGETForHashedQueries = _a.useGETForHashedQueries;
|
|
57
55
|
var supportsPersistedQueries = true;
|
|
58
|
-
var hashesChildKey = 'forLink' + nextHashesChildKey++;
|
|
59
56
|
var getHashPromise = function (query) {
|
|
60
57
|
return new Promise(function (resolve) { return resolve(generateHash(query)); });
|
|
61
58
|
};
|
|
@@ -63,12 +60,10 @@ var createPersistedQueryLink = function (options) {
|
|
|
63
60
|
if (!query || typeof query !== 'object') {
|
|
64
61
|
return getHashPromise(query);
|
|
65
62
|
}
|
|
66
|
-
var
|
|
67
|
-
if (!
|
|
68
|
-
hashesByQuery.set(query,
|
|
69
|
-
return
|
|
70
|
-
? hashes[hashesChildKey]
|
|
71
|
-
: hashes[hashesChildKey] = getHashPromise(query);
|
|
63
|
+
var hash = hashesByQuery.get(query);
|
|
64
|
+
if (!hash)
|
|
65
|
+
hashesByQuery.set(query, hash = getHashPromise(query));
|
|
66
|
+
return hash;
|
|
72
67
|
}
|
|
73
68
|
return new core.ApolloLink(function (operation, forward) {
|
|
74
69
|
__DEV__ ? globals.invariant(forward, 'PersistedQueryLink cannot be the last link in the chain.') : globals.invariant(forward, 26);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apollo/client",
|
|
3
|
-
"version": "3.7.
|
|
3
|
+
"version": "3.7.13",
|
|
4
4
|
"description": "A fully-featured caching GraphQL client.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"keywords": [
|
|
@@ -66,10 +66,10 @@
|
|
|
66
66
|
"zen-observable-ts": "^1.2.5"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@babel/parser": "7.21.
|
|
69
|
+
"@babel/parser": "7.21.4",
|
|
70
70
|
"@changesets/changelog-github": "0.4.8",
|
|
71
71
|
"@changesets/cli": "2.26.1",
|
|
72
|
-
"@graphql-tools/schema": "9.0.
|
|
72
|
+
"@graphql-tools/schema": "9.0.19",
|
|
73
73
|
"@rollup/plugin-node-resolve": "11.2.1",
|
|
74
74
|
"@testing-library/react": "14.0.0",
|
|
75
75
|
"@testing-library/react-12": "npm:@testing-library/react@^12",
|
|
@@ -78,28 +78,28 @@
|
|
|
78
78
|
"@types/fetch-mock": "7.3.5",
|
|
79
79
|
"@types/glob": "8.1.0",
|
|
80
80
|
"@types/hoist-non-react-statics": "3.3.1",
|
|
81
|
-
"@types/jest": "29.5.
|
|
82
|
-
"@types/lodash": "4.14.
|
|
83
|
-
"@types/node": "18.
|
|
84
|
-
"@types/node-fetch": "2.6.
|
|
85
|
-
"@types/react": "18.0
|
|
81
|
+
"@types/jest": "29.5.1",
|
|
82
|
+
"@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
86
|
"@types/react-dom": "18.0.11",
|
|
87
87
|
"@types/use-sync-external-store": "0.0.3",
|
|
88
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
89
|
-
"@typescript-eslint/parser": "5.
|
|
88
|
+
"@typescript-eslint/eslint-plugin": "5.59.0",
|
|
89
|
+
"@typescript-eslint/parser": "5.59.1",
|
|
90
90
|
"acorn": "8.8.2",
|
|
91
91
|
"blob-polyfill": "7.0.20220408",
|
|
92
92
|
"bytes": "3.1.2",
|
|
93
93
|
"cross-fetch": "3.1.5",
|
|
94
|
-
"eslint": "8.
|
|
95
|
-
"eslint-plugin-testing-library": "5.10.
|
|
94
|
+
"eslint": "8.39.0",
|
|
95
|
+
"eslint-plugin-testing-library": "5.10.3",
|
|
96
96
|
"fetch-mock": "9.11.0",
|
|
97
97
|
"glob": "8.1.0",
|
|
98
98
|
"graphql": "16.6.0",
|
|
99
|
-
"graphql-ws": "5.12.
|
|
99
|
+
"graphql-ws": "5.12.1",
|
|
100
100
|
"jest": "29.5.0",
|
|
101
101
|
"jest-environment-jsdom": "29.5.0",
|
|
102
|
-
"jest-junit": "
|
|
102
|
+
"jest-junit": "16.0.0",
|
|
103
103
|
"lodash": "4.17.21",
|
|
104
104
|
"patch-package": "6.5.1",
|
|
105
105
|
"react": "18.2.0",
|
|
@@ -107,17 +107,17 @@
|
|
|
107
107
|
"react-dom": "18.2.0",
|
|
108
108
|
"react-dom-17": "npm:react-dom@^17",
|
|
109
109
|
"recast": "0.22.0",
|
|
110
|
-
"resolve": "1.22.
|
|
111
|
-
"rimraf": "
|
|
110
|
+
"resolve": "1.22.3",
|
|
111
|
+
"rimraf": "5.0.0",
|
|
112
112
|
"rollup": "2.79.1",
|
|
113
113
|
"rollup-plugin-terser": "7.0.2",
|
|
114
114
|
"rxjs": "7.8.0",
|
|
115
115
|
"subscriptions-transport-ws": "0.11.0",
|
|
116
|
-
"terser": "5.
|
|
117
|
-
"ts-jest": "29.0
|
|
116
|
+
"terser": "5.17.1",
|
|
117
|
+
"ts-jest": "29.1.0",
|
|
118
118
|
"ts-node": "10.9.1",
|
|
119
119
|
"typedoc": "0.22.18",
|
|
120
|
-
"typescript": "5.0.
|
|
120
|
+
"typescript": "5.0.4",
|
|
121
121
|
"wait-for-observables": "1.0.3",
|
|
122
122
|
"web-streams-polyfill": "3.2.1",
|
|
123
123
|
"whatwg-fetch": "3.6.2"
|
package/react/hooks/hooks.cjs
CHANGED
|
@@ -606,9 +606,13 @@ function useSubscription(subscription, options) {
|
|
|
606
606
|
if (!observable) {
|
|
607
607
|
return;
|
|
608
608
|
}
|
|
609
|
+
var subscriptionStopped = false;
|
|
609
610
|
var subscription = observable.subscribe({
|
|
610
611
|
next: function (fetchResult) {
|
|
611
612
|
var _a, _b;
|
|
613
|
+
if (subscriptionStopped) {
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
612
616
|
var result = {
|
|
613
617
|
loading: false,
|
|
614
618
|
data: fetchResult.data,
|
|
@@ -631,26 +635,33 @@ function useSubscription(subscription, options) {
|
|
|
631
635
|
},
|
|
632
636
|
error: function (error) {
|
|
633
637
|
var _a, _b;
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
638
|
+
if (!subscriptionStopped) {
|
|
639
|
+
setResult({
|
|
640
|
+
loading: false,
|
|
641
|
+
data: void 0,
|
|
642
|
+
error: error,
|
|
643
|
+
variables: options === null || options === void 0 ? void 0 : options.variables,
|
|
644
|
+
});
|
|
645
|
+
(_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
|
|
646
|
+
}
|
|
641
647
|
},
|
|
642
648
|
complete: function () {
|
|
643
649
|
var _a, _b;
|
|
644
|
-
if (
|
|
645
|
-
ref.current.options.onComplete
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
ref.current.options.onSubscriptionComplete
|
|
650
|
+
if (!subscriptionStopped) {
|
|
651
|
+
if ((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onComplete) {
|
|
652
|
+
ref.current.options.onComplete();
|
|
653
|
+
}
|
|
654
|
+
else if ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.onSubscriptionComplete) {
|
|
655
|
+
ref.current.options.onSubscriptionComplete();
|
|
656
|
+
}
|
|
649
657
|
}
|
|
650
658
|
},
|
|
651
659
|
});
|
|
652
660
|
return function () {
|
|
653
|
-
|
|
661
|
+
subscriptionStopped = true;
|
|
662
|
+
setTimeout(function () {
|
|
663
|
+
subscription.unsubscribe();
|
|
664
|
+
});
|
|
654
665
|
};
|
|
655
666
|
}, [observable]);
|
|
656
667
|
return result;
|