Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 0 additions & 6 deletions .api-reports/api-report-core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import type { ApplyHKTImplementationWithDefault } from '@apollo/client/utilities
import { Cache as Cache_2 } from '@apollo/client/cache';
import { checkFetcher } from '@apollo/client/link/http';
import type { ClientAwarenessLink } from '@apollo/client/link/client-awareness';
import { ClientParseError } from '@apollo/client/link/http';
import { CombinedGraphQLErrors } from '@apollo/client/errors';
import { CombinedProtocolErrors } from '@apollo/client/errors';
import { concat } from '@apollo/client/link';
Expand Down Expand Up @@ -88,7 +87,6 @@ import { rewriteURIForGET } from '@apollo/client/link/http';
import { selectHttpOptionsAndBody } from '@apollo/client/link/http';
import { selectHttpOptionsAndBodyInternal } from '@apollo/client/link/http';
import { selectURI } from '@apollo/client/link/http';
import { serializeFetchParameter } from '@apollo/client/link/http';
import { ServerError } from '@apollo/client/errors';
import { ServerParseError } from '@apollo/client/errors';
import { setVerbosity as setLogVerbosity } from '@apollo/client/utilities/invariant';
Expand Down Expand Up @@ -388,8 +386,6 @@ export { Cache_2 as Cache }

export { checkFetcher }

export { ClientParseError }

export { CombinedGraphQLErrors }

export { CombinedProtocolErrors }
Expand Down Expand Up @@ -1031,8 +1027,6 @@ export { selectHttpOptionsAndBodyInternal }

export { selectURI }

export { serializeFetchParameter }

export { ServerError }

export { ServerParseError }
Expand Down
9 changes: 0 additions & 9 deletions .api-reports/api-report-link_http.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import { ApolloLink } from '@apollo/client/link';
import type { ASTNode } from 'graphql';
import { ClientAwarenessLink } from '@apollo/client/link/client-awareness';
import type { InvariantError } from '@apollo/client/utilities/invariant';
import type { print as print_2 } from '@apollo/client/utilities';

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

// @public (undocumented)
export type ClientParseError = InvariantError & {
parseError: Error;
};

// @public @deprecated (undocumented)
export const createHttpLink: (linkOptions?: HttpLink.Options & ClientAwarenessLink.Options) => HttpLink;

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

// @public (undocumented)
export const serializeFetchParameter: (p: any, label: string) => string;

// (No @packageDocumentation comment for this package)

```
15 changes: 0 additions & 15 deletions .api-reports/api-report.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -679,13 +679,6 @@ class ClientAwarenessLink extends ApolloLink {
constructor(constructorOptions?: ClientAwarenessLink.Options);
}

// Warning: (ae-forgotten-export) The symbol "InvariantError" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export type ClientParseError = InvariantError & {
parseError: Error;
};

// Warning: (ae-forgotten-export) The symbol "Prettify" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "MergeUnions" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "ExtractByMatchingTypeNames" needs to be exported by the entry point index.d.ts
Expand Down Expand Up @@ -1566,11 +1559,6 @@ interface InvalidateModifier {
// @public (undocumented)
const _invalidateModifier: unique symbol;

// @public (undocumented)
class InvariantError extends Error {
constructor(message?: string);
}

// @internal @deprecated (undocumented)
type IsAny<T> = 0 extends 1 & T ? true : false;

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

// @public (undocumented)
export const serializeFetchParameter: (p: any, label: string) => string;

// @public (undocumented)
export namespace ServerError {
// (undocumented)
Expand Down
5 changes: 5 additions & 0 deletions .changeset/friendly-news-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@apollo/client": major
---

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That's a good call. Yes, the error messages from JSON.stringify suck, but it's not worth the extra complexity of maintaining an additional error and shipping out extra bundle size.

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)": 43862,
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production) (CJS)": 38777,
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\"": 33487,
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production)": 27626
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (CJS)": 43708,
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production) (CJS)": 38584,
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\"": 33364,
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production)": 27561
}
3 changes: 0 additions & 3 deletions src/__tests__/__snapshots__/exports.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ Array [
"selectHttpOptionsAndBody",
"selectHttpOptionsAndBodyInternal",
"selectURI",
"serializeFetchParameter",
"setLogVerbosity",
"split",
"version",
Expand Down Expand Up @@ -110,7 +109,6 @@ Array [
"selectHttpOptionsAndBody",
"selectHttpOptionsAndBodyInternal",
"selectURI",
"serializeFetchParameter",
"setLogVerbosity",
"split",
"version",
Expand Down Expand Up @@ -210,7 +208,6 @@ Array [
"selectHttpOptionsAndBody",
"selectHttpOptionsAndBodyInternal",
"selectURI",
"serializeFetchParameter",
]
`;

Expand Down
2 changes: 0 additions & 2 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ export {
// TODO remove: needed by @apollo/client/link/batch-http but not public
selectHttpOptionsAndBodyInternal,
selectURI,
serializeFetchParameter,
} from "@apollo/client/link/http";
export type { ClientParseError } from "@apollo/client/link/http";

