@gambalabs/apollo 6.0.0-alpha.23 → 6.0.0-alpha.27

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/dist/config.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { C as ClientConfig } from './shared/apollo.c5299a22.mjs';
1
+ import { C as ClientConfig } from './shared/apollo.eb74b1b6.mjs';
2
2
  import 'graphql-ws';
3
3
  import '@apollo/client';
4
4
  import 'nuxt/app';
package/dist/config.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { C as ClientConfig } from './shared/apollo.c5299a22.js';
1
+ import { C as ClientConfig } from './shared/apollo.eb74b1b6.js';
2
2
  import 'graphql-ws';
3
3
  import '@apollo/client';
4
4
  import 'nuxt/app';
package/dist/module.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
- import { N as NuxtApolloConfig, C as ClientConfig } from './shared/apollo.c5299a22.mjs';
2
+ import { N as NuxtApolloConfig, C as ClientConfig } from './shared/apollo.eb74b1b6.mjs';
3
3
  export { ErrorResponse } from '@apollo/client/link/error';
4
4
  import 'graphql-ws';
5
5
  import '@apollo/client';
package/dist/module.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
- import { N as NuxtApolloConfig, C as ClientConfig } from './shared/apollo.c5299a22.js';
2
+ import { N as NuxtApolloConfig, C as ClientConfig } from './shared/apollo.eb74b1b6.js';
3
3
  export { ErrorResponse } from '@apollo/client/link/error';
4
4
  import 'graphql-ws';
5
5
  import '@apollo/client';
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gambalabs/apollo",
3
- "version": "6.0.0-alpha.23",
3
+ "version": "6.0.0-alpha.27",
4
4
  "configKey": "apollo",
