Skip to content

Commit

Permalink
Rename useObservableQuery to useBackgroundQuery.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed Dec 10, 2021
1 parent d7cd7eb commit dce43ed
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/__tests__/__snapshots__/exports.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ Array [
"throwServerError",
"toPromise",
"useApolloClient",
"useBackgroundQuery",
"useFragment",
"useLazyQuery",
"useMutation",
"useObservableQuery",
"useQuery",
"useReactiveVar",
"useSubscription",
Expand Down Expand Up @@ -240,10 +240,10 @@ Array [
"parser",
"resetApolloContext",
"useApolloClient",
"useBackgroundQuery",
"useFragment",
"useLazyQuery",
"useMutation",
"useObservableQuery",
"useQuery",
"useReactiveVar",
"useSubscription",
Expand Down Expand Up @@ -280,10 +280,10 @@ Array [
exports[`exports of public entry points @apollo/client/react/hooks 1`] = `
Array [
"useApolloClient",
"useBackgroundQuery",
"useFragment",
"useLazyQuery",
"useMutation",
"useObservableQuery",
"useQuery",
"useReactiveVar",
"useSubscription",
Expand Down
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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[];
Expand All @@ -42,7 +42,7 @@ describe("useObservableQuery", () => {
useNetworkStatus,
useData,
useError,
} = useObservableQuery({
} = useBackgroundQuery({
query,
notifyOnNetworkStatusChange: true,
});
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -236,7 +236,7 @@ describe("useObservableQuery", () => {
useNetworkStatus,
useError,
useData,
} = useObservableQuery({
} = useBackgroundQuery({
query: listQuery,
});

Expand All @@ -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 ? (
<ol>
Expand Down
2 changes: 1 addition & 1 deletion src/react/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export * from './useQuery';
export * from './useSubscription';
export * from './useReactiveVar';
export * from './useFragment';
export * from './useObservableQuery';
export * from './useBackgroundQuery';
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import {
import { useApolloClient } from "./useApolloClient";
import { useReactiveVar } from "./useReactiveVar";

export function useObservableQuery<TData, TVars>(
export function useBackgroundQuery<TData, TVars>(
queryOrOptions:
| ObservableQuery<TData, TVars>
| WatchQueryOptions<TVars, TData>,
): UseObservableQueryResult<TData, TVars> {
): UseBackgroundQueryResult<TData, TVars> {
const state = useInternalState(queryOrOptions);
const { observable } = state;

Expand Down Expand Up @@ -62,10 +62,10 @@ export function useObservableQuery<TData, TVars>(
return state;
}

export interface UseObservableQueryResult<TData, TVars> {
export interface UseBackgroundQueryResult<TData, TVars> {
observable: ObservableQuery<TData, TVars>;
// 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;
Expand All @@ -74,7 +74,7 @@ export interface UseObservableQueryResult<TData, TVars> {
}

interface InternalState<TData, TVars>
extends UseObservableQueryResult<TData, TVars> {
extends UseBackgroundQueryResult<TData, TVars> {
options: WatchQueryOptions<TVars, TData>;
loadingVar: ReactiveVar<boolean>;
networkStatusVar: ReactiveVar<NetworkStatus>;
Expand Down

0 comments on commit dce43ed

Please sign in to comment.