Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add react/internal entry point and update existing imports #11439

Merged
merged 11 commits into from
Dec 19, 2023
12 changes: 6 additions & 6 deletions .api-reports/api-report-react.md
Original file line number Diff line number Diff line change
Expand Up @@ -2417,12 +2417,12 @@ interface WatchQueryOptions<TVariables extends OperationVariables = OperationVar
// src/core/types.ts:201:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts
// src/core/watchQueryOptions.ts:277:3 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
// src/core/watchQueryOptions.ts:316:3 - (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts
// src/react/hooks/useBackgroundQuery.ts:30:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useBackgroundQuery.ts:31:3 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useLoadableQuery.ts:50:5 - (ae-forgotten-export) The symbol "ResetFunction" needs to be exported by the entry point index.d.ts
// src/react/query-preloader/createQueryPreloader.ts:83:5 - (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ErrorPolicy"
// src/react/query-preloader/createQueryPreloader.ts:88:5 - (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "FetchPolicy"
// src/react/query-preloader/createQueryPreloader.ts:98:5 - (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "NetworkStatus"
// src/react/hooks/useBackgroundQuery.ts:29:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useBackgroundQuery.ts:30:3 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useLoadableQuery.ts:49:5 - (ae-forgotten-export) The symbol "ResetFunction" needs to be exported by the entry point index.d.ts
// src/react/query-preloader/createQueryPreloader.ts:80:5 - (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "ErrorPolicy"
// src/react/query-preloader/createQueryPreloader.ts:85:5 - (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "FetchPolicy"
// src/react/query-preloader/createQueryPreloader.ts:95:5 - (ae-unresolved-link) The @link reference could not be resolved: The package "@apollo/client" does not have an export "NetworkStatus"

// (No @packageDocumentation comment for this package)

Expand Down
6 changes: 3 additions & 3 deletions .api-reports/api-report-react_hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -2253,9 +2253,9 @@ interface WatchQueryOptions<TVariables extends OperationVariables = OperationVar
// src/core/types.ts:201:5 - (ae-forgotten-export) The symbol "Resolver" needs to be exported by the entry point index.d.ts
// src/core/watchQueryOptions.ts:277:3 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
// src/core/watchQueryOptions.ts:316:3 - (ae-forgotten-export) The symbol "IgnoreModifier" needs to be exported by the entry point index.d.ts
// src/react/hooks/useBackgroundQuery.ts:30:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useBackgroundQuery.ts:31:3 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useLoadableQuery.ts:50:5 - (ae-forgotten-export) The symbol "ResetFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useBackgroundQuery.ts:29:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useBackgroundQuery.ts:30:3 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useLoadableQuery.ts:49:5 - (ae-forgotten-export) The symbol "ResetFunction" needs to be exported by the entry point index.d.ts

// (No @packageDocumentation comment for this package)

