@apollo/client 3.6.0-beta.10 → 3.6.0-beta.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.
Files changed (48) hide show
  1. package/apollo-client.cjs +187 -173
  2. package/apollo-client.cjs.map +1 -1
  3. package/apollo-client.min.cjs +1 -1
  4. package/core/ApolloClient.d.ts +1 -1
  5. package/core/ApolloClient.d.ts.map +1 -1
  6. package/core/ApolloClient.js.map +1 -1
  7. package/core/ObservableQuery.d.ts +0 -1
  8. package/core/ObservableQuery.d.ts.map +1 -1
  9. package/core/ObservableQuery.js +14 -13
  10. package/core/ObservableQuery.js.map +1 -1
  11. package/core/QueryManager.d.ts.map +1 -1
  12. package/core/QueryManager.js +2 -1
  13. package/core/QueryManager.js.map +1 -1
  14. package/core/core.cjs +15 -14
  15. package/core/core.cjs.map +1 -1
  16. package/core/watchQueryOptions.d.ts +2 -1
  17. package/core/watchQueryOptions.d.ts.map +1 -1
  18. package/core/watchQueryOptions.js.map +1 -1
  19. package/invariantErrorCodes.js +1 -1
  20. package/package.json +4 -2
  21. package/react/hooks/hooks.cjs +154 -142
  22. package/react/hooks/hooks.cjs.map +1 -1
  23. package/react/hooks/index.d.ts +1 -1
  24. package/react/hooks/index.d.ts.map +1 -1
  25. package/react/hooks/index.js +1 -1
  26. package/react/hooks/index.js.map +1 -1
  27. package/react/hooks/useLazyQuery.d.ts +2 -2
  28. package/react/hooks/useLazyQuery.d.ts.map +1 -1
  29. package/react/hooks/useLazyQuery.js +38 -24
  30. package/react/hooks/useLazyQuery.js.map +1 -1
  31. package/react/hooks/useQuery.d.ts +34 -3
  32. package/react/hooks/useQuery.d.ts.map +1 -1
  33. package/react/hooks/useQuery.js +120 -99
  34. package/react/hooks/useQuery.js.map +1 -1
  35. package/react/types/types.d.ts +9 -13
  36. package/react/types/types.d.ts.map +1 -1
  37. package/react/types/types.js.map +1 -1
  38. package/utilities/graphql/transform.d.ts +2 -2
  39. package/utilities/graphql/transform.d.ts.map +1 -1
  40. package/utilities/graphql/transform.js +1 -1
  41. package/utilities/graphql/transform.js.map +1 -1
  42. package/utilities/utilities.cjs +1 -1
  43. package/utilities/utilities.cjs.map +1 -1
  44. package/version.js +1 -1
  45. package/react/hooks/options.d.ts +0 -3
  46. package/react/hooks/options.d.ts.map +0 -1
  47. package/react/hooks/options.js +0 -20
  48. package/react/hooks/options.js.map +0 -1
