@gambalabs/apollo 6.0.0-alpha.23 → 6.0.0-alpha.25
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 +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/module.d.mts +1 -1
- package/dist/module.d.ts +1 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +16 -2
- package/dist/runtime/plugin.mjs +22 -36
- package/dist/runtime/pusher.mjs +3 -0
- package/dist/shared/{apollo.c5299a22.d.mts → apollo.eb74b1b6.d.mts} +23 -0
- package/dist/shared/{apollo.c5299a22.d.ts → apollo.eb74b1b6.d.ts} +23 -0
- package/package.json +1 -1
package/dist/config.d.mts
CHANGED
package/dist/config.d.ts
CHANGED
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.
|
|
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.
|
|
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
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.
|
|
8
|
+
const version = "6.0.0-alpha.25";
|
|
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
|
}
|
package/dist/runtime/plugin.mjs
CHANGED
|
@@ -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,25 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
92
93
|
if (clientConfig.persistedQueries) {
|
|
93
94
|
persistedLink = createPersistedQueryLink({ sha256, useGETForHashedQueries: true });
|
|
94
95
|
}
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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);
|
|
123
|
-
});
|
|
96
|
+
const gambaFetch = async (uri, options) => {
|
|
97
|
+
let handledByTimeout = false;
|
|
98
|
+
const abortController = new AbortController();
|
|
99
|
+
const timer = setTimeout(() => {
|
|
100
|
+
handledByTimeout = true;
|
|
101
|
+
abortController.abort(`Request exceeded timeout ${clientConfig.requestMaxTimeout / 1e3} seconds`);
|
|
102
|
+
}, clientConfig.requestMaxTimeout);
|
|
103
|
+
return fetch(uri, {
|
|
104
|
+
...options,
|
|
105
|
+
signal: abortController.signal
|
|
106
|
+
}).finally(() => {
|
|
107
|
+
clearTimeout(timer);
|
|
124
108
|
});
|
|
125
109
|
};
|
|
126
110
|
const httpEndLink = createUploadLink({
|
|
127
111
|
...clientConfig?.httpLinkOptions && clientConfig.httpLinkOptions,
|
|
128
112
|
uri: process.client && clientConfig.browserHttpEndpoint || clientConfig.httpEndpoint,
|
|
129
113
|
headers: { ...clientConfig?.httpLinkOptions?.headers || {} },
|
|
130
|
-
fetch:
|
|
131
|
-
// use custom fetch instead of default fetch to handle status code
|
|
114
|
+
fetch: gambaFetch
|
|
132
115
|
});
|
|
133
116
|
const httpLink = baseLink.concat(httpEndLink);
|
|
134
117
|
let wsLink = null;
|
|
@@ -187,6 +170,9 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
187
170
|
const errorLink = onError((err) => {
|
|
188
171
|
nuxtApp.callHook("apollo:error", err);
|
|
189
172
|
});
|
|
173
|
+
const retryLink = new RetryLink({
|
|
174
|
+
...clientConfig.retryOptions
|
|
175
|
+
});
|
|
190
176
|
const link = pusherLink ? ApolloLink.from([
|
|
191
177
|
errorLink,
|
|
192
178
|
baseLink,
|
|
@@ -197,13 +183,13 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
197
183
|
const definition = getMainDefinition(query);
|
|
198
184
|
return definition.kind === "OperationDefinition" && definition.operation === "query";
|
|
199
185
|
},
|
|
200
|
-
ApolloLink.from([persistedLink, httpEndLink]),
|
|
201
|
-
httpEndLink
|
|
186
|
+
ApolloLink.from([persistedLink, retryLink, httpEndLink]),
|
|
187
|
+
ApolloLink.from([retryLink, httpEndLink])
|
|
202
188
|
)
|
|
203
|
-
] : [httpEndLink]
|
|
189
|
+
] : [retryLink, httpEndLink]
|
|
204
190
|
]) : ApolloLink.from([
|
|
205
191
|
errorLink,
|
|
206
|
-
...!wsLink ? [httpLink] : [
|
|
192
|
+
...!wsLink ? [retryLink, httpLink] : [
|
|
207
193
|
...clientConfig?.websocketsOnly ? [wsLink] : [
|
|
208
194
|
split(
|
|
209
195
|
({ query }) => {
|
|
@@ -211,7 +197,7 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
211
197
|
return definition.kind === "OperationDefinition" && definition.operation === "subscription";
|
|
212
198
|
},
|
|
213
199
|
wsLink,
|
|
214
|
-
httpLink
|
|
200
|
+
ApolloLink.from([retryLink, httpLink])
|
|
215
201
|
)
|
|
216
202
|
]
|
|
217
203
|
]
|
package/dist/runtime/pusher.mjs
CHANGED
|
@@ -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 };
|