Expand Down
1,705 changes: 1,705 additions & 0 deletions .api-reports/api-report-react_internal.md

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions .api-reports/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -3085,9 +3085,9 @@ interface WriteContext extends ReadMergeModifyContext {
// src/core/watchQueryOptions.ts:277:3 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts
// src/core/watchQueryOptions.ts:316:3 - (ae-forgotten-export) The symbol "IgnoreModifier" 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:30:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useBackgroundQuery.ts:31:3 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useLoadableQuery.ts:50:5 - (ae-forgotten-export) The symbol "ResetFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useBackgroundQuery.ts:29:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useBackgroundQuery.ts:30:3 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts
// src/react/hooks/useLoadableQuery.ts:49:5 - (ae-forgotten-export) The symbol "ResetFunction" needs to be exported by the entry point index.d.ts

// (No @packageDocumentation comment for this package)

Expand Down
5 changes: 5 additions & 0 deletions .changeset/spicy-drinks-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@apollo/client': patch
---

Address bundling issue introduced in [#11412](https://github.com/apollographql/apollo-client/pull/11412) where the `react/cache` internals ended up duplicated in the bundle. This was due to the fact that we had a `react/hooks` entrypoint that imported these files along with the newly introduced `createQueryPreloader` function, which lived outside of the `react/hooks` folder.
4 changes: 2 additions & 2 deletions .size-limits.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"dist/apollo-client.min.cjs": 39137,
"import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32653
"dist/apollo-client.min.cjs": 39184,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Putting the minified files next to each other, there is literally no difference in them apart from the version number - I think this might have been a tad off in the upstream branch or something.

"import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32696
}
1 change: 1 addition & 0 deletions config/entryPoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const entryPoints = [
{ dirs: ["react", "context"] },
{ dirs: ["react", "hoc"] },
{ dirs: ["react", "hooks"] },
{ dirs: ["react", "internal"] },
{ dirs: ["react", "parser"] },
{ dirs: ["react", "ssr"] },
{ dirs: ["testing"], extensions: [".js", ".jsx"] },
Expand Down
11 changes: 11 additions & 0 deletions src/__tests__/__snapshots__/exports.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,17 @@ Array [
]
`;

exports[`exports of public entry points @apollo/client/react/internal 1`] = `
Array [
"InternalQueryReference",
"getSuspenseCache",
"getWrappedPromise",
"unwrapQueryRef",
"updateWrappedQueryRef",
"wrapQueryRef",
]
`;

exports[`exports of public entry points @apollo/client/react/parser 1`] = `
Array [
"DocumentType",
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import * as reactComponents from "../react/components";
import * as reactContext from "../react/context";
import * as reactHOC from "../react/hoc";
import * as reactHooks from "../react/hooks";
import * as reactInternal from "../react/internal";
import * as reactParser from "../react/parser";
import * as reactSSR from "../react/ssr";
import * as testing from "../testing";
Expand Down Expand Up @@ -71,6 +72,7 @@ describe("exports of public entry points", () => {
check("@apollo/client/react/context", reactContext);
check("@apollo/client/react/hoc", reactHOC);
check("@apollo/client/react/hooks", reactHooks);
check("@apollo/client/react/internal", reactInternal);
check("@apollo/client/react/parser", reactParser);
check("@apollo/client/react/ssr", reactSSR);
check("@apollo/client/testing", testing);
Expand Down
2 changes: 0 additions & 2 deletions src/react/cache/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/react/hooks/__tests__/useBackgroundQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import {
import { useBackgroundQuery } from "../useBackgroundQuery";
import { useReadQuery } from "../useReadQuery";
import { ApolloProvider } from "../../context";
import { QueryReference, getWrappedPromise } from "../../cache/QueryReference";
import { QueryReference, getWrappedPromise } from "../../internal";
import { InMemoryCache } from "../../../cache";
import {
SuspenseQueryHookFetchPolicy,
Expand Down
2 changes: 1 addition & 1 deletion src/react/hooks/__tests__/useQueryRefHandlers.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { UseReadQueryResult, useReadQuery } from "../useReadQuery";
import { Suspense } from "react";
import { createQueryPreloader } from "../../query-preloader/createQueryPreloader";
import userEvent from "@testing-library/user-event";
import { QueryReference } from "../../cache/QueryReference";
import { QueryReference } from "../../internal";
import { useBackgroundQuery } from "../useBackgroundQuery";
import { useLoadableQuery } from "../useLoadableQuery";
import { concatPagination } from "../../../utilities";
Expand Down
7 changes: 3 additions & 4 deletions src/react/hooks/useBackgroundQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@ import type {
} from "../../core/index.js";
import { useApolloClient } from "./useApolloClient.js";
import {
getSuspenseCache,
unwrapQueryRef,
updateWrappedQueryRef,
wrapQueryRef,
} from "../cache/QueryReference.js";
import type { QueryReference } from "../cache/QueryReference.js";
} from "../internal/index.js";
import type { CacheKey, QueryReference } from "../internal/index.js";
import type { BackgroundQueryHookOptions, NoInfer } from "../types/types.js";
import { __use } from "./internal/index.js";
import { getSuspenseCache } from "../cache/index.js";
import { useWatchQueryOptions } from "./useSuspenseQuery.js";
import type { FetchMoreFunction, RefetchFunction } from "./useSuspenseQuery.js";
import { canonicalStringify } from "../../cache/index.js";
import type { DeepPartial } from "../../utilities/index.js";
import type { CacheKey } from "../cache/types.js";
import type { SkipToken } from "./constants.js";

export type UseBackgroundQueryResult<
Expand Down
7 changes: 3 additions & 4 deletions src/react/hooks/useLoadableQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,21 @@ import type {
} from "../../core/index.js";
import { useApolloClient } from "./useApolloClient.js";
import {
getSuspenseCache,
unwrapQueryRef,
updateWrappedQueryRef,
wrapQueryRef,
} from "../cache/QueryReference.js";
import type { QueryReference } from "../cache/QueryReference.js";
} from "../internal/index.js";
import type { CacheKey, QueryReference } from "../internal/index.js";
import type { LoadableQueryHookOptions } from "../types/types.js";
import { __use, useRenderGuard } from "./internal/index.js";
import { getSuspenseCache } from "../cache/index.js";
import { useWatchQueryOptions } from "./useSuspenseQuery.js";
import type { FetchMoreFunction, RefetchFunction } from "./useSuspenseQuery.js";
import { canonicalStringify } from "../../cache/index.js";
import type {
DeepPartial,
OnlyRequiredProperties,
} from "../../utilities/index.js";
import type { CacheKey } from "../cache/types.js";
import { invariant } from "../../utilities/globals/index.js";

export type LoadQueryFunction<TVariables extends OperationVariables> = (
Expand Down
4 changes: 2 additions & 2 deletions src/react/hooks/useQueryRefHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
unwrapQueryRef,
updateWrappedQueryRef,
wrapQueryRef,
} from "../cache/QueryReference.js";
import type { QueryReference } from "../cache/QueryReference.js";
} from "../internal/index.js";
import type { QueryReference } from "../internal/index.js";
import type { OperationVariables } from "../../core/types.js";
import type { RefetchFunction, FetchMoreFunction } from "./useSuspenseQuery.js";
import type { FetchMoreQueryOptions } from "../../core/watchQueryOptions.js";
Expand Down
4 changes: 2 additions & 2 deletions src/react/hooks/useReadQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {
getWrappedPromise,
unwrapQueryRef,
updateWrappedQueryRef,
} from "../cache/QueryReference.js";
import type { QueryReference } from "../cache/QueryReference.js";
} from "../internal/index.js";
import type { QueryReference } from "../internal/index.js";
import { __use } from "./internal/index.js";
import { toApolloError } from "./useSuspenseQuery.js";
import { useSyncExternalStore } from "./useSyncExternalStore.js";
Expand Down
4 changes: 2 additions & 2 deletions src/react/hooks/useSuspenseQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import type {
NoInfer,
} from "../types/types.js";
import { __use, useDeepMemo } from "./internal/index.js";
import { getSuspenseCache } from "../cache/index.js";
import { getSuspenseCache } from "../internal/index.js";
import { canonicalStringify } from "../../cache/index.js";
import { skipToken } from "./constants.js";
import type { SkipToken } from "./constants.js";
import type { CacheKey, QueryKey } from "../cache/types.js";
import type { CacheKey, QueryKey } from "../internal/index.js";

export interface UseSuspenseQueryResult<
TData = unknown,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import type {
ObservableQuery,
OperationVariables,
WatchQueryOptions,
} from "../../core/index.js";
} from "../../../core/index.js";
import type {
ObservableSubscription,
PromiseWithState,
} from "../../utilities/index.js";
} from "../../../utilities/index.js";
import {
createFulfilledPromise,
createRejectedPromise,
} from "../../utilities/index.js";
} from "../../../utilities/index.js";
import type { QueryKey } from "./types.js";
import type { useBackgroundQuery, useReadQuery } from "../hooks/index.js";
import { wrapPromiseWithState } from "../../utilities/index.js";
import type { useBackgroundQuery, useReadQuery } from "../../hooks/index.js";
import { wrapPromiseWithState } from "../../../utilities/index.js";

