Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .api-reports/api-report-core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2022,7 +2022,7 @@ interface WriteContext extends ReadMergeModifyContext {
// src/cache/inmemory/types.ts:133:3 - (ae-forgotten-export) The symbol "KeyFieldsFunction" needs to be exported by the entry point index.d.ts
// src/core/ObservableQuery.ts:130:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
// src/core/ObservableQuery.ts:131:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts
// src/core/QueryManager.ts:187:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
// src/core/QueryManager.ts:185:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
// src/core/QueryManager.ts:455:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts

// (No @packageDocumentation comment for this package)
Expand Down
1,517 changes: 1,453 additions & 64 deletions .api-reports/api-report-react.api.md

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions .api-reports/api-report-react_internal.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import type { OperationVariables } from '@apollo/client/core';
import type { PromiseWithState } from '@apollo/client/utilities';
import type { QueryResult } from '@apollo/client/core';
import type { Unmasked } from '@apollo/client/core';
import type { useBackgroundQuery } from '@apollo/client/react/hooks';
import type { useFragment } from '@apollo/client/react/hooks';
import type { useQuery } from '@apollo/client/react/hooks';
import type { useQueryRefHandlers } from '@apollo/client/react/hooks';
import type { useReadQuery } from '@apollo/client/react/hooks';
import type { useSuspenseFragment } from '@apollo/client/react/hooks';
import type { useSuspenseQuery } from '@apollo/client/react/hooks';
import type { useBackgroundQuery } from '@apollo/client/react';
import type { useFragment } from '@apollo/client/react';
import type { useQuery } from '@apollo/client/react';
import type { useQueryRefHandlers } from '@apollo/client/react';
import type { useReadQuery } from '@apollo/client/react';
import type { useSuspenseFragment } from '@apollo/client/react';
import type { useSuspenseQuery } from '@apollo/client/react';
import type { WatchFragmentOptions } from '@apollo/client/core';
import type { WatchFragmentOptions as WatchFragmentOptions_2 } from '@apollo/client/cache';
import type { WatchFragmentResult } from '@apollo/client/cache';
Expand Down
6 changes: 2 additions & 4 deletions .api-reports/api-report-utilities.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import type { MutationOptions } from '@apollo/client/core';
import type { NameNode } from 'graphql';
import { Observable } from 'rxjs';
import type { OperationDefinitionNode } from 'graphql';
import type { OperationTypeNode } from 'graphql';
import type { OperationVariables } from '@apollo/client/core';
import type { QueryOptions } from '@apollo/client/core';
import type { Reference as Reference_2 } from '@apollo/client/cache';
Expand Down Expand Up @@ -84,7 +85,6 @@ export interface CacheSizes {
"queryManager.getDocumentInfo": number;
"removeTypenameFromVariables.getVariableDefinitions": number;
canonicalStringify: number;
parser: number;
print: number;
}

Expand All @@ -103,7 +103,7 @@ export const canUseDOM: boolean;
export const canUseLayoutEffect: boolean;

// @public (undocumented)
export function checkDocument(doc: DocumentNode): DocumentNode;
export function checkDocument(doc: DocumentNode, expectedType?: OperationTypeNode): DocumentNode;

// @public
export function cloneDeep<T>(value: T): T;
Expand Down Expand Up @@ -213,8 +213,6 @@ export const enum defaultCacheSizes {
// (undocumented)
canonicalStringify = 1000,
// (undocumented)
parser = 1000,
// (undocumented)
print = 2000
}

Expand Down
1 change: 0 additions & 1 deletion .api-reports/api-report-utilities_internal.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export const getApolloClientMemoryInternals: (() => {
transform: number | undefined;
} | undefined;
print: number | undefined;
parser: number | undefined;
canonicalStringify: number | undefined;
links: unknown[];
queryManager: {
Expand Down
3 changes: 1 addition & 2 deletions .api-reports/api-report.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,6 @@ const getApolloClientMemoryInternals: (() => {
transform: number | undefined;
} | undefined;
print: number | undefined;
parser: number | undefined;
canonicalStringify: number | undefined;
links: unknown[];
queryManager: {
Expand Down Expand Up @@ -2482,7 +2481,7 @@ interface WriteContext extends ReadMergeModifyContext {
// src/cache/inmemory/types.ts:133:3 - (ae-forgotten-export) The symbol "KeyFieldsFunction" needs to be exported by the entry point index.d.ts
// src/core/ObservableQuery.ts:130:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts
// src/core/ObservableQuery.ts:131:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts
// src/core/QueryManager.ts:187:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
// src/core/QueryManager.ts:185:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts
// src/core/QueryManager.ts:455:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts
// src/link/http/selectHttpOptionsAndBody.ts:128:1 - (ae-forgotten-export) The symbol "HttpQueryOptions" needs to be exported by the entry point index.d.ts

Expand Down
5 changes: 5 additions & 0 deletions .changeset/dirty-eagles-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@apollo/client": major
---

Removed the `@apollo/client/react/context` and `@apollo/client/react/hooks` entry points. Please use `@apollo/client/react` instead.
5 changes: 5 additions & 0 deletions .changeset/nice-dots-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@apollo/client": patch
---

Removed the `parser` cache. The functionality has been replaced in a way that doesn't need caching.
5 changes: 5 additions & 0 deletions .changeset/purple-bears-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@apollo/client": major
---

Removed the `@apollo/client/react/parser` entry point. There is no replacement.
8 changes: 4 additions & 4 deletions .size-limits.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (CJS)": 42953,
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production) (CJS)": 38324,
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\"": 32954,
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production)": 27724
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (CJS)": 42819,
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production) (CJS)": 38357,
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\"": 32736,
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production)": 27747
}
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@
"react-server": "./src/react/index.react-server.ts",
"default": "./src/react/index.ts"
},
"./react/context": "./src/react/context/index.ts",
"./react/hooks": "./src/react/hooks/index.ts",
"./react/internal": "./src/react/internal/index.ts",
"./react/parser": "./src/react/parser/index.ts",
"./react/ssr": "./src/react/ssr/index.ts",
"./testing": "./src/testing/index.ts",
"./testing/core": "./src/testing/core/index.ts",
Expand Down
42 changes: 0 additions & 42 deletions src/__tests__/__snapshots__/exports.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,8 @@ exports[`exports of public entry points @apollo/client/react 1`] = `
Array [
"ApolloConsumer",
"ApolloProvider",
"DocumentType",
"createQueryPreloader",
"getApolloContext",
"operationName",
"parser",
"skipToken",
"useApolloClient",
"useBackgroundQuery",
Expand All @@ -274,38 +271,8 @@ exports[`exports of public entry points @apollo/client/react with conditions [re
Array [
"ApolloConsumer",
"ApolloProvider",
"DocumentType",
"createQueryPreloader",
"getApolloContext",
"operationName",
"parser",
"useApolloClient",
"useBackgroundQuery",
"useFragment",
"useLazyQuery",
Comment on lines -280 to -285
Copy link
Member Author

Choose a reason for hiding this comment

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

This diff is not really nice, it looks like "removed" here and then merges in a removed entry point with the same exports further down.

"useLoadableQuery",
"useMutation",
"useQuery",
"useQueryRefHandlers",
"useReactiveVar",
"useReadQuery",
"useSubscription",
"useSuspenseFragment",
"useSuspenseQuery",
]
`;

exports[`exports of public entry points @apollo/client/react/context 1`] = `
Array [
"ApolloConsumer",
"ApolloProvider",
"getApolloContext",
]
`;

exports[`exports of public entry points @apollo/client/react/hooks 1`] = `
Array [
"skipToken",
"useApolloClient",
"useBackgroundQuery",
"useFragment",
Expand Down Expand Up @@ -335,15 +302,6 @@ Array [
]
`;

exports[`exports of public entry points @apollo/client/react/parser 1`] = `
Array [
"DocumentType",
"operationName",
"parser",
"verifyDocumentType",
]
`;

exports[`exports of public entry points @apollo/client/react/ssr 1`] = `
Array [
"getDataFromTree",
Expand Down
6 changes: 0 additions & 6 deletions src/__tests__/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ import * as linkUtils from "@apollo/client/link/utils";
import * as linkWS from "@apollo/client/link/ws";
import * as masking from "@apollo/client/masking";
import * as react from "@apollo/client/react";
import * as reactContext from "@apollo/client/react/context";
import * as reactHooks from "@apollo/client/react/hooks";
import * as reactInternal from "@apollo/client/react/internal";
import * as reactParser from "@apollo/client/react/parser";
import * as reactSSR from "@apollo/client/react/ssr";
import * as testing from "@apollo/client/testing";
import * as testingCore from "@apollo/client/testing/core";
Expand Down Expand Up @@ -90,10 +87,7 @@ describe("exports of public entry points", () => {
check("@apollo/client/link/ws", linkWS);
check("@apollo/client/masking", masking);
check("@apollo/client/react", react);
check("@apollo/client/react/context", reactContext);
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);
check("@apollo/client/testing/core", testingCore);
Expand Down
2 changes: 0 additions & 2 deletions src/core/ApolloClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,6 @@ export class ApolloClient implements DataProxy {
* ```json
*{
* limits: {
* parser: 1000,
* canonicalStringify: 1000,
* print: 2000,
* 'documentTransform.cache': 2000,
Expand All @@ -907,7 +906,6 @@ export class ApolloClient implements DataProxy {
* 'inMemoryCache.executeSubSelectedArray': 5000
* },
* sizes: {
* parser: 26,
* canonicalStringify: 4,
* print: 14,
* addTypenameDocumentTransform: [
Expand Down
14 changes: 10 additions & 4 deletions src/core/QueryManager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Trie } from "@wry/trie";
import type { DocumentNode } from "graphql";
import { OperationTypeNode } from "graphql";
import type { Subscription } from "rxjs";
import {
catchError,
Expand Down Expand Up @@ -32,7 +33,7 @@ import { execute } from "@apollo/client/link/core";
import type { MaybeMasked, Unmasked } from "@apollo/client/masking";
import { maskFragment, maskOperation } from "@apollo/client/masking";
import type { DeepPartial } from "@apollo/client/utilities";
import { print } from "@apollo/client/utilities";
import { checkDocument, print } from "@apollo/client/utilities";
import { AutoCleanedWeakCache, cacheSizes } from "@apollo/client/utilities";
import {
addNonReactiveToNamedFragments,
Expand Down Expand Up @@ -102,9 +103,6 @@ import type {

const { hasOwnProperty } = Object.prototype;

// TODO(brian): A hack until this issue is resolved (https://github.com/graphql/graphql-js/issues/3356)
Copy link
Member Author

Choose a reason for hiding this comment

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

This means we have to drop GraphQL 15 compat, which we probably should do anyways.

Copy link
Member Author

Choose a reason for hiding this comment

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

type OperationTypeNode = any;

const IGNORE = {} as IgnoreModifier;

interface MutationStoreValue {
Expand Down Expand Up @@ -276,6 +274,8 @@ export class QueryManager {
"mutation option is required. You must specify your GraphQL document in the mutation option."
);

checkDocument(mutation, OperationTypeNode.MUTATION);

invariant(
fetchPolicy === "network-only" || fetchPolicy === "no-cache",
"Mutations support only 'network-only' or 'no-cache' fetchPolicy strings. The default `network-only` behavior automatically writes mutation results to the cache. Passing `no-cache` skips the cache write."
Expand Down Expand Up @@ -788,6 +788,8 @@ export class QueryManager {
T,
TVariables extends OperationVariables = OperationVariables,
>(options: WatchQueryOptions<TVariables, T>): ObservableQuery<T, TVariables> {
checkDocument(options.query, OperationTypeNode.QUERY);

const query = this.transform(options.query);

// assign variable default values if supplied
Expand Down Expand Up @@ -824,6 +826,8 @@ export class QueryManager {
options: QueryOptions<TVars, TData>,
queryId = this.generateQueryId()
): Promise<QueryResult<MaybeMasked<TData>>> {
checkDocument(options.query, OperationTypeNode.QUERY);

const query = this.transform(options.query);

return this.fetchQuery<TData, TVars>(queryId, { ...options, query })
Expand Down Expand Up @@ -1027,6 +1031,8 @@ export class QueryManager {
extensions = {},
} = options;

checkDocument(query, OperationTypeNode.SUBSCRIPTION);

query = this.transform(query);
variables = this.getVariables(query, variables);

Expand Down
3 changes: 1 addition & 2 deletions src/link/persisted-queries/__tests__/react.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import {
createPersistedQueryLink as createPersistedQuery,
VERSION,
} from "@apollo/client/link/persisted-queries";
import { useQuery } from "@apollo/client/react";
import { ApolloProvider } from "@apollo/client/react/context";
import { ApolloProvider, useQuery } from "@apollo/client/react";
import { getDataFromTree } from "@apollo/client/react/ssr";
import { addTypenameToDocument } from "@apollo/client/utilities";

Expand Down
8 changes: 5 additions & 3 deletions src/react/context/ApolloConsumer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import { invariant } from "@apollo/client/utilities/invariant";

import { getApolloContext } from "./ApolloContext.js";

export interface ApolloConsumerProps {
children: (client: ApolloClient) => ReactTypes.ReactNode;
declare namespace ApolloConsumer {
export interface Props {
children: (client: ApolloClient) => ReactTypes.ReactNode;
}
Comment on lines +9 to +12
Copy link
Member Author

Choose a reason for hiding this comment

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

This was previously exported from /react/context, but not from /react. I don't want to add more noise to /react, and this keeps it available for use from the outside.

Same for ApolloProvider.

Copy link
Member

@jerelmiller jerelmiller Apr 3, 2025

Choose a reason for hiding this comment

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

Should this be called out in the changelog?

Copy link
Member Author

Choose a reason for hiding this comment

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

Tbh., I don't think anyone ever used those - it would probably be more noise than it would be worth.

}

export const ApolloConsumer: ReactTypes.FC<ApolloConsumerProps> = (props) => {
export const ApolloConsumer: ReactTypes.FC<ApolloConsumer.Props> = (props) => {
const ApolloContext = getApolloContext();
return (
<ApolloContext.Consumer>
Expand Down
10 changes: 6 additions & 4 deletions src/react/context/ApolloProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import { invariant } from "@apollo/client/utilities/invariant";

import { getApolloContext } from "./ApolloContext.js";

export interface ApolloProviderProps {
client: ApolloClient;
children: ReactTypes.ReactNode | ReactTypes.ReactNode[] | null;
export declare namespace ApolloProvider {
interface Props {
client: ApolloClient;
children: ReactTypes.ReactNode | ReactTypes.ReactNode[] | null;
}
}

export const ApolloProvider: ReactTypes.FC<ApolloProviderProps> = ({
export const ApolloProvider: ReactTypes.FC<ApolloProvider.Props> = ({
client,
children,
}) => {
Expand Down
2 changes: 1 addition & 1 deletion src/react/context/__tests__/ApolloConsumer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
ApolloConsumer,
ApolloProvider,
getApolloContext,
} from "@apollo/client/react/context";
} from "@apollo/client/react";

const client = new ApolloClient({
cache: new Cache(),
Expand Down
7 changes: 3 additions & 4 deletions src/react/context/__tests__/ApolloProvider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import React, { useContext } from "react";
import { InMemoryCache as Cache } from "@apollo/client/cache";
import { ApolloClient } from "@apollo/client/core";
import { ApolloLink } from "@apollo/client/link/core";
import { ApolloProvider, getApolloContext } from "@apollo/client/react/context";
import { ApolloProvider, getApolloContext } from "@apollo/client/react";

import type { ApolloContextValue } from "../ApolloContext.js";
import type { ApolloProviderProps } from "../ApolloProvider.js";

describe("<ApolloProvider /> Component", () => {
const client = new ApolloClient({
Expand Down Expand Up @@ -115,8 +114,8 @@ describe("<ApolloProvider /> Component", () => {
describe.each<
[
string,
Omit<ApolloProviderProps, "children">,
Omit<ApolloProviderProps, "children">,
Omit<ApolloProvider.Props, "children">,
Omit<ApolloProvider.Props, "children">,
]
>([["client", { client }, { client: anotherClient }]])(
"context value stability, %s prop",
Expand Down
6 changes: 0 additions & 6 deletions src/react/context/index.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/react/hooks/__tests__/useApolloClient.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import React from "react";
import { InMemoryCache } from "@apollo/client/cache";
import { ApolloClient } from "@apollo/client/core";
import { ApolloLink } from "@apollo/client/link/core";
import { ApolloProvider } from "@apollo/client/react/context";
import { useApolloClient } from "@apollo/client/react/hooks";
import { ApolloProvider, useApolloClient } from "@apollo/client/react";
import { InvariantError } from "@apollo/client/utilities/invariant";

describe("useApolloClient Hook", () => {
Expand Down
Loading