/* Masking */
export type {
Expand Down
3 changes: 1 addition & 2 deletions src/link/batch-http/batchHttpLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
parseAndCheckHttpResponse,
selectHttpOptionsAndBodyInternal,
selectURI,
serializeFetchParameter,
} from "@apollo/client/link/http";
import { filterOperationVariables } from "@apollo/client/link/utils";
import { __DEV__ } from "@apollo/client/utilities/environment";
Expand Down Expand Up @@ -132,7 +131,7 @@ export class BaseBatchHttpLink extends ApolloLink {
}

try {
(options as any).body = serializeFetchParameter(loadedBody, "Payload");
(options as any).body = JSON.stringify(loadedBody);
} catch (parseError) {
return throwError(() => parseError);
}
Expand Down
3 changes: 1 addition & 2 deletions src/link/http/BaseHttpLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
selectHttpOptionsAndBodyInternal,
} from "./selectHttpOptionsAndBody.js";
import { selectURI } from "./selectURI.js";
import { serializeFetchParameter } from "./serializeFetchParameter.js";

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

Expand Down Expand Up @@ -108,7 +107,7 @@ export class BaseHttpLink extends ApolloLink {
}
chosenURI = newURI;
} else {
options.body = serializeFetchParameter(body, "Payload");
options.body = JSON.stringify(body);
}
// Prefer linkOptions.fetch (preferredFetch) if provided, and otherwise
// fall back to the *current* global window.fetch function (see issue
Expand Down
19 changes: 4 additions & 15 deletions src/link/http/__tests__/HttpLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ import {
wait,
} from "@apollo/client/testing/internal";

import type { ClientParseError } from "../serializeFetchParameter.js";

import { voidFetchDuringEachTest } from "./helpers.js";

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

const error = await stream.takeError();

expect(error.message).toMatch(/Variables map is not serializable/);
expect(error.parseError.message).toMatch(
/Converting circular structure to JSON/
);
expect(error.message).toMatch(/Converting circular structure to JSON/);
});

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

const error = await stream.takeError();

expect(error.message).toMatch(/Extensions map is not serializable/);
expect(error.parseError.message).toMatch(
/Converting circular structure to JSON/
);
expect(error.message).toMatch(/Converting circular structure to JSON/);
});

it("does not need any constructor arguments", () => {
Expand Down Expand Up @@ -1115,12 +1107,9 @@ describe("HttpLink", () => {
const observable = execute(link, { query: sampleQuery, variables });
const stream = new ObservableStream(observable);

const error: ClientParseError = await stream.takeError();
const error = await stream.takeError();

expect(error.message).toMatch(/Payload is not serializable/);
expect(error.parseError.message).toMatch(
/Converting circular structure to JSON/
);
expect(error.message).toMatch(/Converting circular structure to JSON/);
});

describe("AbortController", () => {
Expand Down
17 changes: 0 additions & 17 deletions src/link/http/__tests__/serializeFetchParameter.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/link/http/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export { parseAndCheckHttpResponse } from "./parseAndCheckHttpResponse.js";
export type { ClientParseError } from "./serializeFetchParameter.js";
export { serializeFetchParameter } from "./serializeFetchParameter.js";
export {
defaultPrinter,
fallbackHttpConfig,
Expand Down
11 changes: 2 additions & 9 deletions src/link/http/rewriteURIForGET.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { HttpLink } from "./HttpLink.js";
import { serializeFetchParameter } from "./serializeFetchParameter.js";

// For GET operations, returns the given URI rewritten with parameters, or a
// parse error.
Expand All @@ -20,10 +19,7 @@ export function rewriteURIForGET(chosenURI: string, body: HttpLink.Body) {
if (body.variables) {
let serializedVariables;
try {
serializedVariables = serializeFetchParameter(
body.variables,
"Variables map"
);
serializedVariables = JSON.stringify(body.variables);
} catch (parseError) {
return { parseError };
}
Expand All @@ -32,10 +28,7 @@ export function rewriteURIForGET(chosenURI: string, body: HttpLink.Body) {
if (body.extensions) {
let serializedExtensions;
try {
serializedExtensions = serializeFetchParameter(
body.extensions,
"Extensions map"
);
serializedExtensions = JSON.stringify(body.extensions);
} catch (parseError) {
return { parseError };
}
Expand Down
22 changes: 0 additions & 22 deletions src/link/http/serializeFetchParameter.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/utilities/subscriptions/relay/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { GraphQLResponse, RequestParameters } from "relay-runtime";
import { Observable } from "relay-runtime";

import type { OperationVariables } from "@apollo/client";
import { serializeFetchParameter } from "@apollo/client";
import type { HttpLink } from "@apollo/client/link/http";
import { maybe } from "@apollo/client/utilities/internal/globals";

Expand Down Expand Up @@ -35,7 +34,7 @@ export function createFetchMultipartSubscription(

return Observable.create((sink) => {
try {
options.body = serializeFetchParameter(body, "Payload");
options.body = JSON.stringify(body);
} catch (parseError) {
sink.error(parseError as Error);
}
Expand Down