@gambalabs/apollo 6.0.0-alpha.19 → 6.0.0-alpha.20
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 +44 -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.20";
|
|
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,24 @@ 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
|
+
}
|
|
105
|
+
return response;
|
|
106
|
+
};
|
|
95
107
|
const httpEndLink = createUploadLink({
|
|
96
108
|
...clientConfig?.httpLinkOptions && clientConfig.httpLinkOptions,
|
|
97
109
|
uri: process.client && clientConfig.browserHttpEndpoint || clientConfig.httpEndpoint,
|
|
98
|
-
headers: { ...clientConfig?.httpLinkOptions?.headers || {} }
|
|
110
|
+
headers: { ...clientConfig?.httpLinkOptions?.headers || {} },
|
|
111
|
+
fetch: customFetch
|
|
112
|
+
// use custom fetch instead of default fetch to handle status code
|
|
99
113
|
});
|
|
100
114
|
const httpLink = baseLink.concat(httpEndLink);
|
|
101
115
|
let wsLink = null;
|
|
@@ -121,23 +135,34 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
121
135
|
}
|
|
122
136
|
let pusherLink = null;
|
|
123
137
|
if (process.client && clientConfig.pusher) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
138
|
+
const pusherObj = new Pusher(clientConfig.pusher.pusherAppKey, {
|
|
139
|
+
wsHost: clientConfig.pusher.wsHost,
|
|
140
|
+
wsPort: clientConfig.pusher.wsPort,
|
|
141
|
+
forceTLS: clientConfig.pusher.forceTLS,
|
|
142
|
+
disableStats: true,
|
|
143
|
+
enabledTransports: ["ws", "wss"],
|
|
144
|
+
cluster: clientConfig.pusher.cluster,
|
|
145
|
+
activityTimeout: clientConfig.pusher.activityTimeout,
|
|
146
|
+
reconnect: {
|
|
147
|
+
auto: true
|
|
148
|
+
},
|
|
149
|
+
channelAuthorization: {
|
|
150
|
+
endpoint: clientConfig.pusher.channelEndpoint,
|
|
151
|
+
headersProvider() {
|
|
152
|
+
const { token: csrfToken } = nuxtApp.$csrfToken();
|
|
153
|
+
const { token: authToken } = nuxtApp.$authToken();
|
|
154
|
+
return { "X-CSRF-Token": csrfToken.value, authorization: `Bearer ${authToken.value}` };
|
|
139
155
|
}
|
|
140
|
-
}
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
const handleVisibilityChange = () => {
|
|
159
|
+
if (document.visibilityState === "visible" && pusherObj.connection.state !== "connected") {
|
|
160
|
+
pusherObj.connect();
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
document.addEventListener("visibilitychange", handleVisibilityChange);
|
|
164
|
+
pusherLink = new PusherLink({
|
|
165
|
+
pusher: pusherObj
|
|
141
166
|
});
|
|
142
167
|
}
|
|
143
168
|
const errorLink = onError((err) => {
|