@apollo/client 4.1.1 → 4.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apollo/client",
3
- "version": "4.1.1",
3
+ "version": "4.1.3",
4
4
  "description": "A fully-featured caching GraphQL client.",
5
5
  "private": false,
6
6
  "keywords": [
@@ -1,5 +1,6 @@
1
1
  import type { DocumentNode } from "graphql";
2
+ import type { SkipToken } from "@apollo/client/react";
2
3
  import { useQuery } from "@apollo/client/react";
3
4
  import type { PrerenderStaticInternalContext } from "./prerenderStatic.js";
4
- export declare const useSSRQuery: (this: PrerenderStaticInternalContext, query: DocumentNode, options?: useQuery.Options<any, any>) => useQuery.Result<any, any>;
5
+ export declare const useSSRQuery: (this: PrerenderStaticInternalContext, query: DocumentNode, options?: useQuery.Options<any, any> | SkipToken) => useQuery.Result<any, any>;
5
6
  //# sourceMappingURL=useSSRQuery.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { NetworkStatus } from "@apollo/client";
2
- import { useApolloClient, useQuery } from "@apollo/client/react";
2
+ import { skipToken, useApolloClient, useQuery } from "@apollo/client/react";
3
3
  import { maybeDeepFreeze } from "@apollo/client/utilities/internal";
4
4
  const skipStandbyResult = maybeDeepFreeze({
5
5
  loading: false,
@@ -14,7 +14,7 @@ export const useSSRQuery = function (query, options = {}) {
14
14
  function notAllowed() {
15
15
  throw new Error("This method cannot be called during SSR.");
16
16
  }
17
- const client = useApolloClient(options.client);
17
+ const client = useApolloClient(typeof options === "object" ? options.client : undefined);
18
18
  const baseResult = {
19
19
  client,
20
20
  refetch: notAllowed,
@@ -23,16 +23,18 @@ export const useSSRQuery = function (query, options = {}) {
23
23
  updateQuery: notAllowed,
24
24
  startPolling: notAllowed,
25
25
  stopPolling: notAllowed,
26
- variables: options?.variables,
26
+ variables: typeof options === "object" ? options?.variables : undefined,
27
27
  previousData: undefined,
28
28
  };
29
- if (options.skip || options.fetchPolicy === "standby") {
29
+ if (options === skipToken ||
30
+ options.skip ||
31
+ options.fetchPolicy === "standby") {
30
32
  return withoutObservableAccess({
31
33
  ...baseResult,
32
34
  ...skipStandbyResult,
33
35
  });
34
36
  }
35
- if (options.ssr === false) {
37
+ if (options.ssr === false || options.fetchPolicy === "no-cache") {
36
38
  return withoutObservableAccess({
37
39
  ...baseResult,
38
40
  ...useQuery.ssrDisabledResult,
@@ -1 +1 @@
1
- {"version":3,"file":"useSSRQuery.js","sourceRoot":"","sources":["../../../src/react/ssr/useSSRQuery.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAIpE,MAAM,iBAAiB,GAAgC,eAAe,CAAC;IACrE,OAAO,EAAE,KAAK;IACd,IAAI,EAAE,KAAK,CAAQ;IACnB,SAAS,EAAE,OAAO;IAClB,KAAK,EAAE,KAAK,CAAC;IACb,aAAa,EAAE,aAAa,CAAC,KAAK;IAClC,OAAO,EAAE,IAAI;CACd,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,WAAW,GAAG,UAGzB,KAAmB,EACnB,UAAsC,EAAE;IAExC,aAAa,CAAC;IACd,SAAS,UAAU;QACjB,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC9D,CAAC;IACD,MAAM,MAAM,GAAG,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAE/C,MAAM,UAAU,GAGZ;QACF,MAAM;QACN,OAAO,EAAE,UAAU;QACnB,SAAS,EAAE,UAAU;QACrB,eAAe,EAAE,UAAU;QAC3B,WAAW,EAAE,UAAU;QACvB,YAAY,EAAE,UAAU;QACxB,WAAW,EAAE,UAAU;QACvB,SAAS,EAAE,OAAO,EAAE,SAAS;QAC7B,YAAY,EAAE,SAAS;KACxB,CAAC;IAEF,IAAI,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;QACtD,OAAO,uBAAuB,CAAC;YAC7B,GAAG,UAAU;YACb,GAAG,iBAAiB;SACrB,CAAC,CAAC;IACL,CAAC;IACD,IAAI,OAAO,CAAC,GAAG,KAAK,KAAK,EAAE,CAAC;QAC1B,OAAO,uBAAuB,CAAC;YAC7B,GAAG,UAAU;YACb,GAAG,QAAQ,CAAC,iBAAiB;SAC9B,CAAC,CAAC;IACL,CAAC;IAED,IAAI,UAAU,GAAG,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IACnE,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;YAC7B,KAAK;YACL,GAAG,OAAO;YACV,WAAW,EACT,CACE,OAAO,CAAC,WAAW,KAAK,cAAc;gBACtC,OAAO,CAAC,WAAW,KAAK,mBAAmB,CAC5C,CAAC,CAAC;gBACD,aAAa;gBACf,CAAC,CAAC,OAAO,CAAC,WAAW;SACxB,CAAC,CAAC;QACH,IAAI,CAAC,wBAAwB,CAAC,UAAU,EAAE,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IACtE,CAAC;IACD,OAAO;QACL,UAAU;QACV,GAAG,UAAU,CAAC,gBAAgB,EAAE;QAChC,GAAG,UAAU;KACd,CAAC;AACJ,CAAC,CAAC;AAEF,SAAS,uBAAuB,CAC9B,KAAQ;IAER,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,YAAY,EAAE;QACzC,GAAG;YACD,MAAM,IAAI,KAAK,CACb,qGAAqG,CACtG,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;IACH,OAAO,KAAY,CAAC;AACtB,CAAC","sourcesContent":["import type { DocumentNode } from \"graphql\";\n\nimport type { ObservableQuery } from \"@apollo/client\";\nimport { NetworkStatus } from \"@apollo/client\";\nimport { useApolloClient, useQuery } from \"@apollo/client/react\";\nimport { maybeDeepFreeze } from \"@apollo/client/utilities/internal\";\n\nimport type { PrerenderStaticInternalContext } from \"./prerenderStatic.js\";\n\nconst skipStandbyResult: ObservableQuery.Result<any> = maybeDeepFreeze({\n loading: false,\n data: void 0 as any,\n dataState: \"empty\",\n error: void 0,\n networkStatus: NetworkStatus.ready,\n partial: true,\n});\n\nexport const useSSRQuery = function (\n // eslint-disable-next-line react-hooks/unsupported-syntax\n this: PrerenderStaticInternalContext,\n query: DocumentNode,\n options: useQuery.Options<any, any> = {}\n): useQuery.Result<any, any> {\n \"use no memo\";\n function notAllowed(): never {\n throw new Error(\"This method cannot be called during SSR.\");\n }\n const client = useApolloClient(options.client);\n\n const baseResult: Omit<\n useQuery.Result,\n \"observable\" | \"data\" | \"error\" | \"loading\" | \"networkStatus\" | \"dataState\"\n > = {\n client,\n refetch: notAllowed,\n fetchMore: notAllowed,\n subscribeToMore: notAllowed,\n updateQuery: notAllowed,\n startPolling: notAllowed,\n stopPolling: notAllowed,\n variables: options?.variables,\n previousData: undefined,\n };\n\n if (options.skip || options.fetchPolicy === \"standby\") {\n return withoutObservableAccess({\n ...baseResult,\n ...skipStandbyResult,\n });\n }\n if (options.ssr === false) {\n return withoutObservableAccess({\n ...baseResult,\n ...useQuery.ssrDisabledResult,\n });\n }\n\n let observable = this.getObservableQuery(query, options.variables);\n if (!observable) {\n observable = client.watchQuery({\n query,\n ...options,\n fetchPolicy:\n (\n options.fetchPolicy === \"network-only\" ||\n options.fetchPolicy === \"cache-and-network\"\n ) ?\n \"cache-first\"\n : options.fetchPolicy,\n });\n this.onCreatedObservableQuery(observable, query, options.variables);\n }\n return {\n observable,\n ...observable.getCurrentResult(),\n ...baseResult,\n };\n};\n\nfunction withoutObservableAccess<T>(\n value: T\n): T & { observable: ObservableQuery<any, any> } {\n Object.defineProperty(value, \"observable\", {\n get() {\n throw new Error(\n '\"observable\" property is not accessible on skipped hooks or hook calls with `ssr: false` during SSR'\n );\n },\n });\n return value as any;\n}\n"]}
1
+ {"version":3,"file":"useSSRQuery.js","sourceRoot":"","sources":["../../../src/react/ssr/useSSRQuery.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC5E,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAIpE,MAAM,iBAAiB,GAAgC,eAAe,CAAC;IACrE,OAAO,EAAE,KAAK;IACd,IAAI,EAAE,KAAK,CAAQ;IACnB,SAAS,EAAE,OAAO;IAClB,KAAK,EAAE,KAAK,CAAC;IACb,aAAa,EAAE,aAAa,CAAC,KAAK;IAClC,OAAO,EAAE,IAAI;CACd,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,WAAW,GAAG,UAGzB,KAAmB,EACnB,UAAkD,EAAE;IAEpD,aAAa,CAAC;IACd,SAAS,UAAU;QACjB,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC9D,CAAC;IACD,MAAM,MAAM,GAAG,eAAe,CAC5B,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CACzD,CAAC;IAEF,MAAM,UAAU,GAGZ;QACF,MAAM;QACN,OAAO,EAAE,UAAU;QACnB,SAAS,EAAE,UAAU;QACrB,eAAe,EAAE,UAAU;QAC3B,WAAW,EAAE,UAAU;QACvB,YAAY,EAAE,UAAU;QACxB,WAAW,EAAE,UAAU;QACvB,SAAS,EAAE,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,SAAS;QACvE,YAAY,EAAE,SAAS;KACxB,CAAC;IAEF,IACE,OAAO,KAAK,SAAS;QACrB,OAAO,CAAC,IAAI;QACZ,OAAO,CAAC,WAAW,KAAK,SAAS,EACjC,CAAC;QACD,OAAO,uBAAuB,CAAC;YAC7B,GAAG,UAAU;YACb,GAAG,iBAAiB;SACrB,CAAC,CAAC;IACL,CAAC;IACD,IAAI,OAAO,CAAC,GAAG,KAAK,KAAK,IAAI,OAAO,CAAC,WAAW,KAAK,UAAU,EAAE,CAAC;QAChE,OAAO,uBAAuB,CAAC;YAC7B,GAAG,UAAU;YACb,GAAG,QAAQ,CAAC,iBAAiB;SAC9B,CAAC,CAAC;IACL,CAAC;IAED,IAAI,UAAU,GAAG,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IACnE,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;YAC7B,KAAK;YACL,GAAG,OAAO;YACV,WAAW,EACT,CACE,OAAO,CAAC,WAAW,KAAK,cAAc;gBACtC,OAAO,CAAC,WAAW,KAAK,mBAAmB,CAC5C,CAAC,CAAC;gBACD,aAAa;gBACf,CAAC,CAAC,OAAO,CAAC,WAAW;SACxB,CAAC,CAAC;QACH,IAAI,CAAC,wBAAwB,CAAC,UAAU,EAAE,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IACtE,CAAC;IACD,OAAO;QACL,UAAU;QACV,GAAG,UAAU,CAAC,gBAAgB,EAAE;QAChC,GAAG,UAAU;KACd,CAAC;AACJ,CAAC,CAAC;AAEF,SAAS,uBAAuB,CAC9B,KAAQ;IAER,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,YAAY,EAAE;QACzC,GAAG;YACD,MAAM,IAAI,KAAK,CACb,qGAAqG,CACtG,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;IACH,OAAO,KAAY,CAAC;AACtB,CAAC","sourcesContent":["import type { DocumentNode } from \"graphql\";\n\nimport type { ObservableQuery } from \"@apollo/client\";\nimport { NetworkStatus } from \"@apollo/client\";\nimport type { SkipToken } from \"@apollo/client/react\";\nimport { skipToken, useApolloClient, useQuery } from \"@apollo/client/react\";\nimport { maybeDeepFreeze } from \"@apollo/client/utilities/internal\";\n\nimport type { PrerenderStaticInternalContext } from \"./prerenderStatic.js\";\n\nconst skipStandbyResult: ObservableQuery.Result<any> = maybeDeepFreeze({\n loading: false,\n data: void 0 as any,\n dataState: \"empty\",\n error: void 0,\n networkStatus: NetworkStatus.ready,\n partial: true,\n});\n\nexport const useSSRQuery = function (\n // eslint-disable-next-line react-hooks/unsupported-syntax\n this: PrerenderStaticInternalContext,\n query: DocumentNode,\n options: useQuery.Options<any, any> | SkipToken = {}\n): useQuery.Result<any, any> {\n \"use no memo\";\n function notAllowed(): never {\n throw new Error(\"This method cannot be called during SSR.\");\n }\n const client = useApolloClient(\n typeof options === \"object\" ? options.client : undefined\n );\n\n const baseResult: Omit<\n useQuery.Result,\n \"observable\" | \"data\" | \"error\" | \"loading\" | \"networkStatus\" | \"dataState\"\n > = {\n client,\n refetch: notAllowed,\n fetchMore: notAllowed,\n subscribeToMore: notAllowed,\n updateQuery: notAllowed,\n startPolling: notAllowed,\n stopPolling: notAllowed,\n variables: typeof options === \"object\" ? options?.variables : undefined,\n previousData: undefined,\n };\n\n if (\n options === skipToken ||\n options.skip ||\n options.fetchPolicy === \"standby\"\n ) {\n return withoutObservableAccess({\n ...baseResult,\n ...skipStandbyResult,\n });\n }\n if (options.ssr === false || options.fetchPolicy === \"no-cache\") {\n return withoutObservableAccess({\n ...baseResult,\n ...useQuery.ssrDisabledResult,\n });\n }\n\n let observable = this.getObservableQuery(query, options.variables);\n if (!observable) {\n observable = client.watchQuery({\n query,\n ...options,\n fetchPolicy:\n (\n options.fetchPolicy === \"network-only\" ||\n options.fetchPolicy === \"cache-and-network\"\n ) ?\n \"cache-first\"\n : options.fetchPolicy,\n });\n this.onCreatedObservableQuery(observable, query, options.variables);\n }\n return {\n observable,\n ...observable.getCurrentResult(),\n ...baseResult,\n };\n};\n\nfunction withoutObservableAccess<T>(\n value: T\n): T & { observable: ObservableQuery<any, any> } {\n Object.defineProperty(value, \"observable\", {\n get() {\n throw new Error(\n '\"observable\" property is not accessible on skipped hooks or hook calls with `ssr: false` during SSR'\n );\n },\n });\n return value as any;\n}\n"]}
@@ -14,6 +14,7 @@ export function createFetchMultipartSubscription(uri, { fetch: preferredFetch, h
14
14
  };
15
15
  const options = generateOptionsForMultipartSubscription(headers || {});
16
16
  return Observable.create((sink) => {
17
+ const controller = new AbortController();
17
18
  try {
18
19
  options.body = JSON.stringify(body);
19
20
  }
@@ -22,7 +23,7 @@ export function createFetchMultipartSubscription(uri, { fetch: preferredFetch, h
22
23
  }
23
24
  const currentFetch = preferredFetch || maybe(() => fetch) || backupFetch;
24
25
  const observerNext = sink.next.bind(sink);
25
- currentFetch(uri, options)
26
+ currentFetch(uri, { ...options, signal: controller.signal })
26
27
  .then((response) => {
27
28
  const ctype = response.headers?.get("content-type");
28
29
  if (ctype !== null && /^multipart\/mixed/i.test(ctype)) {
@@ -34,8 +35,13 @@ export function createFetchMultipartSubscription(uri, { fetch: preferredFetch, h
34
35
  sink.complete();
35
36
  })
36
37
  .catch((err) => {
37
- sink.error(err);
38
+ if (err.name !== "AbortError") {
39
+ sink.error(err);
40
+ }
38
41
  });
42
+ return () => {
43
+ controller.abort();
44
+ };
39
45
  });
40
46
  };
41
47
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/utilities/subscriptions/relay/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAI3C,OAAO,EAAE,KAAK,EAAE,MAAM,2CAA2C,CAAC;AAElE,uEAAuE;AACvE,OAAO,EAAE,iBAAiB,EAAE,MAAM,iDAAiD,CAAC;AACpF,uEAAuE;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,gDAAgD,CAAC;AAEpF,MAAM,WAAW,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;AAOvC,M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T,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,CAAC,CAAC;iBACD,KAAK,CAAC,CAAC,GAAQ,EAAE,EAAE;gBAClB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAClB,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,uCAAuC,CAC9C,OAA+B;IAE/B,MAAM,OAAO,GAAoD;QAC/D,GAAG,kBAAkB,CAAC,OAAO;QAC7B,OAAO,EAAE;YACP,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC;YAClB,GAAG,kBAAkB,CAAC,OAAO;YAC7B,MAAM,EACJ,wEAAwE;SAC3E;KACF,CAAC;IACF,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type { GraphQLResponse, RequestParameters } from \"relay-runtime\";\nimport { Observable } from \"relay-runtime\";\n\nimport type { OperationVariables } from \"@apollo/client\";\nimport type { BaseHttpLink } from \"@apollo/client/link/http\";\nimport { maybe } from \"@apollo/client/utilities/internal/globals\";\n\n// eslint-disable-next-line local-rules/import-from-inside-other-export\nimport { readMultipartBody } from \"../../../link/http/parseAndCheckHttpResponse.js\";\n// eslint-disable-next-line local-rules/import-from-inside-other-export\nimport { fallbackHttpConfig } from \"../../../link/http/selectHttpOptionsAndBody.js\";\n\nconst backupFetch = maybe(() => fetch);\n\ntype CreateMultipartSubscriptionOptions = {\n fetch?: WindowOrWorkerGlobalScope[\"fetch\"];\n headers?: Record<string, string>;\n};\n\nexport function createFetchMultipartSubscription(\n uri: string,\n { fetch: preferredFetch, headers }: CreateMultipartSubscriptionOptions = {}\n) {\n return function fetchMultipartSubscription(\n operation: RequestParameters,\n variables: OperationVariables\n ): Observable<GraphQLResponse> {\n const body: BaseHttpLink.Body = {\n operationName: operation.name,\n variables,\n query: operation.text || \"\",\n };\n const options = generateOptionsForMultipartSubscription(headers || {});\n\n return Observable.create((sink) => {\n try {\n options.body = JSON.stringify(body);\n } catch (parseError) {\n sink.error(parseError as Error);\n }\n\n const currentFetch = preferredFetch || maybe(() => fetch) || backupFetch;\n const observerNext = sink.next.bind(sink);\n\n currentFetch!(uri, options)\n .then((response) => {\n const ctype = response.headers?.get(\"content-type\");\n\n if (ctype !== null && /^multipart\\/mixed/i.test(ctype)) {\n return readMultipartBody(response, observerNext);\n }\n\n sink.error(new Error(\"Expected multipart response\"));\n })\n .then(() => {\n sink.complete();\n })\n .catch((err: any) => {\n sink.error(err);\n });\n });\n };\n}\n\nfunction generateOptionsForMultipartSubscription(\n headers: Record<string, string>\n) {\n const options: { headers: Record<string, any>; body?: string } = {\n ...fallbackHttpConfig.options,\n headers: {\n ...(headers || {}),\n ...fallbackHttpConfig.headers,\n accept:\n \"multipart/mixed;boundary=graphql;subscriptionSpec=1.0,application/json\",\n },\n };\n return options;\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/utilities/subscriptions/relay/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAI3C,OAAO,EAAE,KAAK,EAAE,MAAM,2CAA2C,CAAC;AAElE,uEAAuE;AACvE,OAAO,EAAE,iBAAiB,EAAE,MAAM,iDAAiD,CAAC;AACpF,uEAAuE;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,gDAAgD,CAAC;AAEpF,MAAM,WAAW,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;AAOvC,MAAM,UAAU,gCAAgC,CAC9C,GAAW,EACX,EAAE,KAAK,EAAE,cAAc,EAAE,OAAO,KAAyC,EAAE;IAE3E,OAAO,SAAS,0BAA0B,CACxC,SAA4B,EAC5B,SAA6B;QAE7B,MAAM,IAAI,GAAsB;YAC9B,aAAa,EAAE,SAAS,CAAC,IAAI;YAC7B,SAAS;YACT,KAAK,EAAE,SAAS,CAAC,IAAI,IAAI,EAAE;SAC5B,CAAC;QACF,MAAM,OAAO,GAAG,uCAA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BAClB,CAAC;YACH,CAAC,CAAC,CAAC;YAEL,OAAO,GAAG,EAAE;gBACV,UAAU,CAAC,KAAK,EAAE,CAAC;YACrB,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,uCAAuC,CAC9C,OAA+B;IAE/B,MAAM,OAAO,GAAoD;QAC/D,GAAG,kBAAkB,CAAC,OAAO;QAC7B,OAAO,EAAE;YACP,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC;YAClB,GAAG,kBAAkB,CAAC,OAAO;YAC7B,MAAM,EACJ,wEAAwE;SAC3E;KACF,CAAC;IACF,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type { GraphQLResponse, RequestParameters } from \"relay-runtime\";\nimport { Observable } from \"relay-runtime\";\n\nimport type { OperationVariables } from \"@apollo/client\";\nimport type { BaseHttpLink } from \"@apollo/client/link/http\";\nimport { maybe } from \"@apollo/client/utilities/internal/globals\";\n\n// eslint-disable-next-line local-rules/import-from-inside-other-export\nimport { readMultipartBody } from \"../../../link/http/parseAndCheckHttpResponse.js\";\n// eslint-disable-next-line local-rules/import-from-inside-other-export\nimport { fallbackHttpConfig } from \"../../../link/http/selectHttpOptionsAndBody.js\";\n\nconst backupFetch = maybe(() => fetch);\n\ntype CreateMultipartSubscriptionOptions = {\n fetch?: WindowOrWorkerGlobalScope[\"fetch\"];\n headers?: Record<string, string>;\n};\n\nexport function createFetchMultipartSubscription(\n uri: string,\n { fetch: preferredFetch, headers }: CreateMultipartSubscriptionOptions = {}\n) {\n return function fetchMultipartSubscription(\n operation: RequestParameters,\n variables: OperationVariables\n ): Observable<GraphQLResponse> {\n const body: BaseHttpLink.Body = {\n operationName: operation.name,\n variables,\n query: operation.text || \"\",\n };\n const options = generateOptionsForMultipartSubscription(headers || {});\n\n return Observable.create((sink) => {\n const controller = new AbortController();\n\n try {\n options.body = JSON.stringify(body);\n } catch (parseError) {\n sink.error(parseError as Error);\n }\n\n const currentFetch = preferredFetch || maybe(() => fetch) || backupFetch;\n const observerNext = sink.next.bind(sink);\n\n currentFetch!(uri, { ...options, signal: controller.signal })\n .then((response) => {\n const ctype = response.headers?.get(\"content-type\");\n\n if (ctype !== null && /^multipart\\/mixed/i.test(ctype)) {\n return readMultipartBody(response, observerNext);\n }\n\n sink.error(new Error(\"Expected multipart response\"));\n })\n .then(() => {\n sink.complete();\n })\n .catch((err: any) => {\n if (err.name !== \"AbortError\") {\n sink.error(err);\n }\n });\n\n return () => {\n controller.abort();\n };\n });\n };\n}\n\nfunction generateOptionsForMultipartSubscription(\n headers: Record<string, string>\n) {\n const options: { headers: Record<string, any>; body?: string } = {\n ...fallbackHttpConfig.options,\n headers: {\n ...(headers || {}),\n ...fallbackHttpConfig.headers,\n accept:\n \"multipart/mixed;boundary=graphql;subscriptionSpec=1.0,application/json\",\n },\n };\n return options;\n}\n"]}
package/version.js CHANGED
@@ -1,3 +1,3 @@
1
- export const version = "4.1.1";
1
+ export const version = "4.1.3";
2
2
  export const build = "esm";
3
3
  //# sourceMappingURL=version.js.map