@gambalabs/apollo 6.0.0-alpha.30 → 6.0.0-alpha.32

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gambalabs/apollo",
3
- "version": "6.0.0-alpha.30",
3
+ "version": "6.0.0-alpha.32",
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.30";
8
+ const version = "6.0.0-alpha.32";
9
9
 
10
10
  const serializeConfig = (obj) => {
11
11
  if (typeof obj === "function") {
@@ -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
- forward(operation).subscribe({
30
- next: (data) => {
31
- // If the operation has the subscription channel, it's a subscription
32
- subscriptionChannel =
33
- data?.extensions?.lighthouse_subscriptions.channel ?? null
34
- // No subscription found in the response, pipe data through
35
- if (!subscriptionChannel) {
36
- observer.next(data)
37
- observer.complete()
38
-
39
- return
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(toValue(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
- const event = data?.extensions?.lighthouse_subscriptions.event ?? 'lighthouse-subscription'
42
- this.subscribeToChannel(subscriptionChannel, event, observer)
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 {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gambalabs/apollo",
3
- "version": "6.0.0-alpha.30",
3
+ "version": "6.0.0-alpha.32",
4
4
  "license": "MIT",
5
5
  "repository": "https://github.com/GambaLabs/apollo",
6
6
  "homepage": "https://apollo.nuxtjs.org",