5
5
  "compatibility": {
6
6
  "nuxt": "^3.0.0-rc.9"
package/dist/module.mjs CHANGED
@@ -5,7 +5,7 @@ import { useLogger, defineNuxtModule, createResolver, addTemplate, addPlugin, ad
5
5
  import GraphQLPlugin from '@rollup/plugin-graphql';
6
6
 
7
7
  const name = "@gambalabs/apollo";
8
- const version = "6.0.0-alpha.23";
8
+ const version = "6.0.0-alpha.27";
9
9
 
10
10
  const serializeConfig = (obj) => {
11
11
  if (typeof obj === "function") {
@@ -47,7 +47,20 @@ const module = defineNuxtModule({
47
47
  sameSite: "lax"
48
48
  },
49
49
  clientAwareness: false,
50
- requestMaxTimeout: 7e3
50
+ requestMaxTimeout: 7e3,
51
+ retryOptions: {
52
+ delay: {
53
+ initial: 300,
54
+ max: Infinity,
55
+ jitter: true
56
+ },
57
+ attempts: {
58
+ max: 5,
59
+ retryIf(error, operation) {
60
+ return !error;
61
+ }
62
+ }
63
+ }
51
64
  },
52
65
  async setup(options, nuxt) {
53
66
  if (!options.clients || !Object.keys(options.clients).length) {
@@ -87,6 +100,7 @@ const module = defineNuxtModule({
87
100
  v.tokenName = v?.tokenName || `apollo:${k}.token`;
88
101
  v.tokenStorage = v?.tokenStorage || options.tokenStorage;
89
102
  v.requestMaxTimeout = v?.requestMaxTimeout || options.requestMaxTimeout;
103
+ v.retryOptions = v?.retryOptions || options.retryOptions;
90
104
  if (v.cookieAttributes) {
91
105
  v.cookieAttributes = defu(v?.cookieAttributes, options.cookieAttributes);
92
106
  }
@@ -8,6 +8,7 @@ import createUploadLink from "apollo-upload-client/createUploadLink.mjs";
8
8
  import { createPersistedQueryLink } from "@apollo/client/link/persisted-queries";
9
9
  import { sha256 } from "crypto-hash";
10
10
  import { GraphQLWsLink } from "@apollo/client/link/subscriptions";
11
+ import { RetryLink } from "@apollo/client/link/retry";
11
12
  import { setContext } from "@apollo/client/link/context";
12
13
  import Pusher from "pusher-js";
13
14
  import createRestartableClient from "./ws.mjs";
@@ -92,43 +93,26 @@ export default defineNuxtPlugin((nuxtApp) => {
92
93
  if (clientConfig.persistedQueries) {
93
94
  persistedLink = createPersistedQueryLink({ sha256, useGETForHashedQueries: true });
94
95
  }
95
- const customFetch = async (uri, options) => {
96
- return new Promise((resolve, reject) => {
97
- let handledByTimeout = false;
98
- const timer = setTimeout(() => {
99
- handledByTimeout = true;
100
- nuxtApp.callHook("apollo:error", {
101
- networkError: {
102
- bodyText: `Request Exceeded timeout ${clientConfig.requestMaxTimeout}ms`,
103
- statusCode: "(failed)net::ERR_NAME_NOT_RESOLVED",
104
- options
105
- }
106
- });
107
- reject(new Error(`Request Exceeded timeout ${clientConfig.requestMaxTimeout}ms`));
108
- }, clientConfig.requestMaxTimeout);
109
- fetch(uri, options).then(async (response) => {
110
- clearTimeout(timer);
111
- if (response.status >= 300) {
112
- const errorText = await response.clone().text();
113
- nuxtApp.callHook("apollo:error", { networkError: { bodyText: errorText, statusCode: response.status, options } });
114
- }
115
- resolve(response);
116
- }).catch((e) => {
117
- if (handledByTimeout) {
118
- return;
119
- }
120
- clearTimeout(timer);
121
- nuxtApp.callHook("apollo:error", { networkError: { bodyText: "Failed to fetch", statusCode: "(failed)net::ERR_NAME_NOT_RESOLVED", options } });
122
- reject(e);
96
+ const gambaFetch = async (uri, options) => {
97
+ const abortController = new AbortController();
98
+ const timer = setTimeout(() => {
99
+ abortController.abort({
100
+ message: `Request exceeded timeout ${clientConfig.requestMaxTimeout / 1e3} seconds`,
101
+ name: "timeout"
123
102
  });
103
+ }, clientConfig.requestMaxTimeout);
104
+ return fetch(uri, {
105
+ ...options,
106
+ signal: abortController.signal
107
+ }).finally(() => {
108
+ clearTimeout(timer);
124
109
  });
125
110
  };
126
111
  const httpEndLink = createUploadLink({
127
112
  ...clientConfig?.httpLinkOptions && clientConfig.httpLinkOptions,
128
113
  uri: process.client && clientConfig.browserHttpEndpoint || clientConfig.httpEndpoint,
129
114
  headers: { ...clientConfig?.httpLinkOptions?.headers || {} },
130
- fetch: customFetch
131
- // use custom fetch instead of default fetch to handle status code
115
+ fetch: gambaFetch
132
116
  });
133
117
  const httpLink = baseLink.concat(httpEndLink);
134
118
  let wsLink = null;
@@ -187,6 +171,9 @@ export default defineNuxtPlugin((nuxtApp) => {
187
171
  const errorLink = onError((err) => {
188
172
  nuxtApp.callHook("apollo:error", err);
189
173
  });
174
+ const retryLink = new RetryLink({
175
+ ...clientConfig.retryOptions
176
+ });
190
177
  const link = pusherLink ? ApolloLink.from([
191
178
  errorLink,
192
179
  baseLink,
@@ -197,13 +184,13 @@ export default defineNuxtPlugin((nuxtApp) => {
197
184
  const definition = getMainDefinition(query);
198
185
  return definition.kind === "OperationDefinition" && definition.operation === "query";
199
186
  },
200
- ApolloLink.from([persistedLink, httpEndLink]),
201
- httpEndLink
187
+ ApolloLink.from([persistedLink, retryLink, httpEndLink]),
188
+ ApolloLink.from([retryLink, httpEndLink])
202
189
  )
203
- ] : [httpEndLink]
190
+ ] : [retryLink, httpEndLink]
204
191
  ]) : ApolloLink.from([
205
192
  errorLink,
206
- ...!wsLink ? [httpLink] : [
193
+ ...!wsLink ? [retryLink, httpLink] : [
207
194
  ...clientConfig?.websocketsOnly ? [wsLink] : [
208
195
  split(
209
196
  ({ query }) => {
@@ -211,7 +198,7 @@ export default defineNuxtPlugin((nuxtApp) => {
211
198
  return definition.kind === "OperationDefinition" && definition.operation === "subscription";
212
199
  },
213
200
  wsLink,
214
- httpLink
201
+ ApolloLink.from([retryLink, httpLink])
215
202
  )
216
203
  ]
217
204
  ]
@@ -40,6 +40,9 @@ class PusherLink extends ApolloLink {
40
40
  }
41
41
  const event = data?.extensions?.lighthouse_subscriptions.event ?? 'lighthouse-subscription'
42
42
  this.subscribeToChannel(subscriptionChannel, event, observer)
43
+ },
44
+ error: (networkError) => {
45
+ observer.error(networkError)
43
46
  }
44
47
  })
45
48
 
@@ -14,6 +14,18 @@ type Pusher = {
14
14
  activityTimeout: number;
15
15
  }
16
16
 
17
+ type RetryOptions = {
18
+ delay: {
19
+ initial: number
20
+ max: number
21
+ jitter: boolean
22
+ }
23
+ attempts: {
24
+ max: number
25
+ retryIf: (error: any, operation: any) => boolean
26
+ }
27
+ }
28
+
17
29
  type ClientConfig = {
18
30
  /**
19
31
  * The GraphQL endpoint.
@@ -133,6 +145,12 @@ type ClientConfig = {
133
145
  * @default false
134
146
  */
135
147
  persistedQueries?: boolean
148
+
149
+ /**
150
+ * options for Retry link
151
+ */
152
+
153
+ retryOptions?: Partial<RetryOptions>
136
154
  };
137
155
 
138
156
  interface NuxtApolloConfig<T = false> {
@@ -211,6 +229,11 @@ interface NuxtApolloConfig<T = false> {
211
229
  * @default false
212
230
  */
213
231
  clientAwareness?: boolean
232
+
233
+ /**
234
+ * options for Retry link
235
+ */
236
+ retryOptions?: Partial<RetryOptions>
214
237
  }
215
238
 
216
239
  export type { ClientConfig as C, NuxtApolloConfig as N };
@@ -14,6 +14,18 @@ type Pusher = {
14
14
  activityTimeout: number;
15
15
  }
16
16
 
17
+ type RetryOptions = {
18
+ delay: {
19
+ initial: number
20
+ max: number
21
+ jitter: boolean
22
+ }
23
+ attempts: {
24
+ max: number
25
+ retryIf: (error: any, operation: any) => boolean
26
+ }
27
+ }
28
+
17
29
  type ClientConfig = {
18
30
  /**
19
31
  * The GraphQL endpoint.
@@ -133,6 +145,12 @@ type ClientConfig = {
133
145
  * @default false
134
146
  */
135
147
  persistedQueries?: boolean
148
+
149
+ /**
150
+ * options for Retry link
151
+ */
152
+
153
+ retryOptions?: Partial<RetryOptions>
136
154
  };
137
155
 
138
156
  interface NuxtApolloConfig<T = false> {
@@ -211,6 +229,11 @@ interface NuxtApolloConfig<T = false> {
211
229
  * @default false
212
230
  */
213
231
  clientAwareness?: boolean
232
+
233
+ /**
234
+ * options for Retry link
235
+ */
236
+ retryOptions?: Partial<RetryOptions>
214
237
  }
215
238
 
216
239
  export type { ClientConfig as C, NuxtApolloConfig as N };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gambalabs/apollo",
3
- "version": "6.0.0-alpha.23",
3
+ "version": "6.0.0-alpha.27",
4
4
  "license": "MIT",
5
5
  "repository": "https://github.com/GambaLabs/apollo",
6
6
  "homepage": "https://apollo.nuxtjs.org",