diff --git a/.api-reports/api-report-core.api.md b/.api-reports/api-report-core.api.md index cb31ddd4692..f7e3ebd12ee 100644 --- a/.api-reports/api-report-core.api.md +++ b/.api-reports/api-report-core.api.md @@ -2059,8 +2059,6 @@ interface QueryOptions { errorPolicy?: ErrorPolicy; fetchPolicy?: FetchPolicy; notifyOnNetworkStatusChange?: boolean; - // @deprecated - partialRefetch?: boolean; pollInterval?: number; query: DocumentNode | TypedDocumentNode; returnPartialData?: boolean; @@ -2253,8 +2251,6 @@ interface SharedWatchQueryOptions // Warning: (ae-forgotten-export) The symbol "NextFetchPolicyContext" needs to be exported by the entry point index.d.ts nextFetchPolicy?: WatchQueryFetchPolicy | ((this: WatchQueryOptions, currentFetchPolicy: WatchQueryFetchPolicy, context: NextFetchPolicyContext) => WatchQueryFetchPolicy); notifyOnNetworkStatusChange?: boolean; - // @deprecated - partialRefetch?: boolean; pollInterval?: number; refetchWritePolicy?: RefetchWritePolicy; returnPartialData?: boolean; @@ -2505,7 +2501,7 @@ interface WriteContext extends ReadMergeModifyContext { // src/core/ObservableQuery.ts:121:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts // src/core/QueryManager.ts:159:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts // src/core/QueryManager.ts:414:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts -// src/core/watchQueryOptions.ts:277:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts +// src/core/watchQueryOptions.ts:271:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts // src/link/http/selectHttpOptionsAndBody.ts:128:32 - (ae-forgotten-export) The symbol "HttpQueryOptions" needs to be exported by the entry point index.d.ts // (No @packageDocumentation comment for this package) diff --git a/.api-reports/api-report-react.api.md b/.api-reports/api-report-react.api.md index 8373acf4521..ab8eb8fe830 100644 --- a/.api-reports/api-report-react.api.md +++ b/.api-reports/api-report-react.api.md @@ -1825,8 +1825,6 @@ interface QueryOptions { errorPolicy?: ErrorPolicy; fetchPolicy?: FetchPolicy; notifyOnNetworkStatusChange?: boolean; - // @deprecated - partialRefetch?: boolean; pollInterval?: number; query: DocumentNode | TypedDocumentNode; returnPartialData?: boolean; @@ -2029,8 +2027,6 @@ interface SharedWatchQueryOptions // Warning: (ae-forgotten-export) The symbol "NextFetchPolicyContext" needs to be exported by the entry point index.d.ts nextFetchPolicy?: WatchQueryFetchPolicy | ((this: WatchQueryOptions, currentFetchPolicy: WatchQueryFetchPolicy, context: NextFetchPolicyContext) => WatchQueryFetchPolicy); notifyOnNetworkStatusChange?: boolean; - // @deprecated - partialRefetch?: boolean; pollInterval?: number; refetchWritePolicy?: RefetchWritePolicy; returnPartialData?: boolean; @@ -2518,7 +2514,7 @@ interface WatchQueryOptions { errorPolicy?: ErrorPolicy; fetchPolicy?: FetchPolicy; notifyOnNetworkStatusChange?: boolean; - // @deprecated - partialRefetch?: boolean; pollInterval?: number; query: DocumentNode | TypedDocumentNode; returnPartialData?: boolean; @@ -1738,8 +1736,6 @@ interface SharedWatchQueryOptions // Warning: (ae-forgotten-export) The symbol "NextFetchPolicyContext" needs to be exported by the entry point index.d.ts nextFetchPolicy?: WatchQueryFetchPolicy | ((this: WatchQueryOptions, currentFetchPolicy: WatchQueryFetchPolicy, context: NextFetchPolicyContext) => WatchQueryFetchPolicy); notifyOnNetworkStatusChange?: boolean; - // @deprecated - partialRefetch?: boolean; pollInterval?: number; // Warning: (ae-forgotten-export) The symbol "RefetchWritePolicy" needs to be exported by the entry point index.d.ts refetchWritePolicy?: RefetchWritePolicy; @@ -1920,7 +1916,7 @@ interface WatchQueryOptions { errorPolicy?: ErrorPolicy; fetchPolicy?: FetchPolicy; notifyOnNetworkStatusChange?: boolean; - // @deprecated - partialRefetch?: boolean; pollInterval?: number; query: DocumentNode | TypedDocumentNode; returnPartialData?: boolean; @@ -1865,8 +1863,6 @@ interface SharedWatchQueryOptions // Warning: (ae-forgotten-export) The symbol "NextFetchPolicyContext" needs to be exported by the entry point index.d.ts nextFetchPolicy?: WatchQueryFetchPolicy | ((this: WatchQueryOptions, currentFetchPolicy: WatchQueryFetchPolicy, context: NextFetchPolicyContext) => WatchQueryFetchPolicy); notifyOnNetworkStatusChange?: boolean; - // @deprecated - partialRefetch?: boolean; pollInterval?: number; refetchWritePolicy?: RefetchWritePolicy; returnPartialData?: boolean; @@ -2342,7 +2338,7 @@ interface WatchQueryOptions { errorPolicy?: ErrorPolicy; fetchPolicy?: FetchPolicy; notifyOnNetworkStatusChange?: boolean; - // @deprecated - partialRefetch?: boolean; pollInterval?: number; query: DocumentNode | TypedDocumentNode; returnPartialData?: boolean; @@ -1915,8 +1913,6 @@ interface SharedWatchQueryOptions // Warning: (ae-forgotten-export) The symbol "NextFetchPolicyContext" needs to be exported by the entry point index.d.ts nextFetchPolicy?: WatchQueryFetchPolicy | ((this: WatchQueryOptions, currentFetchPolicy: WatchQueryFetchPolicy, context: NextFetchPolicyContext) => WatchQueryFetchPolicy); notifyOnNetworkStatusChange?: boolean; - // @deprecated - partialRefetch?: boolean; pollInterval?: number; refetchWritePolicy?: RefetchWritePolicy; returnPartialData?: boolean; @@ -2405,7 +2401,7 @@ export function wrapQueryRef(inter // src/core/QueryManager.ts:414:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts // src/core/types.ts:175:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts // src/core/types.ts:204:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts -// src/core/watchQueryOptions.ts:277:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts +// src/core/watchQueryOptions.ts:271:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts // src/react/hooks/useBackgroundQuery.ts:38:3 - (ae-forgotten-export) The symbol "SubscribeToMoreFunction" needs to be exported by the entry point index.d.ts // src/react/hooks/useBackgroundQuery.ts:54:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts // src/react/hooks/useBackgroundQuery.ts:78:4 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts diff --git a/.api-reports/api-report-react_ssr.api.md b/.api-reports/api-report-react_ssr.api.md index cb40f4d1f28..6d68fa3d42e 100644 --- a/.api-reports/api-report-react_ssr.api.md +++ b/.api-reports/api-report-react_ssr.api.md @@ -1556,8 +1556,6 @@ interface QueryOptions { errorPolicy?: ErrorPolicy; fetchPolicy?: FetchPolicy; notifyOnNetworkStatusChange?: boolean; - // @deprecated - partialRefetch?: boolean; pollInterval?: number; query: DocumentNode | TypedDocumentNode; returnPartialData?: boolean; @@ -1723,8 +1721,6 @@ interface SharedWatchQueryOptions // Warning: (ae-forgotten-export) The symbol "NextFetchPolicyContext" needs to be exported by the entry point index.d.ts nextFetchPolicy?: WatchQueryFetchPolicy | ((this: WatchQueryOptions, currentFetchPolicy: WatchQueryFetchPolicy, context: NextFetchPolicyContext) => WatchQueryFetchPolicy); notifyOnNetworkStatusChange?: boolean; - // @deprecated - partialRefetch?: boolean; pollInterval?: number; // Warning: (ae-forgotten-export) The symbol "RefetchWritePolicy" needs to be exported by the entry point index.d.ts refetchWritePolicy?: RefetchWritePolicy; @@ -1905,7 +1901,7 @@ interface WatchQueryOptions { errorPolicy?: ErrorPolicy; fetchPolicy?: FetchPolicy; notifyOnNetworkStatusChange?: boolean; - // @deprecated - partialRefetch?: boolean; pollInterval?: number; query: DocumentNode | TypedDocumentNode; returnPartialData?: boolean; @@ -1768,8 +1766,6 @@ interface SharedWatchQueryOptions // Warning: (ae-forgotten-export) The symbol "NextFetchPolicyContext" needs to be exported by the entry point index.d.ts nextFetchPolicy?: WatchQueryFetchPolicy | ((this: WatchQueryOptions, currentFetchPolicy: WatchQueryFetchPolicy, context: NextFetchPolicyContext) => WatchQueryFetchPolicy); notifyOnNetworkStatusChange?: boolean; - // @deprecated - partialRefetch?: boolean; pollInterval?: number; // Warning: (ae-forgotten-export) The symbol "RefetchWritePolicy" needs to be exported by the entry point index.d.ts refetchWritePolicy?: RefetchWritePolicy; @@ -1970,7 +1966,7 @@ export function withWarningSpy(it: (...args: TArgs // src/core/QueryManager.ts:414:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts // src/core/types.ts:175:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts // src/core/types.ts:204:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts -// src/core/watchQueryOptions.ts:277:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts +// src/core/watchQueryOptions.ts:271:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts // (No @packageDocumentation comment for this package) diff --git a/.api-reports/api-report-testing_core.api.md b/.api-reports/api-report-testing_core.api.md index 473326a16a8..8cf4ea4041c 100644 --- a/.api-reports/api-report-testing_core.api.md +++ b/.api-reports/api-report-testing_core.api.md @@ -1594,8 +1594,6 @@ interface QueryOptions { errorPolicy?: ErrorPolicy; fetchPolicy?: FetchPolicy; notifyOnNetworkStatusChange?: boolean; - // @deprecated - partialRefetch?: boolean; pollInterval?: number; query: DocumentNode | TypedDocumentNode; returnPartialData?: boolean; @@ -1725,8 +1723,6 @@ interface SharedWatchQueryOptions // Warning: (ae-forgotten-export) The symbol "NextFetchPolicyContext" needs to be exported by the entry point index.d.ts nextFetchPolicy?: WatchQueryFetchPolicy | ((this: WatchQueryOptions, currentFetchPolicy: WatchQueryFetchPolicy, context: NextFetchPolicyContext) => WatchQueryFetchPolicy); notifyOnNetworkStatusChange?: boolean; - // @deprecated - partialRefetch?: boolean; pollInterval?: number; // Warning: (ae-forgotten-export) The symbol "RefetchWritePolicy" needs to be exported by the entry point index.d.ts refetchWritePolicy?: RefetchWritePolicy; @@ -1927,7 +1923,7 @@ export function withWarningSpy(it: (...args: TArgs // src/core/QueryManager.ts:414:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts // src/core/types.ts:175:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts // src/core/types.ts:204:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts -// src/core/watchQueryOptions.ts:277:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts +// src/core/watchQueryOptions.ts:271:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts // (No @packageDocumentation comment for this package) diff --git a/.api-reports/api-report-utilities.api.md b/.api-reports/api-report-utilities.api.md index 76b0f621592..60a3aedb6f4 100644 --- a/.api-reports/api-report-utilities.api.md +++ b/.api-reports/api-report-utilities.api.md @@ -2372,8 +2372,6 @@ interface QueryOptions { errorPolicy?: ErrorPolicy; fetchPolicy?: FetchPolicy; notifyOnNetworkStatusChange?: boolean; - // @deprecated - partialRefetch?: boolean; pollInterval?: number; query: DocumentNode | TypedDocumentNode; returnPartialData?: boolean; @@ -2580,8 +2578,6 @@ interface SharedWatchQueryOptions // Warning: (ae-forgotten-export) The symbol "NextFetchPolicyContext" needs to be exported by the entry point index.d.ts nextFetchPolicy?: WatchQueryFetchPolicy | ((this: WatchQueryOptions, currentFetchPolicy: WatchQueryFetchPolicy, context: NextFetchPolicyContext) => WatchQueryFetchPolicy); notifyOnNetworkStatusChange?: boolean; - // @deprecated - partialRefetch?: boolean; pollInterval?: number; // Warning: (ae-forgotten-export) The symbol "RefetchWritePolicy" needs to be exported by the entry point index.d.ts refetchWritePolicy?: RefetchWritePolicy; @@ -2878,7 +2874,7 @@ interface WriteContext extends ReadMergeModifyContext { // src/core/QueryManager.ts:414:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts // src/core/types.ts:175:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts // src/core/types.ts:204:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts -// src/core/watchQueryOptions.ts:277:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts +// src/core/watchQueryOptions.ts:271:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts // src/utilities/graphql/storeUtils.ts:226:12 - (ae-forgotten-export) The symbol "storeKeyNameStringify" needs to be exported by the entry point index.d.ts // src/utilities/policies/pagination.ts:76:3 - (ae-forgotten-export) The symbol "TRelayEdge" needs to be exported by the entry point index.d.ts // src/utilities/policies/pagination.ts:77:3 - (ae-forgotten-export) The symbol "TRelayPageInfo" needs to be exported by the entry point index.d.ts diff --git a/.api-reports/api-report.api.md b/.api-reports/api-report.api.md index 3a4bac0f7a6..9cab2abd14f 100644 --- a/.api-reports/api-report.api.md +++ b/.api-reports/api-report.api.md @@ -2406,8 +2406,6 @@ interface QueryOptions { errorPolicy?: ErrorPolicy; fetchPolicy?: FetchPolicy; notifyOnNetworkStatusChange?: boolean; - // @deprecated - partialRefetch?: boolean; pollInterval?: number; query: DocumentNode | TypedDocumentNode; returnPartialData?: boolean; @@ -2661,8 +2659,6 @@ interface SharedWatchQueryOptions // Warning: (ae-forgotten-export) The symbol "NextFetchPolicyContext" needs to be exported by the entry point index.d.ts nextFetchPolicy?: WatchQueryFetchPolicy | ((this: WatchQueryOptions, currentFetchPolicy: WatchQueryFetchPolicy, context: NextFetchPolicyContext) => WatchQueryFetchPolicy); notifyOnNetworkStatusChange?: boolean; - // @deprecated - partialRefetch?: boolean; pollInterval?: number; refetchWritePolicy?: RefetchWritePolicy; returnPartialData?: boolean; @@ -3216,7 +3212,7 @@ interface WriteContext extends ReadMergeModifyContext { // src/core/ObservableQuery.ts:121:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts // src/core/QueryManager.ts:159:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts // src/core/QueryManager.ts:414:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts -// src/core/watchQueryOptions.ts:277:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts +// src/core/watchQueryOptions.ts:271:2 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts // src/link/http/selectHttpOptionsAndBody.ts:128:32 - (ae-forgotten-export) The symbol "HttpQueryOptions" needs to be exported by the entry point index.d.ts // src/react/hooks/useBackgroundQuery.ts:38:3 - (ae-forgotten-export) The symbol "SubscribeToMoreFunction" needs to be exported by the entry point index.d.ts // src/react/hooks/useBackgroundQuery.ts:54:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts diff --git a/.changeset/fluffy-shoes-applaud.md b/.changeset/fluffy-shoes-applaud.md new file mode 100644 index 00000000000..f2ed2699dec --- /dev/null +++ b/.changeset/fluffy-shoes-applaud.md @@ -0,0 +1,5 @@ +--- +"@apollo/client": major +--- + +Remove deprecated `partialRefetch` option. diff --git a/.size-limits.json b/.size-limits.json index 7a903b40f8b..fe44b136ba5 100644 --- a/.size-limits.json +++ b/.size-limits.json @@ -1,4 +1,4 @@ { - "dist/apollo-client.min.cjs": 41617, + "dist/apollo-client.min.cjs": 41536, "import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 34350 } diff --git a/src/__tests__/ApolloClient.ts b/src/__tests__/ApolloClient.ts index e147de233a4..ed48a83cc47 100644 --- a/src/__tests__/ApolloClient.ts +++ b/src/__tests__/ApolloClient.ts @@ -2724,7 +2724,6 @@ describe("ApolloClient", () => { pollInterval: 100, notifyOnNetworkStatusChange: true, returnPartialData: true, - partialRefetch: true, }, }, }); diff --git a/src/core/ObservableQuery.ts b/src/core/ObservableQuery.ts index 2a70e6e9097..2f35f7731ba 100644 --- a/src/core/ObservableQuery.ts +++ b/src/core/ObservableQuery.ts @@ -308,7 +308,6 @@ export class ObservableQuery< if ( __DEV__ && !diff.complete && - !this.options.partialRefetch && !result.loading && !result.data && !result.error diff --git a/src/core/__tests__/QueryManager/index.ts b/src/core/__tests__/QueryManager/index.ts index 5d6d9592bcc..8fb823b72e1 100644 --- a/src/core/__tests__/QueryManager/index.ts +++ b/src/core/__tests__/QueryManager/index.ts @@ -635,7 +635,6 @@ describe("QueryManager", () => { watchQuery: { fetchPolicy: "cache-and-network", returnPartialData: false, - partialRefetch: true, notifyOnNetworkStatusChange: true, }, query: { diff --git a/src/core/watchQueryOptions.ts b/src/core/watchQueryOptions.ts index 1528b1d0330..511d0e2c970 100644 --- a/src/core/watchQueryOptions.ts +++ b/src/core/watchQueryOptions.ts @@ -78,9 +78,6 @@ export interface QueryOptions { /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#returnPartialData:member} */ returnPartialData?: boolean; - /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#partialRefetch:member} */ - partialRefetch?: boolean; - /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#canonizeResults:member} */ canonizeResults?: boolean; } @@ -136,9 +133,6 @@ export interface SharedWatchQueryOptions< /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#returnPartialData:member} */ returnPartialData?: boolean; - /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#partialRefetch:member} */ - partialRefetch?: boolean; - /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#canonizeResults:member} */ canonizeResults?: boolean; diff --git a/src/react/hooks/__tests__/useQuery.test.tsx b/src/react/hooks/__tests__/useQuery.test.tsx index 2edf19d2a36..39f85b1ffd8 100644 --- a/src/react/hooks/__tests__/useQuery.test.tsx +++ b/src/react/hooks/__tests__/useQuery.test.tsx @@ -6747,215 +6747,6 @@ describe("useQuery Hook", () => { }); }); - describe("Partial refetch", () => { - it("should attempt a refetch when data is missing and partialRefetch is true", async () => { - using consoleSpy = spyOnConsole("error"); - const query = gql` - { - hello - } - `; - - const link = mockSingleLink( - { - request: { query }, - result: { data: {} }, - delay: 20, - }, - { - request: { query }, - result: { data: { hello: "world" } }, - delay: 20, - } - ); - - const client = new ApolloClient({ - link, - cache: new InMemoryCache(), - }); - - const { result } = renderHook( - () => - useQuery(query, { - partialRefetch: true, - notifyOnNetworkStatusChange: true, - }), - { - wrapper: ({ children }) => ( - {children} - ), - } - ); - - expect(result.current.loading).toBe(true); - expect(result.current.data).toBe(undefined); - expect(result.current.error).toBe(undefined); - expect(result.current.networkStatus).toBe(NetworkStatus.loading); - - await waitFor( - () => { - expect(result.current.networkStatus).toBe(NetworkStatus.refetch); - }, - { interval: 1 } - ); - expect(result.current.loading).toBe(true); - expect(result.current.data).toBe(undefined); - expect(result.current.error).toBe(undefined); - - expect(consoleSpy.error).toHaveBeenCalledTimes(1); - expect(consoleSpy.error.mock.calls[0][0]).toMatch("Missing field"); - - await waitFor( - () => { - expect(result.current.networkStatus).toBe(NetworkStatus.ready); - }, - { interval: 1 } - ); - - expect(result.current.loading).toBe(false); - expect(result.current.data).toEqual({ hello: "world" }); - expect(result.current.error).toBe(undefined); - }); - - it("should attempt a refetch when data is missing and partialRefetch is true 2", async () => { - const query = gql` - query people { - allPeople(first: 1) { - people { - name - } - } - } - `; - - const data = { - allPeople: { people: [{ name: "Luke Skywalker" }] }, - }; - - using consoleSpy = spyOnConsole("error"); - const link = mockSingleLink( - { request: { query }, result: { data: {} }, delay: 20 }, - { request: { query }, result: { data }, delay: 20 } - ); - - const client = new ApolloClient({ - link, - cache: new InMemoryCache(), - }); - - const { result } = renderHook( - () => - useQuery(query, { - partialRefetch: true, - notifyOnNetworkStatusChange: true, - }), - { - wrapper: ({ children }) => ( - {children} - ), - } - ); - - expect(result.current.loading).toBe(true); - expect(result.current.data).toBe(undefined); - expect(result.current.error).toBe(undefined); - expect(result.current.networkStatus).toBe(NetworkStatus.loading); - - await waitFor( - () => { - expect(result.current.networkStatus).toBe(NetworkStatus.refetch); - }, - { interval: 1 } - ); - expect(result.current.loading).toBe(true); - expect(result.current.data).toBe(undefined); - expect(result.current.error).toBe(undefined); - - expect(consoleSpy.error).toHaveBeenCalledTimes(1); - expect(consoleSpy.error.mock.calls[0][0]).toMatch("Missing field"); - - await waitFor( - () => { - expect(result.current.networkStatus).toBe(NetworkStatus.ready); - }, - { interval: 1 } - ); - expect(result.current.loading).toBe(false); - expect(result.current.data).toEqual(data); - expect(result.current.error).toBe(undefined); - }); - - it("should attempt a refetch when data is missing, partialRefetch is true and addTypename is false for the cache", async () => { - using consoleSpy = spyOnConsole("error"); - const query = gql` - { - hello - } - `; - - const link = mockSingleLink( - { - request: { query }, - result: { data: {} }, - delay: 20, - }, - { - request: { query }, - result: { data: { hello: "world" } }, - delay: 20, - } - ); - - const client = new ApolloClient({ - link, - // THIS LINE IS THE ONLY DIFFERENCE FOR THIS TEST - cache: new InMemoryCache({ addTypename: false }), - }); - - const wrapper = ({ children }: any) => ( - {children} - ); - - using _disabledAct = disableActEnvironment(); - const { takeSnapshot } = await renderHookToSnapshotStream( - () => - useQuery(query, { - partialRefetch: true, - notifyOnNetworkStatusChange: true, - }), - { wrapper } - ); - - { - const result = await takeSnapshot(); - expect(result.loading).toBe(true); - expect(result.data).toBe(undefined); - expect(result.error).toBe(undefined); - expect(result.networkStatus).toBe(NetworkStatus.loading); - } - - { - const result = await takeSnapshot(); - expect(result.networkStatus).toBe(NetworkStatus.refetch); - expect(result.loading).toBe(true); - expect(result.error).toBe(undefined); - expect(result.data).toBe(undefined); - } - - const calls = consoleSpy.error.mock.calls; - expect(calls.length).toBe(1); - expect(calls[0][0]).toMatch("Missing field"); - - { - const result = await takeSnapshot(); - expect(result.networkStatus).toBe(NetworkStatus.ready); - expect(result.loading).toBe(false); - expect(result.data).toEqual({ hello: "world" }); - expect(result.error).toBe(undefined); - } - }); - }); - describe("Client Resolvers", () => { it("should receive up to date @client(always: true) fields on entity update", async () => { const query = gql` diff --git a/src/react/hooks/useQuery.ts b/src/react/hooks/useQuery.ts index a1b83c3c68c..5a51dba6eff 100644 --- a/src/react/hooks/useQuery.ts +++ b/src/react/hooks/useQuery.ts @@ -11,7 +11,6 @@ * makeWatchQueryOptions * isSSRAllowed * disableNetworkFetches - * partialRefetch * renderPromises * isSyncSSR * callbacks @@ -260,7 +259,6 @@ export function useQueryInternals< const isSyncSSR = !!renderPromises; const disableNetworkFetches = client.disableNetworkFetches; const ssrAllowed = options.ssr !== false && !options.skip; - const partialRefetch = options.partialRefetch; const makeWatchQueryOptions = createMakeWatchQueryOptions( client, @@ -301,7 +299,6 @@ export function useQueryInternals< options, watchQueryOptions, disableNetworkFetches, - partialRefetch, isSyncSSR, { onCompleted: options.onCompleted || noop, @@ -329,7 +326,6 @@ function useObservableSubscriptionResult< options: QueryHookOptions, NoInfer>, watchQueryOptions: Readonly>, disableNetworkFetches: boolean, - partialRefetch: boolean | undefined, isSyncSSR: boolean, callbacks: { onCompleted: (data: MaybeMasked) => void; @@ -410,7 +406,6 @@ function useObservableSubscriptionResult< resultData, observable, client, - partialRefetch, handleStoreChange, callbackRef.current ); @@ -445,7 +440,6 @@ function useObservableSubscriptionResult< resultData, observable, client, - partialRefetch, handleStoreChange, callbackRef.current ); @@ -468,33 +462,14 @@ function useObservableSubscriptionResult< }; }, - [ - disableNetworkFetches, - isSyncSSR, - observable, - resultData, - partialRefetch, - client, - ] + [disableNetworkFetches, isSyncSSR, observable, resultData, client] ), () => currentResultOverride || - getCurrentResult( - resultData, - observable, - callbackRef.current, - partialRefetch, - client - ), + getCurrentResult(resultData, observable, callbackRef.current, client), () => currentResultOverride || - getCurrentResult( - resultData, - observable, - callbackRef.current, - partialRefetch, - client - ) + getCurrentResult(resultData, observable, callbackRef.current, client) ); } @@ -656,7 +631,6 @@ function setResult( resultData: InternalResult, observable: ObservableQuery, client: ApolloClient, - partialRefetch: boolean | undefined, forceUpdate: () => void, callbacks: Callbacks ) { @@ -674,7 +648,7 @@ function setResult( } resultData.current = toQueryResult( - unsafeHandlePartialRefetch(nextResult, observable, partialRefetch), + nextResult, resultData.previousData, observable, client @@ -716,21 +690,17 @@ function getCurrentResult( resultData: InternalResult, observable: ObservableQuery, callbacks: Callbacks, - partialRefetch: boolean | undefined, client: ApolloClient ): InternalQueryResult { // Using this.result as a cache ensures getCurrentResult continues returning // the same (===) result object, unless state.setResult has been called, or // we're doing server rendering and therefore override the result below. if (!resultData.current) { - // WARNING: SIDE-EFFECTS IN THE RENDER FUNCTION - // this could call unsafeHandlePartialRefetch setResult( observable.getCurrentResult(), resultData, observable, client, - partialRefetch, () => {}, callbacks ); @@ -779,34 +749,6 @@ export function toQueryResult( return queryResult; } -function unsafeHandlePartialRefetch< - TData, - TVariables extends OperationVariables, ->( - result: ApolloQueryResult>, - observable: ObservableQuery, - partialRefetch: boolean | undefined -): ApolloQueryResult> { - // TODO: This code should be removed when the partialRefetch option is - // removed. I was unable to get this hook to behave reasonably in certain - // edge cases when this block was put in an effect. - if ( - result.partial && - partialRefetch && - !result.loading && - (!result.data || Object.keys(result.data).length === 0) && - observable.options.fetchPolicy !== "cache-only" - ) { - observable.refetch(); - return { - ...result, - loading: true, - networkStatus: NetworkStatus.refetch, - }; - } - return result; -} - const ssrDisabledResult = maybeDeepFreeze({ loading: true, data: void 0 as any, diff --git a/src/react/types/types.documentation.ts b/src/react/types/types.documentation.ts index f04aa9f1c9e..0fec99a7356 100644 --- a/src/react/types/types.documentation.ts +++ b/src/react/types/types.documentation.ts @@ -106,16 +106,6 @@ export interface QueryOptionsDocumentation { */ refetchWritePolicy_suspense: unknown; - /** - * If `true`, causes a query refetch if the query result is detected as partial. - * - * The default value is `false`. - * - * @deprecated - * Setting this option is unnecessary in Apollo Client 3, thanks to a more consistent application of fetch policies. It might be removed in a future release. - */ - partialRefetch: unknown; - /** * Whether to canonize cache results before returning them. Canonization * takes some extra time, but it speeds up future deep equality comparisons.