Skip to content

Commit 19b8467

Browse files
authored
Merge branch 'release-4.0' into jerel/deprecate-ws-link
2 parents 3e1c169 + fba3d9e commit 19b8467

6 files changed

Lines changed: 35 additions & 32 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ export namespace HttpLink {
8989
preserveHeaderCase?: boolean;
9090
}
9191
export interface Options {
92-
credentials?: string;
92+
credentials?: RequestCredentials;
9393
fetch?: typeof fetch;
94-
fetchOptions?: any;
94+
fetchOptions?: RequestInit;
9595
headers?: Record<string, string>;
9696
includeExtensions?: boolean;
9797
includeUnusedVariables?: boolean;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,9 +1370,9 @@ export namespace HttpLink {
13701370
preserveHeaderCase?: boolean;
13711371
}
13721372
export interface Options {
1373-
credentials?: string;
1373+
credentials?: RequestCredentials;
13741374
fetch?: typeof fetch;
1375-
fetchOptions?: any;
1375+
fetchOptions?: RequestInit;
13761376
headers?: Record<string, string>;
13771377
includeExtensions?: boolean;
13781378
includeUnusedVariables?: boolean;

.changeset/purple-eyes-divide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@apollo/client": patch
3+
---
4+
5+
The `fetchOptions` option provided to `HttpLink` and `BatchHttpLink` is now `RequestInit` instead of `any`. The `credentials` option is now a `RequestCredentials` type instead of a `string`.

src/link/batch-http/__tests__/batchHttpLink.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ describe("SharedHttpTest", () => {
719719
const variables = { params: "stub" };
720720
const link = new BatchHttpLink({
721721
uri: "/data",
722-
credentials: "same-team-yo",
722+
credentials: "include",
723723
});
724724

725725
const stream = new ObservableStream(
@@ -730,19 +730,19 @@ describe("SharedHttpTest", () => {
730730
await expect(stream).toComplete();
731731

732732
const creds = fetchMock.lastCall()![1]!.credentials;
733-
expect(creds).toBe("same-team-yo");
733+
expect(creds).toBe("include");
734734
});
735735

736736
it("prioritizes creds from the context over the setup", async () => {
737737
const variables = { params: "stub" };
738738
const middleware = new ApolloLink((operation, forward) => {
739739
operation.setContext({
740-
credentials: "same-team-yo",
740+
credentials: "omit",
741741
});
742742
return forward(operation);
743743
});
744744
const link = middleware.concat(
745-
new BatchHttpLink({ uri: "/data", credentials: "error" })
745+
new BatchHttpLink({ uri: "/data", credentials: "include" })
746746
);
747747

748748
const stream = new ObservableStream(
@@ -753,7 +753,7 @@ describe("SharedHttpTest", () => {
753753
await expect(stream).toComplete();
754754

755755
const creds = fetchMock.lastCall()![1]!.credentials;
756-
expect(creds).toBe("same-team-yo");
756+
expect(creds).toBe("omit");
757757
});
758758

759759
it("adds uri to the request from the context", async () => {
@@ -801,7 +801,7 @@ describe("SharedHttpTest", () => {
801801
return forward(operation);
802802
});
803803
const link = middleware.concat(
804-
new BatchHttpLink({ uri: "/data", credentials: "error" })
804+
new BatchHttpLink({ uri: "/data", credentials: "include" })
805805
);
806806

807807
const stream = new ObservableStream(
@@ -839,7 +839,7 @@ describe("SharedHttpTest", () => {
839839
const variables = { params: "stub" };
840840
const link = new BatchHttpLink({
841841
uri: "/data",
842-
fetchOptions: { someOption: "foo", mode: "no-cors" },
842+
fetchOptions: { mode: "no-cors" },
843843
});
844844

845845
const stream = new ObservableStream(
@@ -849,8 +849,7 @@ describe("SharedHttpTest", () => {
849849
await expect(stream).toEmitTypedValue(data);
850850
await expect(stream).toComplete();
851851

852-
const { someOption, mode, headers } = fetchMock.lastCall()![1]! as any;
853-
expect(someOption).toBe("foo");
852+
const { mode, headers } = fetchMock.lastCall()![1]! as any;
854853
expect(mode).toBe("no-cors");
855854
expect(headers["content-type"]).toBe("application/json");
856855
});
@@ -902,13 +901,13 @@ describe("SharedHttpTest", () => {
902901
const middleware = new ApolloLink((operation, forward) => {
903902
operation.setContext({
904903
fetchOptions: {
905-
someOption: "foo",
904+
mode: "cors",
906905
},
907906
});
908907
return forward(operation);
909908
});
910909
const link = middleware.concat(
911-
new BatchHttpLink({ uri: "/data", fetchOptions: { someOption: "bar" } })
910+
new BatchHttpLink({ uri: "/data", fetchOptions: { mode: "no-cors" } })
912911
);
913912

914913
const stream = new ObservableStream(
@@ -918,8 +917,8 @@ describe("SharedHttpTest", () => {
918917
await expect(stream).toEmitTypedValue(data);
919918
await expect(stream).toComplete();
920919

921-
const { someOption } = fetchMock.lastCall()![1]! as any;
922-
expect(someOption).toBe("foo");
920+
const { mode } = fetchMock.lastCall()![1]! as any;
921+
expect(mode).toBe("cors");
923922
});
924923

925924
it("allows for not sending the query with the request", async () => {

src/link/http/HttpLink.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,12 @@ export declare namespace HttpLink {
129129
/**
130130
* The credentials policy you want to use for the fetch call.
131131
*/
132-
credentials?: string;
132+
credentials?: RequestCredentials;
133133

134134
/**
135135
* Any overrides of the fetch options argument to pass to the fetch call.
136136
*/
137-
fetchOptions?: any;
137+
fetchOptions?: RequestInit;
138138

139139
/**
140140
* If set to true, use the HTTP GET method for query operations. Mutations

src/link/http/__tests__/HttpLink.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -709,27 +709,27 @@ describe("HttpLink", () => {
709709

710710
it("adds creds to the request from the setup", async () => {
711711
const variables = { params: "stub" };
712-
const link = createHttpLink({ uri: "data", credentials: "same-team-yo" });
712+
const link = createHttpLink({ uri: "data", credentials: "include" });
713713

714714
const observable = execute(link, { query: sampleQuery, variables });
715715
const stream = new ObservableStream(observable);
716716

717717
await expect(stream).toEmitTypedValue(data);
718718

719719
const creds = fetchMock.lastCall()![1]!.credentials;
720-
expect(creds).toBe("same-team-yo");
720+
expect(creds).toBe("include");
721721
});
722722

723723
it("prioritizes creds from the context over the setup", async () => {
724724
const variables = { params: "stub" };
725725
const middleware = new ApolloLink((operation, forward) => {
726726
operation.setContext({
727-
credentials: "same-team-yo",
727+
credentials: "omit",
728728
});
729729
return forward(operation);
730730
});
731731
const link = middleware.concat(
732-
createHttpLink({ uri: "data", credentials: "error" })
732+
createHttpLink({ uri: "data", credentials: "include" })
733733
);
734734

735735
const observable = execute(link, { query: sampleQuery, variables });
@@ -738,7 +738,7 @@ describe("HttpLink", () => {
738738
await expect(stream).toEmitTypedValue(data);
739739

740740
const creds = fetchMock.lastCall()![1]!.credentials;
741-
expect(creds).toBe("same-team-yo");
741+
expect(creds).toBe("omit");
742742
});
743743

744744
it("adds uri to the request from the context", async () => {
@@ -782,7 +782,7 @@ describe("HttpLink", () => {
782782
return forward(operation);
783783
});
784784
const link = middleware.concat(
785-
createHttpLink({ uri: "data", credentials: "error" })
785+
createHttpLink({ uri: "data", credentials: "include" })
786786
);
787787

788788
const observable = execute(link, { query: sampleQuery, variables });
@@ -817,16 +817,15 @@ describe("HttpLink", () => {
817817
const variables = { params: "stub" };
818818
const link = createHttpLink({
819819
uri: "data",
820-
fetchOptions: { someOption: "foo", mode: "no-cors" },
820+
fetchOptions: { mode: "no-cors" },
821821
});
822822

823823
const observable = execute(link, { query: sampleQuery, variables });
824824
const stream = new ObservableStream(observable);
825825

826826
await expect(stream).toEmitTypedValue(data);
827827

828-
const { someOption, mode, headers } = fetchMock.lastCall()![1] as any;
829-
expect(someOption).toBe("foo");
828+
const { mode, headers } = fetchMock.lastCall()![1] as any;
830829
expect(mode).toBe("no-cors");
831830
expect(headers["content-type"]).toBe("application/json");
832831
});
@@ -914,22 +913,22 @@ describe("HttpLink", () => {
914913
const middleware = new ApolloLink((operation, forward) => {
915914
operation.setContext({
916915
fetchOptions: {
917-
someOption: "foo",
916+
mode: "cors",
918917
},
919918
});
920919
return forward(operation);
921920
});
922921
const link = middleware.concat(
923-
createHttpLink({ uri: "data", fetchOptions: { someOption: "bar" } })
922+
createHttpLink({ uri: "data", fetchOptions: { mode: "no-cors" } })
924923
);
925924

926925
const observable = execute(link, { query: sampleQuery, variables });
927926
const stream = new ObservableStream(observable);
928927

929928
await expect(stream).toEmitTypedValue(data);
930929

931-
const { someOption } = fetchMock.lastCall()![1] as any;
932-
expect(someOption).toBe("foo");
930+
const { mode } = fetchMock.lastCall()![1] as any;
931+
expect(mode).toBe("cors");
933932
});
934933

935934
it("allows for not sending the query with the request", async () => {

0 commit comments

Comments
 (0)