type QueryRefPromise<TData> = PromiseWithState<ApolloQueryResult<TData>>;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Trie } from "@wry/trie";
import type { ObservableQuery } from "../../core/index.js";
import { canUseWeakMap } from "../../utilities/index.js";
import type { ObservableQuery } from "../../../core/index.js";
import { canUseWeakMap } from "../../../utilities/index.js";
import { InternalQueryReference } from "./QueryReference.js";
import type { CacheKey } from "./types.js";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {
ApolloLink,
InMemoryCache,
Observable,
} from "../../../core";
import { setupSimpleCase } from "../../../testing/internal";
} from "../../../../core";
import { setupSimpleCase } from "../../../../testing/internal";
import { InternalQueryReference } from "../QueryReference";

test("kicks off request immediately when created", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { SuspenseCacheOptions } from "./index.js";
import type { SuspenseCacheOptions } from "../index.js";
import { SuspenseCache } from "./SuspenseCache.js";
import type { ApolloClient } from "../../core/ApolloClient.js";
import type { ApolloClient } from "../../../core/ApolloClient.js";

declare module "../../core/ApolloClient.js" {
declare module "../../../core/ApolloClient.js" {
interface DefaultOptions {
react?: {
suspense?: Readonly<SuspenseCacheOptions>;
Expand Down
File renamed without changes.
11 changes: 11 additions & 0 deletions src/react/internal/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export { getSuspenseCache } from "./cache/getSuspenseCache.js";
export type { CacheKey, QueryKey } from "./cache/types.js";
export type { QueryReference } from "./cache/QueryReference.js";
export {
InternalQueryReference,
getWrappedPromise,
unwrapQueryRef,
updateWrappedQueryRef,
wrapQueryRef,
} from "./cache/QueryReference.js";
export type { SuspenseCacheOptions } from "./cache/SuspenseCache.js";
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
wait,
} from "../../../testing";
import { expectTypeOf } from "expect-type";
import { QueryReference, unwrapQueryRef } from "../../cache/QueryReference";
import { QueryReference, unwrapQueryRef } from "../../internal";
import { DeepPartial, Observable } from "../../../utilities";
import {
SimpleCaseData,
Expand Down
7 changes: 2 additions & 5 deletions src/react/query-preloader/createQueryPreloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ import type {
DeepPartial,
OnlyRequiredProperties,
} from "../../utilities/index.js";
import {
InternalQueryReference,
wrapQueryRef,
} from "../cache/QueryReference.js";
import type { QueryReference } from "../cache/QueryReference.js";
import { InternalQueryReference, wrapQueryRef } from "../internal/index.js";
import type { QueryReference } from "../internal/index.js";
import type { NoInfer } from "../index.js";

type VariablesOption<TVariables extends OperationVariables> =
Expand Down
2 changes: 1 addition & 1 deletion src/react/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import type {

/* QueryReference type */

export type { QueryReference } from "../cache/QueryReference.js";
export type { QueryReference } from "../internal/index.js";

/* Common types */

Expand Down
4 changes: 2 additions & 2 deletions src/testing/matchers/toBeDisposed.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { MatcherFunction } from "expect";
import type { QueryReference } from "../../react/cache/QueryReference.js";
import type { QueryReference } from "../../react/internal/index.js";
import {
InternalQueryReference,
unwrapQueryRef,
} from "../../react/cache/QueryReference.js";
} from "../../react/internal/index.js";

function isQueryRef(queryRef: unknown): queryRef is QueryReference {
try {
Expand Down
4 changes: 2 additions & 2 deletions src/testing/matchers/toHaveSuspenseCacheEntryUsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type { DocumentNode } from "graphql";
import type { OperationVariables } from "../../core/index.js";
import { ApolloClient } from "../../core/index.js";
import { canonicalStringify } from "../../cache/index.js";
import { getSuspenseCache } from "../../react/cache/index.js";
import type { CacheKey } from "../../react/cache/types.js";
import { getSuspenseCache } from "../../react/internal/index.js";
import type { CacheKey } from "../../react/internal/index.js";

export const toHaveSuspenseCacheEntryUsing: MatcherFunction<
[
Expand Down