From 755649035aee9a1e8db97a6e30306b58ab4349e7 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Tue, 15 Jun 2021 19:40:07 -0400 Subject: [PATCH] Rename `useObservableQuery` to `useBackgroundQuery`. --- src/__tests__/__snapshots__/exports.ts.snap | 6 +++--- ...est.tsx.snap => useBackgroundQuery.test.tsx.snap} | 2 +- ...bleQuery.test.tsx => useBackgroundQuery.test.tsx} | 12 ++++++------ src/react/hooks/index.ts | 2 +- .../{useObservableQuery.ts => useBackgroundQuery.ts} | 10 +++++----- 5 files changed, 16 insertions(+), 16 deletions(-) rename src/react/hooks/__tests__/__snapshots__/{useObservableQuery.test.tsx.snap => useBackgroundQuery.test.tsx.snap} (93%) rename src/react/hooks/__tests__/{useObservableQuery.test.tsx => useBackgroundQuery.test.tsx} (97%) rename src/react/hooks/{useObservableQuery.ts => useBackgroundQuery.ts} (93%) diff --git a/src/__tests__/__snapshots__/exports.ts.snap b/src/__tests__/__snapshots__/exports.ts.snap index ee7c4797c75..962575a1d74 100644 --- a/src/__tests__/__snapshots__/exports.ts.snap +++ b/src/__tests__/__snapshots__/exports.ts.snap @@ -53,10 +53,10 @@ Array [ "throwServerError", "toPromise", "useApolloClient", + "useBackgroundQuery", "useFragment", "useLazyQuery", "useMutation", - "useObservableQuery", "useQuery", "useReactiveVar", "useSubscription", @@ -237,10 +237,10 @@ Array [ "parser", "resetApolloContext", "useApolloClient", + "useBackgroundQuery", "useFragment", "useLazyQuery", "useMutation", - "useObservableQuery", "useQuery", "useReactiveVar", "useSubscription", @@ -277,10 +277,10 @@ Array [ exports[`exports of public entry points @apollo/client/react/hooks 1`] = ` Array [ "useApolloClient", + "useBackgroundQuery", "useFragment", "useLazyQuery", "useMutation", - "useObservableQuery", "useQuery", "useReactiveVar", "useSubscription", diff --git a/src/react/hooks/__tests__/__snapshots__/useObservableQuery.test.tsx.snap b/src/react/hooks/__tests__/__snapshots__/useBackgroundQuery.test.tsx.snap similarity index 93% rename from src/react/hooks/__tests__/__snapshots__/useObservableQuery.test.tsx.snap rename to src/react/hooks/__tests__/__snapshots__/useBackgroundQuery.test.tsx.snap index 103a825f7dd..e023ebce4c6 100644 --- a/src/react/hooks/__tests__/__snapshots__/useObservableQuery.test.tsx.snap +++ b/src/react/hooks/__tests__/__snapshots__/useBackgroundQuery.test.tsx.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`useObservableQuery useObservableQuery avoids depending on whole query response 1`] = ` +exports[`useBackgroundQuery useBackgroundQuery avoids depending on whole query response 1`] = ` Object { "Item:1": Object { "__typename": "Item", diff --git a/src/react/hooks/__tests__/useObservableQuery.test.tsx b/src/react/hooks/__tests__/useBackgroundQuery.test.tsx similarity index 97% rename from src/react/hooks/__tests__/useObservableQuery.test.tsx rename to src/react/hooks/__tests__/useBackgroundQuery.test.tsx index 6176458d44a..281605eac84 100644 --- a/src/react/hooks/__tests__/useObservableQuery.test.tsx +++ b/src/react/hooks/__tests__/useBackgroundQuery.test.tsx @@ -4,7 +4,7 @@ import { act } from "react-dom/test-utils"; import { Subscription } from "zen-observable-ts"; import { useFragment } from "../useFragment"; -import { useObservableQuery } from "../useObservableQuery"; +import { useBackgroundQuery } from "../useBackgroundQuery"; import { itAsync, MockedProvider } from "../../../testing"; import { ApolloProvider } from "../../context"; import { @@ -19,7 +19,7 @@ import { NetworkStatus, } from "../../../core"; -describe("useObservableQuery", () => { +describe("useBackgroundQuery", () => { itAsync("can be used as a replacement for useQuery", (resolve, reject) => { type TData = { words: string[]; @@ -42,7 +42,7 @@ describe("useObservableQuery", () => { useNetworkStatus, useData, useError, - } = useObservableQuery({ + } = useBackgroundQuery({ query, notifyOnNetworkStatusChange: true, }); @@ -175,7 +175,7 @@ describe("useObservableQuery", () => { list: Item[]; }; - itAsync("useObservableQuery avoids depending on whole query response", async (resolve, reject) => { + itAsync("useBackgroundQuery avoids depending on whole query response", async (resolve, reject) => { const cache = new InMemoryCache({ typePolicies: { Item: { @@ -236,7 +236,7 @@ describe("useObservableQuery", () => { useNetworkStatus, useError, useData, - } = useObservableQuery({ + } = useBackgroundQuery({ query: listQuery, }); @@ -261,7 +261,7 @@ describe("useObservableQuery", () => { // Test that we can force a specific ObservableQuery by passing it instead // of WatchQueryOptions. - expect(useObservableQuery(observable).observable).toBe(observable); + expect(useBackgroundQuery(observable).observable).toBe(observable); return complete ? (
    diff --git a/src/react/hooks/index.ts b/src/react/hooks/index.ts index 3eb7b193820..9924af41a40 100644 --- a/src/react/hooks/index.ts +++ b/src/react/hooks/index.ts @@ -7,4 +7,4 @@ export * from './useQuery'; export * from './useSubscription'; export * from './useReactiveVar'; export * from './useFragment'; -export * from './useObservableQuery'; +export * from './useBackgroundQuery'; diff --git a/src/react/hooks/useObservableQuery.ts b/src/react/hooks/useBackgroundQuery.ts similarity index 93% rename from src/react/hooks/useObservableQuery.ts rename to src/react/hooks/useBackgroundQuery.ts index ef9d5389cdb..ad4b5674893 100644 --- a/src/react/hooks/useObservableQuery.ts +++ b/src/react/hooks/useBackgroundQuery.ts @@ -15,11 +15,11 @@ import { import { useApolloClient } from "./useApolloClient"; import { useReactiveVar } from "./useReactiveVar"; -export function useObservableQuery( +export function useBackgroundQuery( queryOrOptions: | ObservableQuery | WatchQueryOptions, -): UseObservableQueryResult { +): UseBackgroundQueryResult { const state = useInternalState(queryOrOptions); const { observable } = state; @@ -62,10 +62,10 @@ export function useObservableQuery( return state; } -export interface UseObservableQueryResult { +export interface UseBackgroundQueryResult { observable: ObservableQuery; // By returning hook functions that the component can choose to call (or not), - // useObservableQuery is technically a "higher-order hook," in the same way a + // useBackgroundQuery is technically a "higher-order hook," in the same way a // function that returns other functions is a higher-order function. useLoading(): boolean; useNetworkStatus(): NetworkStatus; @@ -74,7 +74,7 @@ export interface UseObservableQueryResult { } interface InternalState -extends UseObservableQueryResult { +extends UseBackgroundQueryResult { options: WatchQueryOptions; loadingVar: ReactiveVar; networkStatusVar: ReactiveVar;