@@ -24,13 +24,14 @@ export interface QueryOptions<TVariables = OperationVariables, TData = any> {
24
24
  export interface WatchQueryOptions<TVariables = OperationVariables, TData = any> extends Omit<QueryOptions<TVariables, TData>, 'fetchPolicy'> {
25
25
  fetchPolicy?: WatchQueryFetchPolicy;
26
26
  nextFetchPolicy?: WatchQueryFetchPolicy | ((this: WatchQueryOptions<TVariables, TData>, currentFetchPolicy: WatchQueryFetchPolicy, context: NextFetchPolicyContext<TData, TVariables>) => WatchQueryFetchPolicy);
27
+ initialFetchPolicy?: WatchQueryFetchPolicy;
27
28
  refetchWritePolicy?: RefetchWritePolicy;
28
29
  }
29
30
  export interface NextFetchPolicyContext<TData, TVariables> {
30
31
  reason: "after-fetch" | "variables-changed";
31
32
  observable: ObservableQuery<TData, TVariables>;
32
33
  options: WatchQueryOptions<TVariables, TData>;
33
- initialPolicy: WatchQueryFetchPolicy;
34
+ initialFetchPolicy: WatchQueryFetchPolicy;
34
35
  }
35
36
  export interface FetchMoreQueryOptions<TVariables, TData = any> {
36
37
  query?: DocumentNode | TypedDocumentNode<TData, TVariables>;
@@ -1 +1 @@
1
- {"version":3,"file":"watchQueryOptions.d.ts","sourceRoot":"","sources":["../../src/core/watchQueryOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAEtE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EACL,cAAc,EACd,wBAAwB,EACxB,kBAAkB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Root":"","sources":["../../src/core/watchQueryOptions.ts"],"names":[],"mappings":"","sourcesContent":["import { DocumentNode } from 'graphql';\nimport { TypedDocumentNode } from '@graphql-typed-document-node/core';\n\nimport { FetchResult } from '../link/core';\nimport {\n DefaultContext,\n MutationQueryReducersMap,\n OperationVariables,\n MutationUpdaterFunction,\n OnQueryUpdated,\n InternalRefetchQueriesInclude,\n} from './types';\nimport { ApolloCache } from '../cache';\nimport { ObservableQuery } from './ObservableQuery';\n\n/**\n * fetchPolicy determines where the client may return a result from. The options are:\n * - cache-first (default): return result from cache. Only fetch from network if cached result is not available.\n * - cache-and-network: return result from cache first (if it exists), then return network result once it's available.\n * - cache-only: return result from cache if available, fail otherwise.\n * - no-cache: return result from network, fail if network call doesn't succeed, don't save to cache\n * - network-only: return result from network, fail if network call doesn't succeed, save to cache\n * - standby: only for queries that aren't actively watched, but should be available for refetch and updateQueries.\n */\nexport type FetchPolicy =\n | 'cache-first'\n | 'network-only'\n | 'cache-only'\n | 'no-cache'\n | 'standby';\n\nexport type WatchQueryFetchPolicy = FetchPolicy | 'cache-and-network';\n\nexport type MutationFetchPolicy = Extract<\n FetchPolicy,\n | 'network-only' // default behavior (mutation results written to cache)\n | 'no-cache' // alternate behavior (results not written to cache)\n>;\n\nexport type RefetchWritePolicy = \"merge\" | \"overwrite\";\n\n/**\n * errorPolicy determines the level of events for errors in the execution result. The options are:\n * - none (default): any errors from the request are treated like runtime errors and the observable is stopped (XXX this is default to lower breaking changes going from AC 1.0 => 2.0)\n * - ignore: errors from the request do not stop the observable, but also don't call `next`\n * - all: errors are treated like data and will notify observables\n */\nexport type ErrorPolicy = 'none' | 'ignore' | 'all';\n\n/**\n * Query options.\n */\nexport interface QueryOptions<TVariables = OperationVariables, TData = any> {\n /**\n * A GraphQL document that consists of a single query to be sent down to the\n * server.\n */\n // TODO REFACTOR: rename this to document. Didn't do it yet because it's in a\n // lot of tests.\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * A map going from variable name to variable value, where the variables are used\n * within the GraphQL query.\n */\n variables?: TVariables;\n\n /**\n * Specifies the {@link ErrorPolicy} to be used for this query\n */\n errorPolicy?: ErrorPolicy;\n\n /**\n * Context to be passed to link execution chain\n */\n context?: any;\n\n /**\n * Specifies the {@link FetchPolicy} to be used for this query\n */\n fetchPolicy?: FetchPolicy;\n\n /**\n * The time interval (in milliseconds) on which this query should be\n * refetched from the server.\n */\n pollInterval?: number;\n\n /**\n * Whether or not updates to the network status should trigger next on the observer of this query\n */\n notifyOnNetworkStatusChange?: boolean;\n\n /**\n * Allow returning incomplete data from the cache when a larger query cannot\n * be fully satisfied by the cache, instead of returning nothing.\n */\n returnPartialData?: boolean;\n\n /**\n * If `true`, perform a query `refetch` if the query result is marked as\n * being partial, and the returned data is reset to an empty Object by the\n * Apollo Client `QueryManager` (due to a cache miss).\n */\n partialRefetch?: boolean;\n\n /**\n * Whether to canonize cache results before returning them. Canonization\n * takes some extra time, but it speeds up future deep equality comparisons.\n * Defaults to false.\n */\n canonizeResults?: boolean;\n}\n\n/**\n * Watched query options.\n */\nexport interface WatchQueryOptions<TVariables = OperationVariables, TData = any>\n extends Omit<QueryOptions<TVariables, TData>, 'fetchPolicy'> {\n /**\n * Specifies the {@link FetchPolicy} to be used for this query.\n */\n fetchPolicy?: WatchQueryFetchPolicy;\n /**\n * Specifies the {@link FetchPolicy} to be used after this query has completed.\n */\n nextFetchPolicy?: WatchQueryFetchPolicy | ((\n this: WatchQueryOptions<TVariables, TData>,\n currentFetchPolicy: WatchQueryFetchPolicy,\n context: NextFetchPolicyContext<TData, TVariables>,\n ) => WatchQueryFetchPolicy);\n /**\n * Specifies whether a {@link NetworkStatus.refetch} operation should merge\n * incoming field data with existing data, or overwrite the existing data.\n * Overwriting is probably preferable, but merging is currently the default\n * behavior, for backwards compatibility with Apollo Client 3.x.\n */\n refetchWritePolicy?: RefetchWritePolicy;\n}\n\nexport interface NextFetchPolicyContext<TData, TVariables> {\n reason:\n | \"after-fetch\"\n | \"variables-changed\";\n observable: ObservableQuery<TData, TVariables>;\n options: WatchQueryOptions<TVariables, TData>;\n initialPolicy: WatchQueryFetchPolicy;\n}\n\nexport interface FetchMoreQueryOptions<TVariables, TData = any> {\n query?: DocumentNode | TypedDocumentNode<TData, TVariables>;\n variables?: Partial<TVariables>;\n context?: any;\n}\n\nexport type UpdateQueryFn<\n TData = any,\n TSubscriptionVariables = OperationVariables,\n TSubscriptionData = TData\n> = (\n previousQueryResult: TData,\n options: {\n subscriptionData: { data: TSubscriptionData };\n variables?: TSubscriptionVariables;\n },\n) => TData;\n\nexport type SubscribeToMoreOptions<\n TData = any,\n TSubscriptionVariables = OperationVariables,\n TSubscriptionData = TData\n> = {\n document: DocumentNode | TypedDocumentNode<TSubscriptionData, TSubscriptionVariables>;\n variables?: TSubscriptionVariables;\n updateQuery?: UpdateQueryFn<TData, TSubscriptionVariables, TSubscriptionData>;\n onError?: (error: Error) => void;\n context?: DefaultContext;\n};\n\nexport interface SubscriptionOptions<TVariables = OperationVariables, TData = any> {\n /**\n * A GraphQL document, often created with `gql` from the `graphql-tag`\n * package, that contains a single subscription inside of it.\n */\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * An object that maps from the name of a variable as used in the subscription\n * GraphQL document to that variable's value.\n */\n variables?: TVariables;\n\n /**\n * Specifies the {@link FetchPolicy} to be used for this subscription.\n */\n fetchPolicy?: FetchPolicy;\n\n /**\n * Specifies the {@link ErrorPolicy} to be used for this operation\n */\n errorPolicy?: ErrorPolicy;\n\n /**\n * Context object to be passed through the link execution chain.\n */\n context?: DefaultContext;\n}\n\nexport interface MutationBaseOptions<\n TData = any,\n TVariables = OperationVariables,\n TContext = DefaultContext,\n TCache extends ApolloCache<any> = ApolloCache<any>,\n> {\n /**\n * An object that represents the result of this mutation that will be\n * optimistically stored before the server has actually returned a result.\n * This is most often used for optimistic UI, where we want to be able to see\n * the result of a mutation immediately, and update the UI later if any errors\n * appear.\n */\n optimisticResponse?: TData | ((vars: TVariables) => TData);\n\n /**\n * A {@link MutationQueryReducersMap}, which is map from query names to\n * mutation query reducers. Briefly, this map defines how to incorporate the\n * results of the mutation into the results of queries that are currently\n * being watched by your application.\n */\n updateQueries?: MutationQueryReducersMap<TData>;\n\n /**\n * A list of query names which will be refetched once this mutation has\n * returned. This is often used if you have a set of queries which may be\n * affected by a mutation and will have to update. Rather than writing a\n * mutation query reducer (i.e. `updateQueries`) for this, you can simply\n * refetch the queries that will be affected and achieve a consistent store\n * once these queries return.\n */\n refetchQueries?:\n | ((result: FetchResult<TData>) => InternalRefetchQueriesInclude)\n | InternalRefetchQueriesInclude;\n\n /**\n * By default, `refetchQueries` does not wait for the refetched queries to\n * be completed, before resolving the mutation `Promise`. This ensures that\n * query refetching does not hold up mutation response handling (query\n * refetching is handled asynchronously). Set `awaitRefetchQueries` to\n * `true` if you would like to wait for the refetched queries to complete,\n * before the mutation can be marked as resolved.\n */\n awaitRefetchQueries?: boolean;\n\n /**\n * A function which provides an {@link ApolloCache} instance, and the result\n * of the mutation, to allow the user to update the store based on the\n * results of the mutation.\n *\n * This function will be called twice over the lifecycle of a mutation. Once\n * at the very beginning if an `optimisticResponse` was provided. The writes\n * created from the optimistic data will be rolled back before the second time\n * this function is called which is when the mutation has successfully\n * resolved. At that point `update` will be called with the *actual* mutation\n * result and those writes will not be rolled back.\n *\n * Note that since this function is intended to be used to update the\n * store, it cannot be used with a `no-cache` fetch policy. If you're\n * interested in performing some action after a mutation has completed,\n * and you don't need to update the store, use the Promise returned from\n * `client.mutate` instead.\n */\n update?: MutationUpdaterFunction<TData, TVariables, TContext, TCache>;\n\n /**\n * A function that will be called for each ObservableQuery affected by\n * this mutation, after the mutation has completed.\n */\n onQueryUpdated?: OnQueryUpdated<any>;\n\n /**\n * Specifies the {@link ErrorPolicy} to be used for this operation\n */\n errorPolicy?: ErrorPolicy;\n\n /**\n * An object that maps from the name of a variable as used in the mutation\n * GraphQL document to that variable's value.\n */\n variables?: TVariables;\n\n /**\n * The context to be passed to the link execution chain. This context will\n * only be used with this mutation. It will not be used with\n * `refetchQueries`. Refetched queries use the context they were\n * initialized with (since the initial context is stored as part of the\n * `ObservableQuery` instance). If a specific context is needed when\n * refetching queries, make sure it is configured (via the\n * [query `context` option](https://www.apollographql.com/docs/react/api/apollo-client#ApolloClient.query))\n * when the query is first initialized/run.\n */\n context?: TContext;\n}\n\nexport interface MutationOptions<\n TData = any,\n TVariables = OperationVariables,\n TContext = DefaultContext,\n TCache extends ApolloCache<any> = ApolloCache<any>,\n> extends MutationBaseOptions<TData, TVariables, TContext, TCache> {\n /**\n * A GraphQL document, often created with `gql` from the `graphql-tag`\n * package, that contains a single mutation inside of it.\n */\n mutation: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * Specifies the {@link MutationFetchPolicy} to be used for this query.\n * Mutations support only 'network-only' and 'no-cache' fetchPolicy strings.\n * If fetchPolicy is not provided, it defaults to 'network-only'.\n */\n fetchPolicy?: MutationFetchPolicy;\n\n /**\n * To avoid retaining sensitive information from mutation root field\n * arguments, Apollo Client v3.4+ automatically clears any `ROOT_MUTATION`\n * fields from the cache after each mutation finishes. If you need this\n * information to remain in the cache, you can prevent the removal by passing\n * `keepRootFields: true` to the mutation. `ROOT_MUTATION` result data are\n * also passed to the mutation `update` function, so we recommend obtaining\n * the results that way, rather than using this option, if possible.\n */\n keepRootFields?: boolean;\n}\n"]}
1
+ {"version":3,"file":"watchQueryOptions.js","sourceRoot":"","sources":["../../src/core/watchQueryOptions.ts"],"names":[],"mappings":"","sourcesContent":["import { DocumentNode } from 'graphql';\nimport { TypedDocumentNode } from '@graphql-typed-document-node/core';\n\nimport { FetchResult } from '../link/core';\nimport {\n DefaultContext,\n MutationQueryReducersMap,\n OperationVariables,\n MutationUpdaterFunction,\n OnQueryUpdated,\n InternalRefetchQueriesInclude,\n} from './types';\nimport { ApolloCache } from '../cache';\nimport { ObservableQuery } from './ObservableQuery';\n\n/**\n * fetchPolicy determines where the client may return a result from. The options are:\n * - cache-first (default): return result from cache. Only fetch from network if cached result is not available.\n * - cache-and-network: return result from cache first (if it exists), then return network result once it's available.\n * - cache-only: return result from cache if available, fail otherwise.\n * - no-cache: return result from network, fail if network call doesn't succeed, don't save to cache\n * - network-only: return result from network, fail if network call doesn't succeed, save to cache\n * - standby: only for queries that aren't actively watched, but should be available for refetch and updateQueries.\n */\nexport type FetchPolicy =\n | 'cache-first'\n | 'network-only'\n | 'cache-only'\n | 'no-cache'\n | 'standby';\n\nexport type WatchQueryFetchPolicy = FetchPolicy | 'cache-and-network';\n\nexport type MutationFetchPolicy = Extract<\n FetchPolicy,\n | 'network-only' // default behavior (mutation results written to cache)\n | 'no-cache' // alternate behavior (results not written to cache)\n>;\n\nexport type RefetchWritePolicy = \"merge\" | \"overwrite\";\n\n/**\n * errorPolicy determines the level of events for errors in the execution result. The options are:\n * - none (default): any errors from the request are treated like runtime errors and the observable is stopped (XXX this is default to lower breaking changes going from AC 1.0 => 2.0)\n * - ignore: errors from the request do not stop the observable, but also don't call `next`\n * - all: errors are treated like data and will notify observables\n */\nexport type ErrorPolicy = 'none' | 'ignore' | 'all';\n\n/**\n * Query options.\n */\nexport interface QueryOptions<TVariables = OperationVariables, TData = any> {\n /**\n * A GraphQL document that consists of a single query to be sent down to the\n * server.\n */\n // TODO REFACTOR: rename this to document. Didn't do it yet because it's in a\n // lot of tests.\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * A map going from variable name to variable value, where the variables are used\n * within the GraphQL query.\n */\n variables?: TVariables;\n\n /**\n * Specifies the {@link ErrorPolicy} to be used for this query\n */\n errorPolicy?: ErrorPolicy;\n\n /**\n * Context to be passed to link execution chain\n */\n context?: any;\n\n /**\n * Specifies the {@link FetchPolicy} to be used for this query\n */\n fetchPolicy?: FetchPolicy;\n\n /**\n * The time interval (in milliseconds) on which this query should be\n * refetched from the server.\n */\n pollInterval?: number;\n\n /**\n * Whether or not updates to the network status should trigger next on the observer of this query\n */\n notifyOnNetworkStatusChange?: boolean;\n\n /**\n * Allow returning incomplete data from the cache when a larger query cannot\n * be fully satisfied by the cache, instead of returning nothing.\n */\n returnPartialData?: boolean;\n\n /**\n * If `true`, perform a query `refetch` if the query result is marked as\n * being partial, and the returned data is reset to an empty Object by the\n * Apollo Client `QueryManager` (due to a cache miss).\n */\n partialRefetch?: boolean;\n\n /**\n * Whether to canonize cache results before returning them. Canonization\n * takes some extra time, but it speeds up future deep equality comparisons.\n * Defaults to false.\n */\n canonizeResults?: boolean;\n}\n\n/**\n * Watched query options.\n */\nexport interface WatchQueryOptions<TVariables = OperationVariables, TData = any>\n extends Omit<QueryOptions<TVariables, TData>, 'fetchPolicy'> {\n /**\n * Specifies the {@link FetchPolicy} to be used for this query.\n */\n fetchPolicy?: WatchQueryFetchPolicy;\n\n /**\n * Specifies the {@link FetchPolicy} to be used after this query has completed.\n */\n nextFetchPolicy?: WatchQueryFetchPolicy | ((\n this: WatchQueryOptions<TVariables, TData>,\n currentFetchPolicy: WatchQueryFetchPolicy,\n context: NextFetchPolicyContext<TData, TVariables>,\n ) => WatchQueryFetchPolicy);\n\n /**\n * Defaults to the initial value of options.fetchPolicy, but can be explicitly\n * configured to specify the WatchQueryFetchPolicy to revert back to whenever\n * variables change (unless nextFetchPolicy intervenes).\n */\n initialFetchPolicy?: WatchQueryFetchPolicy;\n\n /**\n * Specifies whether a {@link NetworkStatus.refetch} operation should merge\n * incoming field data with existing data, or overwrite the existing data.\n * Overwriting is probably preferable, but merging is currently the default\n * behavior, for backwards compatibility with Apollo Client 3.x.\n */\n refetchWritePolicy?: RefetchWritePolicy;\n}\n\nexport interface NextFetchPolicyContext<TData, TVariables> {\n reason:\n | \"after-fetch\"\n | \"variables-changed\";\n observable: ObservableQuery<TData, TVariables>;\n options: WatchQueryOptions<TVariables, TData>;\n initialFetchPolicy: WatchQueryFetchPolicy;\n}\n\nexport interface FetchMoreQueryOptions<TVariables, TData = any> {\n query?: DocumentNode | TypedDocumentNode<TData, TVariables>;\n variables?: Partial<TVariables>;\n context?: any;\n}\n\nexport type UpdateQueryFn<\n TData = any,\n TSubscriptionVariables = OperationVariables,\n TSubscriptionData = TData\n> = (\n previousQueryResult: TData,\n options: {\n subscriptionData: { data: TSubscriptionData };\n variables?: TSubscriptionVariables;\n },\n) => TData;\n\nexport type SubscribeToMoreOptions<\n TData = any,\n TSubscriptionVariables = OperationVariables,\n TSubscriptionData = TData\n> = {\n document: DocumentNode | TypedDocumentNode<TSubscriptionData, TSubscriptionVariables>;\n variables?: TSubscriptionVariables;\n updateQuery?: UpdateQueryFn<TData, TSubscriptionVariables, TSubscriptionData>;\n onError?: (error: Error) => void;\n context?: DefaultContext;\n};\n\nexport interface SubscriptionOptions<TVariables = OperationVariables, TData = any> {\n /**\n * A GraphQL document, often created with `gql` from the `graphql-tag`\n * package, that contains a single subscription inside of it.\n */\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * An object that maps from the name of a variable as used in the subscription\n * GraphQL document to that variable's value.\n */\n variables?: TVariables;\n\n /**\n * Specifies the {@link FetchPolicy} to be used for this subscription.\n */\n fetchPolicy?: FetchPolicy;\n\n /**\n * Specifies the {@link ErrorPolicy} to be used for this operation\n */\n errorPolicy?: ErrorPolicy;\n\n /**\n * Context object to be passed through the link execution chain.\n */\n context?: DefaultContext;\n}\n\nexport interface MutationBaseOptions<\n TData = any,\n TVariables = OperationVariables,\n TContext = DefaultContext,\n TCache extends ApolloCache<any> = ApolloCache<any>,\n> {\n /**\n * An object that represents the result of this mutation that will be\n * optimistically stored before the server has actually returned a result.\n * This is most often used for optimistic UI, where we want to be able to see\n * the result of a mutation immediately, and update the UI later if any errors\n * appear.\n */\n optimisticResponse?: TData | ((vars: TVariables) => TData);\n\n /**\n * A {@link MutationQueryReducersMap}, which is map from query names to\n * mutation query reducers. Briefly, this map defines how to incorporate the\n * results of the mutation into the results of queries that are currently\n * being watched by your application.\n */\n updateQueries?: MutationQueryReducersMap<TData>;\n\n /**\n * A list of query names which will be refetched once this mutation has\n * returned. This is often used if you have a set of queries which may be\n * affected by a mutation and will have to update. Rather than writing a\n * mutation query reducer (i.e. `updateQueries`) for this, you can simply\n * refetch the queries that will be affected and achieve a consistent store\n * once these queries return.\n */\n refetchQueries?:\n | ((result: FetchResult<TData>) => InternalRefetchQueriesInclude)\n | InternalRefetchQueriesInclude;\n\n /**\n * By default, `refetchQueries` does not wait for the refetched queries to\n * be completed, before resolving the mutation `Promise`. This ensures that\n * query refetching does not hold up mutation response handling (query\n * refetching is handled asynchronously). Set `awaitRefetchQueries` to\n * `true` if you would like to wait for the refetched queries to complete,\n * before the mutation can be marked as resolved.\n */\n awaitRefetchQueries?: boolean;\n\n /**\n * A function which provides an {@link ApolloCache} instance, and the result\n * of the mutation, to allow the user to update the store based on the\n * results of the mutation.\n *\n * This function will be called twice over the lifecycle of a mutation. Once\n * at the very beginning if an `optimisticResponse` was provided. The writes\n * created from the optimistic data will be rolled back before the second time\n * this function is called which is when the mutation has successfully\n * resolved. At that point `update` will be called with the *actual* mutation\n * result and those writes will not be rolled back.\n *\n * Note that since this function is intended to be used to update the\n * store, it cannot be used with a `no-cache` fetch policy. If you're\n * interested in performing some action after a mutation has completed,\n * and you don't need to update the store, use the Promise returned from\n * `client.mutate` instead.\n */\n update?: MutationUpdaterFunction<TData, TVariables, TContext, TCache>;\n\n /**\n * A function that will be called for each ObservableQuery affected by\n * this mutation, after the mutation has completed.\n */\n onQueryUpdated?: OnQueryUpdated<any>;\n\n /**\n * Specifies the {@link ErrorPolicy} to be used for this operation\n */\n errorPolicy?: ErrorPolicy;\n\n /**\n * An object that maps from the name of a variable as used in the mutation\n * GraphQL document to that variable's value.\n */\n variables?: TVariables;\n\n /**\n * The context to be passed to the link execution chain. This context will\n * only be used with this mutation. It will not be used with\n * `refetchQueries`. Refetched queries use the context they were\n * initialized with (since the initial context is stored as part of the\n * `ObservableQuery` instance). If a specific context is needed when\n * refetching queries, make sure it is configured (via the\n * [query `context` option](https://www.apollographql.com/docs/react/api/apollo-client#ApolloClient.query))\n * when the query is first initialized/run.\n */\n context?: TContext;\n}\n\nexport interface MutationOptions<\n TData = any,\n TVariables = OperationVariables,\n TContext = DefaultContext,\n TCache extends ApolloCache<any> = ApolloCache<any>,\n> extends MutationBaseOptions<TData, TVariables, TContext, TCache> {\n /**\n * A GraphQL document, often created with `gql` from the `graphql-tag`\n * package, that contains a single mutation inside of it.\n */\n mutation: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * Specifies the {@link MutationFetchPolicy} to be used for this query.\n * Mutations support only 'network-only' and 'no-cache' fetchPolicy strings.\n * If fetchPolicy is not provided, it defaults to 'network-only'.\n */\n fetchPolicy?: MutationFetchPolicy;\n\n /**\n * To avoid retaining sensitive information from mutation root field\n * arguments, Apollo Client v3.4+ automatically clears any `ROOT_MUTATION`\n * fields from the cache after each mutation finishes. If you need this\n * information to remain in the cache, you can prevent the removal by passing\n * `keepRootFields: true` to the mutation. `ROOT_MUTATION` result data are\n * also passed to the mutation `update` function, so we recommend obtaining\n * the results that way, rather than using this option, if possible.\n */\n keepRootFields?: boolean;\n}\n"]}
@@ -5,7 +5,7 @@
5
5
  // consult the @apollo/client/invariantErrorCodes.js file specific to
6
6
  // your @apollo/client version. This file is not meant to be imported.
7
7
  {
8
- "@apollo/client version": "3.6.0-beta.10",
8
+ "@apollo/client version": "3.6.0-beta.13",
9
9
 
10
10
  1: {
11
11
  file: "@apollo/client/cache/inmemory/entityStore.js",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apollo/client",
3
- "version": "3.6.0-beta.10",
3
+ "version": "3.6.0-beta.13",
4
4
  "description": "A fully-featured caching GraphQL client.",
5
5
  "private": false,
6
6
  "keywords": [
@@ -31,7 +31,7 @@
31
31
  "peerDependencies": {
32
32
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0",
33
33
  "graphql-ws": "^5.5.5",
34
- "react": "^16.8.0 || ^17.0.0",
34
+ "react": "^16.8.0 || ^17.0.0 || ^18.0.0",
35
35
  "subscriptions-transport-ws": "^0.9.0 || ^0.11.0"
36
36
  },
37
37
  "peerDependenciesMeta": {
@@ -57,6 +57,7 @@
57
57
  "symbol-observable": "^4.0.0",
58
58
  "ts-invariant": "^0.10.0",
59
59
  "tslib": "^2.3.0",
60
+ "use-sync-external-store": "^1.0.0",
60
61
  "zen-observable-ts": "^1.2.0"
61
62
  },
62
63
  "devDependencies": {
@@ -74,6 +75,7 @@
74
75
  "@types/node": "16.11.26",
75
76
  "@types/react": "17.0.43",
76
77
  "@types/react-dom": "17.0.14",
78
+ "@types/use-sync-external-store": "^0.0.3",
77
79
  "acorn": "8.6.0",
78
80
  "bundlesize": "0.18.1",
79
81
  "cross-fetch": "3.1.5",
@@ -6,16 +6,13 @@ var globals = require('../../utilities/globals');
6
6
  var react = require('react');
7
7
  var context = require('../context');
8
8
  var tslib = require('tslib');
9
- var equal = require('@wry/equality');
10
9
  var errors = require('../../errors');
10
+ var index_js = require('use-sync-external-store/shim/index.js');
11
+ var equality = require('@wry/equality');
11
12
  var core = require('../../core');
12
13
  var parser = require('../parser');
13
14
  var utilities = require('../../utilities');
14
15
 
15
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
16
-
17
- var equal__default = /*#__PURE__*/_interopDefaultLegacy(equal);
18
-
19
16
  function useApolloClient(override) {
20
17
  var context$1 = react.useContext(context.getApolloContext());
21
18
  var client = override || context$1.client;
@@ -25,26 +22,9 @@ function useApolloClient(override) {
25
22
  return client;
26
23
  }
27
24
 
28
- function useNormalizedOptions(optionsOrFunction) {
29
- var optionsRef = react.useRef();
30
- var options = optionsRef.current || Object.create(null);
31
- if (typeof optionsOrFunction === "function") {
32
- var newOptions = optionsOrFunction(options);
33
- if (newOptions !== options) {
34
- Object.assign(options, newOptions, newOptions.variables && {
35
- variables: tslib.__assign(tslib.__assign({}, options.variables), newOptions.variables),
36
- });
37
- }
38
- }
39
- else if (optionsOrFunction && !equal__default(optionsOrFunction, options)) {
40
- options = optionsOrFunction;
41
- }
42
- return optionsRef.current = options;
43
- }
44
-
45
25
  var hasOwnProperty = Object.prototype.hasOwnProperty;
46
- function useQuery(query, optionsOrFunction) {
47
- var options = useNormalizedOptions(optionsOrFunction);
26
+ function useQuery(query, options) {
27
+ if (options === void 0) { options = Object.create(null); }
48
28
  return useInternalState(useApolloClient(options.client), query).useQuery(options);
49
29
  }
50
30
  function useInternalState(client, query) {
@@ -65,51 +45,140 @@ var InternalState = (function () {
65
45
  function InternalState(client, query) {
66
46
  this.client = client;
67
47
  this.query = query;
48
+ this.ssrDisabledResult = utilities.maybeDeepFreeze({
49
+ loading: true,
50
+ data: void 0,
51
+ error: void 0,
52
+ networkStatus: core.NetworkStatus.loading,
53
+ });
54
+ this.skipStandbyResult = utilities.maybeDeepFreeze({
55
+ loading: false,
56
+ data: void 0,
57
+ error: void 0,
58
+ networkStatus: core.NetworkStatus.ready,
59
+ });
68
60
  this.toQueryResultCache = new (utilities.canUseWeakMap ? WeakMap : Map)();
69
61
  parser.verifyDocumentType(query, parser.DocumentType.Query);
70
62
  }
71
63
  InternalState.prototype.forceUpdate = function () {
72
64
  };
73
65
  InternalState.prototype.useQuery = function (options) {
66
+ var _this = this;
67
+ this.renderPromises = react.useContext(context.getApolloContext()).renderPromises;
74
68
  this.useOptions(options);
75
69
  var obsQuery = this.useObservableQuery();
76
- this.useSubscriptionEffect(obsQuery);
77
- var result = this.getCurrentResult();
70
+ var result = index_js.useSyncExternalStore(react.useCallback(function () {
71
+ if (_this.renderPromises) {
72
+ return function () { };
73
+ }
74
+ var onNext = function () {
75
+ var previousResult = _this.result;
76
+ var result = obsQuery.getCurrentResult();
77
+ if (previousResult &&
78
+ previousResult.loading === result.loading &&
79
+ previousResult.networkStatus === result.networkStatus &&
80
+ equality.equal(previousResult.data, result.data)) {
81
+ return;
82
+ }
83
+ _this.setResult(result);
84
+ };
85
+ var onError = function (error) {
86
+ var last = obsQuery["last"];
87
+ subscription.unsubscribe();
88
+ try {
89
+ obsQuery.resetLastResults();
90
+ subscription = obsQuery.subscribe(onNext, onError);
91
+ }
92
+ finally {
93
+ obsQuery["last"] = last;
94
+ }
95
+ if (!hasOwnProperty.call(error, 'graphQLErrors')) {
96
+ throw error;
97
+ }
98
+ var previousResult = _this.result;
99
+ if (!previousResult ||
100
+ (previousResult && previousResult.loading) ||
101
+ !equality.equal(error, previousResult.error)) {
102
+ _this.setResult({
103
+ data: (previousResult && previousResult.data),
104
+ error: error,
105
+ loading: false,
106
+ networkStatus: core.NetworkStatus.error,
107
+ });
108
+ }
109
+ };
110
+ var subscription = obsQuery.subscribe(onNext, onError);
111
+ return function () { return subscription.unsubscribe(); };
112
+ }, [
113
+ obsQuery,
114
+ this.renderPromises,
115
+ this.client.disableNetworkFetches,
116
+ ]), function () { return _this.getCurrentResult(); });
78
117
  this.unsafeHandlePartialRefetch(result);
79
118
  return this.toQueryResult(result);
80
119
  };
81
120
  InternalState.prototype.useOptions = function (options) {
82
- this.renderPromises = react.useContext(context.getApolloContext()).renderPromises;
83
121
  var watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
84
- if (!equal.equal(watchQueryOptions, this.watchQueryOptions)) {
122
+ if (!equality.equal(watchQueryOptions, this.watchQueryOptions)) {
85
123
  this.watchQueryOptions = watchQueryOptions;
86
124
  }
87
- this.ssrDisabled = !!(options && (options.ssr === false ||
88
- options.skip));
89
- this.onCompleted = options
90
- && options.onCompleted
91
- || InternalState.prototype.onCompleted;
92
- this.onError = options
93
- && options.onError
94
- || InternalState.prototype.onError;
125
+ this.ssrDisabled = !!(options.ssr === false ||
126
+ options.skip);
127
+ this.onCompleted = options.onCompleted || InternalState.prototype.onCompleted;
128
+ this.onError = options.onError || InternalState.prototype.onError;
129
+ if ((this.renderPromises || this.client.disableNetworkFetches) &&
130
+ this.queryHookOptions.ssr === false) {
131
+ this.result = this.ssrDisabledResult;
132
+ }
133
+ else if (this.queryHookOptions.skip ||
134
+ this.watchQueryOptions.fetchPolicy === 'standby') {
135
+ this.result = this.skipStandbyResult;
136
+ }
137
+ else if (this.result === this.ssrDisabledResult ||
138
+ this.result === this.skipStandbyResult) {
139
+ this.result = void 0;
140
+ }
95
141
  };
96
142
  InternalState.prototype.createWatchQueryOptions = function (_a) {
97
- var _b;
98
143
  if (_a === void 0) { _a = {}; }
99
- var skip = _a.skip; _a.ssr; _a.onCompleted; _a.onError; _a.displayName; var otherOptions = tslib.__rest(_a, ["skip", "ssr", "onCompleted", "onError", "displayName"]);
100
- var watchQueryOptions = Object.assign(otherOptions, { query: this.query });
101
- if (skip) {
102
- watchQueryOptions.fetchPolicy = 'standby';
144
+ var skip = _a.skip; _a.ssr; _a.onCompleted; _a.onError; _a.displayName; var defaultOptions = _a.defaultOptions, otherOptions = tslib.__rest(_a, ["skip", "ssr", "onCompleted", "onError", "displayName", "defaultOptions"]);
145
+ var toMerge = [];
146
+ var globalDefaults = this.client.defaultOptions.watchQuery;
147
+ if (globalDefaults)
148
+ toMerge.push(globalDefaults);
149
+ if (defaultOptions)
150
+ toMerge.push(defaultOptions);
151
+ var latestOptions = this.observable && this.observable.options;
152
+ if (latestOptions && toMerge.length) {
153
+ var defaults_1 = toMerge.reduce(core.mergeOptions, Object.create(null));
154
+ toMerge.length = 1;
155
+ toMerge[0] = defaults_1;
156
+ Object.keys(defaults_1).forEach(function (defaultOptionName) {
157
+ var currentOptionValue = latestOptions[defaultOptionName];
158
+ if (hasOwnProperty.call(latestOptions, defaultOptionName) &&
159
+ !equality.equal(defaults_1[defaultOptionName], currentOptionValue)) {
160
+ defaults_1[defaultOptionName] = defaultOptionName === "variables"
161
+ ? tslib.__assign(tslib.__assign({}, defaults_1.variables), currentOptionValue) : currentOptionValue;
162
+ }
163
+ });
103
164
  }
104
- else if (((_b = watchQueryOptions.context) === null || _b === void 0 ? void 0 : _b.renderPromises) &&
165
+ toMerge.push(otherOptions);
166
+ var merged = toMerge.reduce(core.mergeOptions, Object.create(null));
167
+ var watchQueryOptions = Object.assign(merged, { query: this.query });
168
+ if (this.renderPromises &&
105
169
  (watchQueryOptions.fetchPolicy === 'network-only' ||
106
170
  watchQueryOptions.fetchPolicy === 'cache-and-network')) {
107
171
  watchQueryOptions.fetchPolicy = 'cache-first';
108
172
  }
109
173
  else if (!watchQueryOptions.fetchPolicy) {
110
- var defaultOptions = this.client.defaultOptions.watchQuery;
111
- watchQueryOptions.fetchPolicy =
112
- defaultOptions && defaultOptions.fetchPolicy || 'cache-first';
174
+ watchQueryOptions.fetchPolicy = 'cache-first';
175
+ }
176
+ if (skip) {
177
+ var _b = watchQueryOptions.initialFetchPolicy, initialFetchPolicy = _b === void 0 ? watchQueryOptions.fetchPolicy : _b;
178
+ Object.assign(watchQueryOptions, {
179
+ initialFetchPolicy: initialFetchPolicy,
180
+ fetchPolicy: 'standby',
181
+ });
113
182
  }
114
183
  if (!watchQueryOptions.variables) {
115
184
  watchQueryOptions.variables = {};
@@ -127,6 +196,7 @@ var InternalState = (function () {
127
196
  || this.client.watchQuery(this.watchQueryOptions);
128
197
  this.obsQueryFields = react.useMemo(function () { return ({
129
198
  refetch: obsQuery.refetch.bind(obsQuery),
199
+ reobserve: obsQuery.reobserve.bind(obsQuery),
130
200
  fetchMore: obsQuery.fetchMore.bind(obsQuery),
131
201
  updateQuery: obsQuery.updateQuery.bind(obsQuery),
132
202
  startPolling: obsQuery.startPolling.bind(obsQuery),
@@ -172,56 +242,6 @@ var InternalState = (function () {
172
242
  }, [obsQuery, this.watchQueryOptions]);
173
243
  return obsQuery;
174
244
  };
175
- InternalState.prototype.useSubscriptionEffect = function (obsQuery) {
176
- var _this = this;
177
- react.useEffect(function () {
178
- if (_this.renderPromises) {
179
- return;
180
- }
181
- var onNext = function () {
182
- var previousResult = _this.result;
183
- var result = obsQuery.getCurrentResult();
184
- if (previousResult &&
185
- previousResult.loading === result.loading &&
186
- previousResult.networkStatus === result.networkStatus &&
187
- equal.equal(previousResult.data, result.data)) {
188
- return;
189
- }
190
- _this.setResult(result);
191
- };
192
- var onError = function (error) {
193
- var last = obsQuery["last"];
194
- subscription.unsubscribe();
195
- try {
196
- obsQuery.resetLastResults();
197
- subscription = obsQuery.subscribe(onNext, onError);
198
- }
199
- finally {
200
- obsQuery["last"] = last;
201
- }
202
- if (!hasOwnProperty.call(error, 'graphQLErrors')) {
203
- throw error;
204
- }
205
- var previousResult = _this.result;
206
- if (!previousResult ||
207
- (previousResult && previousResult.loading) ||
208
- !equal.equal(error, previousResult.error)) {
209
- _this.setResult({
210
- data: (previousResult && previousResult.data),
211
- error: error,
212
- loading: false,
213
- networkStatus: core.NetworkStatus.error,
214
- });
215
- }
216
- };
217
- var subscription = obsQuery.subscribe(onNext, onError);
218
- return function () { return subscription.unsubscribe(); };
219
- }, [
220
- obsQuery,
221
- this.renderPromises,
222
- this.client.disableNetworkFetches,
223
- ]);
224
- };
225
245
  InternalState.prototype.setResult = function (nextResult) {
226
246
  var previousResult = this.result;
227
247
  if (previousResult && previousResult.data) {
@@ -242,30 +262,10 @@ var InternalState = (function () {
242
262
  }
243
263
  };
244
264
  InternalState.prototype.getCurrentResult = function () {
245
- var result = this.result;
246
- if (!result) {
247
- result = this.result = this.observable.getCurrentResult();
248
- this.handleErrorOrCompleted(result);
265
+ if (!this.result) {
266
+ this.handleErrorOrCompleted(this.result = this.observable.getCurrentResult());
249
267
  }
250
- if ((this.renderPromises || this.client.disableNetworkFetches) &&
251
- this.queryHookOptions.ssr === false) {
252
- result = {
253
- loading: true,
254
- data: void 0,
255
- error: void 0,
256
- networkStatus: core.NetworkStatus.loading,
257
- };
258
- }
259
- else if (this.queryHookOptions.skip ||
260
- this.queryHookOptions.fetchPolicy === 'standby') {
261
- result = {
262
- loading: false,
263
- data: void 0,
264
- error: void 0,
265
- networkStatus: core.NetworkStatus.ready,
266
- };
267
- }
268
- return result;
268
+ return this.result;
269
269
  };
270
270
  InternalState.prototype.toQueryResult = function (result) {
271
271
  var queryResult = this.toQueryResultCache.get(result);
@@ -296,31 +296,34 @@ var InternalState = (function () {
296
296
 
297
297
  var EAGER_METHODS = [
298
298
  'refetch',
299
+ 'reobserve',
299
300
  'fetchMore',
300
301
  'updateQuery',
301
302
  'startPolling',
302
303
  'subscribeToMore',
303
304
  ];
304
- function useLazyQuery(query, optionsOrFunction) {
305
- var options = useNormalizedOptions(optionsOrFunction);
306
- var _a = react.useState({
307
- called: false,
308
- }), execution = _a[0], setExecution = _a[1];
309
- var result = useQuery(query, tslib.__assign(tslib.__assign(tslib.__assign({}, options), execution.options), { fetchPolicy: execution.called ? options === null || options === void 0 ? void 0 : options.fetchPolicy : 'standby', skip: undefined }));
310
- if (!execution.called) {
311
- result = tslib.__assign(tslib.__assign({}, result), { loading: false, data: void 0, error: void 0, called: false });
312
- }
305
+ function useLazyQuery(query, options) {
306
+ var internalState = useInternalState(useApolloClient(options && options.client), query);
307
+ var execOptionsRef = react.useRef();
308
+ var defaultOptions = internalState.client.defaultOptions.watchQuery;
309
+ var initialFetchPolicy = (options && options.fetchPolicy) ||
310
+ (execOptionsRef.current && execOptionsRef.current.fetchPolicy) ||
311
+ (defaultOptions && defaultOptions.fetchPolicy) ||
312
+ "cache-first";
313
+ var useQueryResult = internalState.useQuery(tslib.__assign(tslib.__assign(tslib.__assign({}, options), execOptionsRef.current), { skip: !execOptionsRef.current }));
314
+ var result = Object.assign(useQueryResult, {
315
+ called: !!execOptionsRef.current,
316
+ });
313
317
  var eagerMethods = react.useMemo(function () {
314
318
  var eagerMethods = {};
315
319
  var _loop_1 = function (key) {
316
320
  var method = result[key];
317
321
  eagerMethods[key] = function () {
318
- var args = [];
319
- for (var _i = 0; _i < arguments.length; _i++) {
320
- args[_i] = arguments[_i];
322
+ if (!execOptionsRef.current) {
323
+ execOptionsRef.current = Object.create(null);
324
+ internalState.forceUpdate();
321
325
  }
322
- setExecution(function (execution) { return (tslib.__assign(tslib.__assign({}, execution), { called: true })); });
323
- return method.apply(void 0, args);
326
+ return method.apply(this, arguments);
324
327
  };
325
328
  };
326
329
  for (var _i = 0, EAGER_METHODS_1 = EAGER_METHODS; _i < EAGER_METHODS_1.length; _i++) {
@@ -329,15 +332,24 @@ function useLazyQuery(query, optionsOrFunction) {
329
332
  }
330
333
  return eagerMethods;
331
334
  }, []);
332
- result.error = result.error || void 0;
333
335
  Object.assign(result, eagerMethods);
334
336
  var execute = react.useCallback(function (executeOptions) {
335
- setExecution({ called: true, options: executeOptions });
336
- var promise = result.refetch(executeOptions === null || executeOptions === void 0 ? void 0 : executeOptions.variables).then(function (result1) {
337
- var result2 = tslib.__assign(tslib.__assign({}, result), { data: result1.data, error: result1.error, called: true, loading: false });
338
- Object.assign(result2, eagerMethods);
339
- return result2;
340
- });
337
+ var promise = result.reobserve(execOptionsRef.current = executeOptions ? tslib.__assign(tslib.__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
338
+ fetchPolicy: initialFetchPolicy,
339
+ }).then(function (apolloQueryResult) {
340
+ apolloQueryResult = apolloQueryResult || internalState["getCurrentResult"]();
341
+ if (apolloQueryResult.error ||
342
+ utilities.isNonEmptyArray(apolloQueryResult.errors)) {
343
+ var _a = result.observable.options.errorPolicy, errorPolicy = _a === void 0 ? "none" : _a;
344
+ if (errorPolicy === "none") {
345
+ throw apolloQueryResult.error || new errors.ApolloError({
346
+ graphQLErrors: apolloQueryResult.errors,
347
+ });
348
+ }
349
+ }
350
+ return internalState.toQueryResult(apolloQueryResult);
351
+ }).then(function (queryResult) { return Object.assign(queryResult, eagerMethods); });
352
+ internalState.forceUpdate();
341
353
  promise.catch(function () { });
342
354
  return promise;
343
355
  }, []);
@@ -393,7 +405,7 @@ function useMutation(mutation, options) {
393
405
  error: error,
394
406
  client: client,
395
407
  };
396
- if (ref.current.isMounted && !equal.equal(ref.current.result, result_1)) {
408
+ if (ref.current.isMounted && !equality.equal(ref.current.result, result_1)) {
397
409
  setResult(ref.current.result = result_1);
398
410
  }
399
411
  }
@@ -411,7 +423,7 @@ function useMutation(mutation, options) {
411
423
  called: true,
412
424
  client: client,
413
425
  };
414
- if (!equal.equal(ref.current.result, result_2)) {
426
+ if (!equality.equal(ref.current.result, result_2)) {
415
427
  setResult(ref.current.result = result_2);
416
428
  }
417
429
  }
@@ -474,7 +486,7 @@ function useSubscription(subscription, options) {
474
486
  subscription !== ref.current.subscription ||
475
487
  (options === null || options === void 0 ? void 0 : options.fetchPolicy) !== ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
476
488
  !(options === null || options === void 0 ? void 0 : options.skip) !== !((_c = ref.current.options) === null || _c === void 0 ? void 0 : _c.skip) ||
477
- !equal.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) {
489
+ !equality.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) {
478
490
  setResult({
479
491
  loading: true,
480
492
  data: void 0,