@gambalabs/apollo 6.0.0-alpha.19 → 6.0.0-alpha.21
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 +1 -1
- package/dist/runtime/plugin.mjs +47 -19
- package/dist/shared/{apollo.32d05cc9.d.mts → apollo.d410709a.d.mts} +1 -0
- package/dist/shared/{apollo.32d05cc9.d.ts → apollo.d410709a.d.ts} +1 -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.d410709a.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.d410709a.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.21";
|
|
9
9
|
|
|
10
10
|
const serializeConfig = (obj) => {
|
|
11
11
|
if (typeof obj === "function") {
|
package/dist/runtime/plugin.mjs
CHANGED
|
@@ -61,9 +61,9 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
61
61
|
}
|
|
62
62
|
};
|
|
63
63
|
});
|
|
64
|
-
const getCsrfToken = async () => {
|
|
64
|
+
const getCsrfToken = async (forceUpdate = false) => {
|
|
65
65
|
const token = ref();
|
|
66
|
-
await nuxtApp.callHook("apollo:csrf", { token, client: key });
|
|
66
|
+
await nuxtApp.callHook("apollo:csrf", { token, client: key, forceUpdate });
|
|
67
67
|
return token.value;
|
|
68
68
|
};
|
|
69
69
|
const csrfLink = setContext(async (_, { headers }) => {
|
|
@@ -92,10 +92,27 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
92
92
|
if (clientConfig.persistedQueries) {
|
|
93
93
|
persistedLink = createPersistedQueryLink({ sha256, useGETForHashedQueries: true });
|
|
94
94
|
}
|
|
95
|
+
const customFetch = async (uri, options, blocked1stCall = false) => {
|
|
96
|
+
const response = await fetch(uri, options);
|
|
97
|
+
if (response.status === 419) {
|
|
98
|
+
const token = await getCsrfToken(true);
|
|
99
|
+
if (token && !blocked1stCall) {
|
|
100
|
+
return customFetch(uri, options, !blocked1stCall);
|
|
101
|
+
} else {
|
|
102
|
+
nuxtApp.callHook("apollo:error", { networkError: { bodyText: "Session Expired", statusCode: 419 } });
|
|
103
|
+
}
|
|
104
|
+
} else if (response.status > 300) {
|
|
105
|
+
const errorText = await response.text();
|
|
106
|
+
nuxtApp.callHook("apollo:error", { networkError: { bodyText: errorText, statusCode: response.status } });
|
|
107
|
+
}
|
|
108
|
+
return response;
|
|
109
|
+
};
|
|
95
110
|
const httpEndLink = createUploadLink({
|
|
96
111
|
...clientConfig?.httpLinkOptions && clientConfig.httpLinkOptions,
|
|
97
112
|
uri: process.client && clientConfig.browserHttpEndpoint || clientConfig.httpEndpoint,
|
|
98
|
-
headers: { ...clientConfig?.httpLinkOptions?.headers || {} }
|
|
113
|
+
headers: { ...clientConfig?.httpLinkOptions?.headers || {} },
|
|
114
|
+
fetch: customFetch
|
|
115
|
+
// use custom fetch instead of default fetch to handle status code
|
|
99
116
|
});
|
|
100
117
|
const httpLink = baseLink.concat(httpEndLink);
|
|
101
118
|
let wsLink = null;
|
|
@@ -121,23 +138,34 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
121
138
|
}
|
|
122
139
|
let pusherLink = null;
|
|
123
140
|
if (process.client && clientConfig.pusher) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
141
|
+
const pusherObj = new Pusher(clientConfig.pusher.pusherAppKey, {
|
|
142
|
+
wsHost: clientConfig.pusher.wsHost,
|
|
143
|
+
wsPort: clientConfig.pusher.wsPort,
|
|
144
|
+
forceTLS: clientConfig.pusher.forceTLS,
|
|
145
|
+
disableStats: true,
|
|
146
|
+
enabledTransports: ["ws", "wss"],
|
|
147
|
+
cluster: clientConfig.pusher.cluster,
|
|
148
|
+
activityTimeout: clientConfig.pusher.activityTimeout,
|
|
149
|
+
reconnect: {
|
|
150
|
+
auto: true
|
|
151
|
+
},
|
|
152
|
+
channelAuthorization: {
|
|
153
|
+
endpoint: clientConfig.pusher.channelEndpoint,
|
|
154
|
+
headersProvider() {
|
|
155
|
+
const { token: csrfToken } = nuxtApp.$csrfToken();
|
|
156
|
+
const { token: authToken } = nuxtApp.$authToken();
|
|
157
|
+
return { "X-CSRF-Token": csrfToken.value, authorization: `Bearer ${authToken.value}` };
|
|
139
158
|
}
|
|
140
|
-
}
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
const handleVisibilityChange = () => {
|
|
162
|
+
if (document.visibilityState === "visible" && pusherObj.connection.state !== "connected") {
|
|
163
|
+
pusherObj.connect();
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
document.addEventListener("visibilitychange", handleVisibilityChange);
|
|
167
|
+
pusherLink = new PusherLink({
|
|
168
|
+
pusher: pusherObj
|
|
141
169
|
});
|
|
142
170
|
}
|
|
143
171
|
const errorLink = onError((err) => {
|