Skip to content

Commit 292b949

Browse files
authored
Remove ClientParseError type and use JSON.stringify in place of serializeFetchParameter (#12825)
1 parent 223a409 commit 292b949

15 files changed

Lines changed: 18 additions & 110 deletions

File tree

.api-reports/api-report-core.api.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import type { ApplyHKTImplementationWithDefault } from '@apollo/client/utilities
1212
import { Cache as Cache_2 } from '@apollo/client/cache';
1313
import { checkFetcher } from '@apollo/client/link/http';
1414
import type { ClientAwarenessLink } from '@apollo/client/link/client-awareness';
15-
import { ClientParseError } from '@apollo/client/link/http';
1615
import { CombinedGraphQLErrors } from '@apollo/client/errors';
1716
import { CombinedProtocolErrors } from '@apollo/client/errors';
1817
import { concat } from '@apollo/client/link';
@@ -88,7 +87,6 @@ import { rewriteURIForGET } from '@apollo/client/link/http';
8887
import { selectHttpOptionsAndBody } from '@apollo/client/link/http';
8988
import { selectHttpOptionsAndBodyInternal } from '@apollo/client/link/http';
9089
import { selectURI } from '@apollo/client/link/http';
91-
import { serializeFetchParameter } from '@apollo/client/link/http';
9290
import { ServerError } from '@apollo/client/errors';
9391
import { ServerParseError } from '@apollo/client/errors';
9492
import { setVerbosity as setLogVerbosity } from '@apollo/client/utilities/invariant';
@@ -388,8 +386,6 @@ export { Cache_2 as Cache }
388386

389387
export { checkFetcher }
390388

391-
export { ClientParseError }
392-
393389
export { CombinedGraphQLErrors }
394390

395391
export { CombinedProtocolErrors }
@@ -1031,8 +1027,6 @@ export { selectHttpOptionsAndBodyInternal }
10311027

10321028
export { selectURI }
10331029

1034-
export { serializeFetchParameter }
1035-
10361030
export { ServerError }
10371031

10381032
export { ServerParseError }

.api-reports/api-report-link_http.api.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import { ApolloLink } from '@apollo/client/link';
88
import type { ASTNode } from 'graphql';
99
import { ClientAwarenessLink } from '@apollo/client/link/client-awareness';
10-
import type { InvariantError } from '@apollo/client/utilities/invariant';
1110
import type { print as print_2 } from '@apollo/client/utilities';
1211

1312
// @public (undocumented)
@@ -18,11 +17,6 @@ export class BaseHttpLink extends ApolloLink {
1817
// @public (undocumented)
1918
export const checkFetcher: (fetcher: typeof fetch | undefined) => void;
2019

21-
// @public (undocumented)
22-
export type ClientParseError = InvariantError & {
23-
parseError: Error;
24-
};
25-
2620
// @public @deprecated (undocumented)
2721
export const createHttpLink: (linkOptions?: HttpLink.Options & ClientAwarenessLink.Options) => HttpLink;
2822

@@ -140,9 +134,6 @@ export function selectHttpOptionsAndBodyInternal(operation: ApolloLink.Operation
140134
// @public (undocumented)
141135
export const selectURI: (operation: ApolloLink.Operation, fallbackURI?: string | ((operation: ApolloLink.Operation) => string)) => any;
142136

143-
// @public (undocumented)
144-
export const serializeFetchParameter: (p: any, label: string) => string;
145-
146137
// (No @packageDocumentation comment for this package)
147138

148139
```

.api-reports/api-report.api.md

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -679,13 +679,6 @@ class ClientAwarenessLink extends ApolloLink {
679679
constructor(constructorOptions?: ClientAwarenessLink.Options);
680680
}
681681

682-
// Warning: (ae-forgotten-export) The symbol "InvariantError" needs to be exported by the entry point index.d.ts
683-
//
684-
// @public (undocumented)
685-
export type ClientParseError = InvariantError & {
686-
parseError: Error;
687-
};
688-
689682
// Warning: (ae-forgotten-export) The symbol "Prettify" needs to be exported by the entry point index.d.ts
690683
// Warning: (ae-forgotten-export) The symbol "MergeUnions" needs to be exported by the entry point index.d.ts
691684
// Warning: (ae-forgotten-export) The symbol "ExtractByMatchingTypeNames" needs to be exported by the entry point index.d.ts
@@ -1566,11 +1559,6 @@ interface InvalidateModifier {
15661559
// @public (undocumented)
15671560
const _invalidateModifier: unique symbol;
15681561

1569-
// @public (undocumented)
1570-
class InvariantError extends Error {
1571-
constructor(message?: string);
1572-
}
1573-
15741562
// @internal @deprecated (undocumented)
15751563
type IsAny<T> = 0 extends 1 & T ? true : false;
15761564

@@ -2545,9 +2533,6 @@ export function selectHttpOptionsAndBodyInternal(operation: ApolloLink.Operation
25452533
// @public (undocumented)
25462534
export const selectURI: (operation: ApolloLink.Operation, fallbackURI?: string | ((operation: ApolloLink.Operation) => string)) => any;
25472535

2548-
// @public (undocumented)
2549-
export const serializeFetchParameter: (p: any, label: string) => string;
2550-
25512536
// @public (undocumented)
25522537
export namespace ServerError {
25532538
// (undocumented)

.changeset/friendly-news-drive.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@apollo/client": major
3+
---
4+
5+
The `serializeFetchParameter` helper is no longer exported and `JSON.stringify` is used directly. As such, the `ClientParseError` type has also been removed in favor of throwing any JSON serialize errors directly.

.size-limits.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (CJS)": 44063,
3-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production) (CJS)": 38714,
4-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\"": 33609,
5-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production)": 27632
2+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (CJS)": 43798,
3+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production) (CJS)": 38629,
4+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\"": 33543,
5+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production)": 27562
66
}

src/__tests__/__snapshots__/exports.ts.snap

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ Array [
4343
"selectHttpOptionsAndBody",
4444
"selectHttpOptionsAndBodyInternal",
4545
"selectURI",
46-
"serializeFetchParameter",
4746
"setLogVerbosity",
4847
"split",
4948
"version",
@@ -110,7 +109,6 @@ Array [
110109
"selectHttpOptionsAndBody",
111110
"selectHttpOptionsAndBodyInternal",
112111
"selectURI",
113-
"serializeFetchParameter",
114112
"setLogVerbosity",
115113
"split",
116114
"version",
@@ -210,7 +208,6 @@ Array [
210208
"selectHttpOptionsAndBody",
211209
"selectHttpOptionsAndBodyInternal",
212210
"selectURI",
213-
"serializeFetchParameter",
214211
]
215212
`;
216213

src/core/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,7 @@ export {
133133
// TODO remove: needed by @apollo/client/link/batch-http but not public
134134
selectHttpOptionsAndBodyInternal,
135135
selectURI,
136-
serializeFetchParameter,
137136
} from "@apollo/client/link/http";
138-
export type { ClientParseError } from "@apollo/client/link/http";
139137

140138
/* Masking */
141139
export type {

src/link/batch-http/batchHttpLink.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
parseAndCheckHttpResponse,
1313
selectHttpOptionsAndBodyInternal,
1414
selectURI,
15-
serializeFetchParameter,
1615
} from "@apollo/client/link/http";
1716
import { filterOperationVariables } from "@apollo/client/link/utils";
1817
import { __DEV__ } from "@apollo/client/utilities/environment";
@@ -132,7 +131,7 @@ export class BaseBatchHttpLink extends ApolloLink {
132131
}
133132

134133
try {
135-
(options as any).body = serializeFetchParameter(loadedBody, "Payload");
134+
(options as any).body = JSON.stringify(loadedBody);
136135
} catch (parseError) {
137136
return throwError(() => parseError);
138137
}

src/link/http/BaseHttpLink.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import {
2323
selectHttpOptionsAndBodyInternal,
2424
} from "./selectHttpOptionsAndBody.js";
2525
import { selectURI } from "./selectURI.js";
26-
import { serializeFetchParameter } from "./serializeFetchParameter.js";
2726

2827
const backupFetch = maybe(() => fetch);
2928

@@ -108,7 +107,7 @@ export class BaseHttpLink extends ApolloLink {
108107
}
109108
chosenURI = newURI;
110109
} else {
111-
options.body = serializeFetchParameter(body, "Payload");
110+
options.body = JSON.stringify(body);
112111
}
113112
// Prefer linkOptions.fetch (preferredFetch) if provided, and otherwise
114113
// fall back to the *current* global window.fetch function (see issue

src/link/http/__tests__/HttpLink.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ import {
3232
wait,
3333
} from "@apollo/client/testing/internal";
3434

35-
import type { ClientParseError } from "../serializeFetchParameter.js";
36-
3735
import { voidFetchDuringEachTest } from "./helpers.js";
3836

3937
const sampleQuery = gql`
@@ -395,10 +393,7 @@ describe("HttpLink", () => {
395393

396394
const error = await stream.takeError();
397395

398-
expect(error.message).toMatch(/Variables map is not serializable/);
399-
expect(error.parseError.message).toMatch(
400-
/Converting circular structure to JSON/
401-
);
396+
expect(error.message).toMatch(/Converting circular structure to JSON/);
402397
});
403398

404399
it("throws for GET if the extensions can't be stringified", async () => {
@@ -421,10 +416,7 @@ describe("HttpLink", () => {
421416

422417
const error = await stream.takeError();
423418

424-
expect(error.message).toMatch(/Extensions map is not serializable/);
425-
expect(error.parseError.message).toMatch(
426-
/Converting circular structure to JSON/
427-
);
419+
expect(error.message).toMatch(/Converting circular structure to JSON/);
428420
});
429421

430422
it("does not need any constructor arguments", () => {
@@ -1114,12 +1106,9 @@ describe("HttpLink", () => {
11141106
const observable = execute(link, { query: sampleQuery, variables });
11151107
const stream = new ObservableStream(observable);
11161108

1117-
const error: ClientParseError = await stream.takeError();
1109+
const error = await stream.takeError();
11181110

1119-
expect(error.message).toMatch(/Payload is not serializable/);
1120-
expect(error.parseError.message).toMatch(
1121-
/Converting circular structure to JSON/
1122-
);
1111+
expect(error.message).toMatch(/Converting circular structure to JSON/);
11231112
});
11241113

11251114
describe("AbortController", () => {

0 commit comments

Comments
 (0)