@gambalabs/apollo 6.0.0-alpha.28 → 6.0.0-alpha.31
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/module.json +1 -1
- package/dist/module.mjs +1 -1
- package/dist/runtime/plugin.mjs +2 -2
- package/dist/runtime/pusher.mjs +27 -18
- package/package.json +1 -1
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.31";
|
|
9
9
|
|
|
10
10
|
const serializeConfig = (obj) => {
|
|
11
11
|
if (typeof obj === "function") {
|
package/dist/runtime/plugin.mjs
CHANGED
|
@@ -80,9 +80,9 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
80
80
|
}
|
|
81
81
|
};
|
|
82
82
|
});
|
|
83
|
-
const contextLink = setContext(async (
|
|
83
|
+
const contextLink = setContext(async (graphqlRequest, prevContext) => {
|
|
84
84
|
const context = ref(null);
|
|
85
|
-
await nuxtApp.callHook("apollo:link", { prevContext, context, client: key });
|
|
85
|
+
await nuxtApp.callHook("apollo:link", { prevContext, context, client: key, graphqlRequest });
|
|
86
86
|
if (!context.value) {
|
|
87
87
|
return;
|
|
88
88
|
}
|
package/dist/runtime/pusher.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ApolloLink, Observable } from '@apollo/client/core'
|
|
2
|
+
import { getMainDefinition } from '@apollo/client/utilities'
|
|
2
3
|
|
|
3
4
|
// Inspired by https://github.com/rmosolgo/graphql-ruby/blob/master/javascript_client/src/subscriptions/PusherLink.ts
|
|
4
5
|
class PusherLink extends ApolloLink {
|
|
@@ -26,25 +27,33 @@ class PusherLink extends ApolloLink {
|
|
|
26
27
|
|
|
27
28
|
let subscriptionChannel
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
30
|
+
const { query } = operation
|
|
31
|
+
const definition = getMainDefinition(query)
|
|
32
|
+
const isSubscription = definition.kind === 'OperationDefinition' && definition.operation === 'subscription'
|
|
33
|
+
const { channel, event } = operation.getContext()
|
|
34
|
+
|
|
35
|
+
if (isSubscription && channel) {
|
|
36
|
+
this.subscribeToChannel(channel, event || 'lighthouse-subscription', observer)
|
|
37
|
+
} else {
|
|
38
|
+
forward(operation).subscribe({
|
|
39
|
+
next: (data) => {
|
|
40
|
+
// If the operation has the subscription channel, it's a subscription
|
|
41
|
+
subscriptionChannel =
|
|
42
|
+
data?.extensions?.lighthouse_subscriptions.channel ?? null
|
|
43
|
+
// No subscription found in the response, pipe data through
|
|
44
|
+
if (!subscriptionChannel) {
|
|
45
|
+
observer.next(data)
|
|
46
|
+
observer.complete()
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
const event = data?.extensions?.lighthouse_subscriptions.event ?? 'lighthouse-subscription'
|
|
50
|
+
this.subscribeToChannel(subscriptionChannel, event, observer)
|
|
51
|
+
},
|
|
52
|
+
error: (networkError) => {
|
|
53
|
+
observer.error(networkError)
|
|
40
54
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
},
|
|
44
|
-
error: (networkError) => {
|
|
45
|
-
observer.error(networkError)
|
|
46
|
-
}
|
|
47
|
-
})
|
|
55
|
+
})
|
|
56
|
+
}
|
|
48
57
|
|
|
49
58
|
// Return an object that will unsubscribe_if the query was a subscription
|
|
50
59
|
return {
|