@gambalabs/apollo 6.0.0-alpha.7 → 6.0.0-alpha.9

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2017 Sebastien Chopin (@Atinux)
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Sebastien Chopin (@Atinux)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,47 +1,47 @@
1
- ![Nuxt Apollo](./docs/public/cover.jpg)
2
-
3
- <h1 align="center">Nuxt Apollo</h1>
4
-
5
- <p align="center">Effortlessly integrate GraphQL into your Nuxt 3 projects.</p>
6
-
7
- <p align="center">
8
- <!-- <a href="https://github.com/nuxt-community/apollo-module/actions?query=branch%3Amain+event%3Apush">
9
- <img alt="CI" src="https://github.com/nuxt-community/apollo-module/actions/workflows/ci.yml/badge.svg?branch=main"/>
10
- </a> -->
11
-
12
- <a href="https://npmjs.com/package/@nuxtjs/apollo/v/next">
13
- <img alt="Version" src="https://img.shields.io/npm/v/@nuxtjs/apollo/next?color=blue&style=flat-square"/>
14
- </a>
15
-
16
- <a href="https://npmjs.com/package/@nuxtjs/apollo/v/next">
17
- <img alt="Downloads" src="https://img.shields.io/npm/dt/@nuxtjs/apollo/next?color=blue&style=flat-square"/>
18
- </a>
19
-
20
- <a href="https://opensource.org/licenses/MIT">
21
- <img alt="MIT" src="https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square"/>
22
- </a>
23
- </p>
24
-
25
- ❯ [📖 Documentation](https://apollo.nuxtjs.org)
26
-
27
- ---
28
-
29
- **Note:** This branch is for **Nuxt 3** compatible module. Checkout the [`v4` branch](https://github.com/nuxt-modules/apollo/tree/v4) for **Nuxt 2** support.
30
-
31
- ---
32
-
33
- ## Preview
34
-
35
- [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/edit/nuxt-apollo-demo)
36
-
37
- ## Development
38
-
39
- - Clone this repository
40
- - Ensure you have the latest LTS version of Node.js installed
41
- - Run `corepack enable`
42
- - Install dependencies using `pnpm install`
43
- - Start playground with `pnpm dev`
44
-
45
- ## License
46
-
47
- [MIT License](./LICENSE)
1
+ ![Nuxt Apollo](./docs/public/cover.jpg)
2
+
3
+ <h1 align="center">Nuxt Apollo</h1>
4
+
5
+ <p align="center">Effortlessly integrate GraphQL into your Nuxt 3 projects.</p>
6
+
7
+ <p align="center">
8
+ <!-- <a href="https://github.com/nuxt-community/apollo-module/actions?query=branch%3Amain+event%3Apush">
9
+ <img alt="CI" src="https://github.com/nuxt-community/apollo-module/actions/workflows/ci.yml/badge.svg?branch=main"/>
10
+ </a> -->
11
+
12
+ <a href="https://npmjs.com/package/@nuxtjs/apollo/v/next">
13
+ <img alt="Version" src="https://img.shields.io/npm/v/@nuxtjs/apollo/next?color=blue&style=flat-square"/>
14
+ </a>
15
+
16
+ <a href="https://npmjs.com/package/@nuxtjs/apollo/v/next">
17
+ <img alt="Downloads" src="https://img.shields.io/npm/dt/@nuxtjs/apollo/next?color=blue&style=flat-square"/>
18
+ </a>
19
+
20
+ <a href="https://opensource.org/licenses/MIT">
21
+ <img alt="MIT" src="https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square"/>
22
+ </a>
23
+ </p>
24
+
25
+ ❯ [📖 Documentation](https://apollo.nuxtjs.org)
26
+
27
+ ---
28
+
29
+ **Note:** This branch is for **Nuxt 3** compatible module. Checkout the [`v4` branch](https://github.com/nuxt-modules/apollo/tree/v4) for **Nuxt 2** support.
30
+
31
+ ---
32
+
33
+ ## Preview
34
+
35
+ [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/edit/nuxt-apollo-demo)
36
+
37
+ ## Development
38
+
39
+ - Clone this repository
40
+ - Ensure you have the latest LTS version of Node.js installed
41
+ - Run `corepack enable`
42
+ - Install dependencies using `pnpm install`
43
+ - Start playground with `pnpm dev`
44
+
45
+ ## License
46
+
47
+ [MIT License](./LICENSE)
package/dist/module.d.ts CHANGED
@@ -7,200 +7,200 @@ import { CookieOptions } from 'nuxt/dist/app/composables';
7
7
  import { ErrorResponse } from '@apollo/client/link/error';
8
8
  export { ErrorResponse } from '@apollo/client/link/error';
9
9
 
10
- type CookieAttributes = Omit< CookieOptions, 'encode' | 'decode' | 'expires' | 'default'>;
11
-
12
- type Pusher = {
13
- cluster: string;
14
- wsHost: string;
15
- wsPort: number;
16
- forceTLS: boolean;
17
- channelEndpoint: string;
18
- pusherAppKey: string;
19
- }
20
-
21
- type ClientConfig = {
22
- /**
23
- * The GraphQL endpoint.
24
- * @type {string}
25
- */
26
- httpEndpoint: string;
27
-
28
- /**
29
- * Provide a GraphQL endpoint to be used client-side. Overrides `httpEndpoint`.
30
- * @type {string}
31
- **/
32
- browserHttpEndpoint?: string;
33
-
34
- /**
35
- * Provide additional configuration for the `HttpLink`.
36
- * See https://www.apollographql.com/docs/link/links/http.html#options
37
- * @type {HttpOptions}
38
- **/
39
- httpLinkOptions?: Omit<HttpOptions, 'uri'>;
40
-
41
- /**
42
- * Provide additional configuration for the `GraphQLWsLink`.
43
- * See https://github.com/enisdenjo/graphql-ws/blob/master/docs/interfaces/client.ClientOptions.md
44
- **/
45
- wsLinkOptions?: Omit<ClientOptions, 'url' | 'connectionParams'>;
46
-
47
- /**
48
- * Specify a websocket endpoint to be used for subscriptions.
49
- * The `wss` protocol is recommended in production.
50
- * @type {string}
51
- **/
52
- wsEndpoint?: string;
53
-
54
- /**
55
- * Specify if the client should solely use WebSocket.
56
- * requires `wsEndpoint`.
57
- * @type {boolean}
58
- * @default false
59
- **/
60
- websocketsOnly?: boolean;
61
-
62
- /**
63
- * Specify a pusher config to be used for subscriptions.
64
- * @type {Pusher}
65
- **/
66
- pusher?: Pusher
67
-
68
- /**
69
- * Specify if the client should be able to connect to the Apollo Client Devtools in production mode.
70
- * @type {boolean}
71
- * @default false
72
- **/
73
- connectToDevTools?: boolean;
74
-
75
- /**
76
- * Configure default options to be applied to the apollo client.
77
- **/
78
- defaultOptions?: DefaultOptions;
79
-
80
- /**
81
- * Configure the in-memory cache.
82
- **/
83
- inMemoryCacheOptions?: InMemoryCacheConfig;
84
-
85
- /**
86
- * Specify the name under which the token will be stored.
87
- * as in either a cookie or localStorage.
88
- * @type {string}
89
- * @default "apollo:<client-name>.token"
90
- */
91
- tokenName?: string;
92
-
93
- /**
94
- * Specify if the auth token should be stored in `cookie` or `localStorage`.
95
- * `Cookie` storage is required for SSR.
96
- * @type {string}
97
- * @default "cookie"
98
- **/
99
- tokenStorage?: 'cookie' | 'localStorage';
100
-
101
- /**
102
- * Specify the Authentication scheme.
103
- * @type {string}
104
- * @default "Bearer"
105
- **/
106
- authType?: string | null;
107
-
108
- /**
109
- * Name of the Authentication token header.
110
- * @type {string}
111
- * @default "Authorization"
112
- */
113
- authHeader?: string;
114
-
115
- /**
116
- * Configuration for the auth cookie.
117
- **/
118
- cookieAttributes?: CookieAttributes;
119
-
120
- /**
121
- * Name of the CSRF token header.
122
- * @type {string}
123
- * @default "X-CSRF-TOKEN"
124
- */
125
- csrfHeader?: string
126
-
127
- /**
128
- * Enable automatic persisted queries.
129
- * @type {boolean}
130
- * @default false
131
- */
132
- persistedQueries?: boolean
133
- };
134
-
135
- interface NuxtApolloConfig<T = ClientConfig> {
136
- /**
137
- * Determine if vue-apollo composables should be automatically imported.
138
- * @type {boolean}
139
- * @default true
140
- **/
141
- autoImports?: boolean;
142
-
143
- /**
144
- * Configuration of the Apollo clients.
145
- **/
146
- clients?: Record< string, T extends boolean ? string | ClientConfig : ClientConfig >;
147
-
148
- /**
149
- * Default options to be applied to all Apollo clients.
150
- * This is useful for setting global defaults, and is overridden by `defaultOptions` passed directly to clients.
151
- **/
152
- defaultOptions?: DefaultOptions;
153
-
154
- /**
155
- * Pass cookies from the browser to the GraphQL API in SSR mode.
156
- *
157
- * @type boolean
158
- * @default true
159
- * */
160
- proxyCookies?: boolean;
161
-
162
- /**
163
- * Specify the Authentication scheme.
164
- * @type {string}
165
- * @default 'Bearer'
166
- **/
167
- authType?: string;
168
-
169
- /**
170
- * Name of the Authentication token header.
171
- * @type {string}
172
- * @default "Authorization"
173
- */
174
- authHeader?: string;
175
-
176
- /**
177
- * Name of the CSRF token header.
178
- * @type {string}
179
- * @default "X-CSRF-TOKEN"
180
- */
181
- csrfHeader?: string;
182
-
183
- /**
184
- * Specify if the auth token should be stored in `cookie` or `localStorage`.
185
- * `Cookie` storage is required for SSR.
186
- * @type {string}
187
- * @default "cookie"
188
- **/
189
- tokenStorage?: 'cookie' | 'localStorage';
190
-
191
- /**
192
- * Configuration for the auth cookie.
193
- **/
194
- cookieAttributes?: CookieAttributes;
195
-
196
- /**
197
- * Apollo client awareness instructs the client to send two additional headers
198
- * `apollographql-client-name` and `apollographql-client-version` in each HTTP request.
199
- * This behavior is disabled by default.
200
- * @type {boolean}
201
- * @default false
202
- */
203
- clientAwareness?: boolean
10
+ type CookieAttributes = Omit< CookieOptions, 'encode' | 'decode' | 'expires' | 'default'>;
11
+
12
+ type Pusher = {
13
+ cluster: string;
14
+ wsHost: string;
15
+ wsPort: number;
16
+ forceTLS: boolean;
17
+ channelEndpoint: string;
18
+ pusherAppKey: string;
19
+ }
20
+
21
+ type ClientConfig = {
22
+ /**
23
+ * The GraphQL endpoint.
24
+ * @type {string}
25
+ */
26
+ httpEndpoint: string;
27
+
28
+ /**
29
+ * Provide a GraphQL endpoint to be used client-side. Overrides `httpEndpoint`.
30
+ * @type {string}
31
+ **/
32
+ browserHttpEndpoint?: string;
33
+
34
+ /**
35
+ * Provide additional configuration for the `HttpLink`.
36
+ * See https://www.apollographql.com/docs/link/links/http.html#options
37
+ * @type {HttpOptions}
38
+ **/
39
+ httpLinkOptions?: Omit<HttpOptions, 'uri'>;
40
+
41
+ /**
42
+ * Provide additional configuration for the `GraphQLWsLink`.
43
+ * See https://github.com/enisdenjo/graphql-ws/blob/master/docs/interfaces/client.ClientOptions.md
44
+ **/
45
+ wsLinkOptions?: Omit<ClientOptions, 'url' | 'connectionParams'>;
46
+
47
+ /**
48
+ * Specify a websocket endpoint to be used for subscriptions.
49
+ * The `wss` protocol is recommended in production.
50
+ * @type {string}
51
+ **/
52
+ wsEndpoint?: string;
53
+
54
+ /**
55
+ * Specify if the client should solely use WebSocket.
56
+ * requires `wsEndpoint`.
57
+ * @type {boolean}
58
+ * @default false
59
+ **/
60
+ websocketsOnly?: boolean;
61
+
62
+ /**
63
+ * Specify a pusher config to be used for subscriptions.
64
+ * @type {Pusher}
65
+ **/
66
+ pusher?: Pusher
67
+
68
+ /**
69
+ * Specify if the client should be able to connect to the Apollo Client Devtools in production mode.
70
+ * @type {boolean}
71
+ * @default false
72
+ **/
73
+ connectToDevTools?: boolean;
74
+
75
+ /**
76
+ * Configure default options to be applied to the apollo client.
77
+ **/
78
+ defaultOptions?: DefaultOptions;
79
+
80
+ /**
81
+ * Configure the in-memory cache.
82
+ **/
83
+ inMemoryCacheOptions?: InMemoryCacheConfig;
84
+
85
+ /**
86
+ * Specify the name under which the token will be stored.
87
+ * as in either a cookie or localStorage.
88
+ * @type {string}
89
+ * @default "apollo:<client-name>.token"
90
+ */
91
+ tokenName?: string;
92
+
93
+ /**
94
+ * Specify if the auth token should be stored in `cookie` or `localStorage`.
95
+ * `Cookie` storage is required for SSR.
96
+ * @type {string}
97
+ * @default "cookie"
98
+ **/
99
+ tokenStorage?: 'cookie' | 'localStorage';
100
+
101
+ /**
102
+ * Specify the Authentication scheme.
103
+ * @type {string}
104
+ * @default "Bearer"
105
+ **/
106
+ authType?: string | null;
107
+
108
+ /**
109
+ * Name of the Authentication token header.
110
+ * @type {string}
111
+ * @default "Authorization"
112
+ */
113
+ authHeader?: string;
114
+
115
+ /**
116
+ * Configuration for the auth cookie.
117
+ **/
118
+ cookieAttributes?: CookieAttributes;
119
+
120
+ /**
121
+ * Name of the CSRF token header.
122
+ * @type {string}
123
+ * @default "X-CSRF-TOKEN"
124
+ */
125
+ csrfHeader?: string
126
+
127
+ /**
128
+ * Enable automatic persisted queries.
129
+ * @type {boolean}
130
+ * @default false
131
+ */
132
+ persistedQueries?: boolean
133
+ };
134
+
135
+ interface NuxtApolloConfig<T = ClientConfig> {
136
+ /**
137
+ * Determine if vue-apollo composables should be automatically imported.
138
+ * @type {boolean}
139
+ * @default true
140
+ **/
141
+ autoImports?: boolean;
142
+
143
+ /**
144
+ * Configuration of the Apollo clients.
145
+ **/
146
+ clients?: Record< string, T extends boolean ? string | ClientConfig : ClientConfig >;
147
+
148
+ /**
149
+ * Default options to be applied to all Apollo clients.
150
+ * This is useful for setting global defaults, and is overridden by `defaultOptions` passed directly to clients.
151
+ **/
152
+ defaultOptions?: DefaultOptions;
153
+
154
+ /**
155
+ * Pass cookies from the browser to the GraphQL API in SSR mode.
156
+ *
157
+ * @type boolean
158
+ * @default true
159
+ * */
160
+ proxyCookies?: boolean;
161
+
162
+ /**
163
+ * Specify the Authentication scheme.
164
+ * @type {string}
165
+ * @default 'Bearer'
166
+ **/
167
+ authType?: string;
168
+
169
+ /**
170
+ * Name of the Authentication token header.
171
+ * @type {string}
172
+ * @default "Authorization"
173
+ */
174
+ authHeader?: string;
175
+
176
+ /**
177
+ * Name of the CSRF token header.
178
+ * @type {string}
179
+ * @default "X-CSRF-TOKEN"
180
+ */
181
+ csrfHeader?: string;
182
+
183
+ /**
184
+ * Specify if the auth token should be stored in `cookie` or `localStorage`.
185
+ * `Cookie` storage is required for SSR.
186
+ * @type {string}
187
+ * @default "cookie"
188
+ **/
189
+ tokenStorage?: 'cookie' | 'localStorage';
190
+
191
+ /**
192
+ * Configuration for the auth cookie.
193
+ **/
194
+ cookieAttributes?: CookieAttributes;
195
+
196
+ /**
197
+ * Apollo client awareness instructs the client to send two additional headers
198
+ * `apollographql-client-name` and `apollographql-client-version` in each HTTP request.
199
+ * This behavior is disabled by default.
200
+ * @type {boolean}
201
+ * @default false
202
+ */
203
+ clientAwareness?: boolean
204
204
  }
205
205
 
206
206
  type ModuleOptions = NuxtApolloConfig;
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gambalabs/apollo",
3
- "version": "6.0.0-alpha.7",
3
+ "version": "6.0.0-alpha.9",
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.7";
8
+ const version = "6.0.0-alpha.9";
9
9
 
10
10
  const logger = useLogger(name);
11
11
  async function readConfigFile(path) {
@@ -2,7 +2,8 @@ import destr from "destr";
2
2
  import { onError } from "@apollo/client/link/error";
3
3
  import { getMainDefinition } from "@apollo/client/utilities";
4
4
  import { ApolloClients, provideApolloClients } from "@vue/apollo-composable";
5
- import { ApolloClient, ApolloLink, createHttpLink, InMemoryCache, split } from "@apollo/client/core";
5
+ import { ApolloClient, ApolloLink, InMemoryCache, split } from "@apollo/client/core";
6
+ import createUploadLink from "apollo-upload-client/createUploadLink.mjs";
6
7
  import { createPersistedQueryLink } from "@apollo/client/link/persisted-queries";
7
8
  import { sha256 } from "crypto-hash";
8
9
  import { GraphQLWsLink } from "@apollo/client/link/subscriptions";
@@ -84,7 +85,7 @@ export default defineNuxtPlugin((nuxtApp) => {
84
85
  const persistedLink = createPersistedQueryLink({ sha256, useGETForHashedQueries: true });
85
86
  baseLink = baseLink.concat(persistedLink);
86
87
  }
87
- const httpEndLink = createHttpLink({
88
+ const httpEndLink = createUploadLink({
88
89
  ...clientConfig?.httpLinkOptions && clientConfig.httpLinkOptions,
89
90
  uri: process.client && clientConfig.browserHttpEndpoint || clientConfig.httpEndpoint,
90
91
  headers: { ...clientConfig?.httpLinkOptions?.headers || {} }
@@ -6,5 +6,5 @@ declare class PusherLink extends ApolloLink {
6
6
  subscribeToChannel(subscriptionChannel: any, event: string | undefined, observer: any): void;
7
7
  unsubscribeFromChannel(subscriptionChannel: any): void;
8
8
  }
9
- import { ApolloLink } from "@apollo/client/link/core";
10
- import { Observable } from "@apollo/client/core";
9
+ import { ApolloLink } from '@apollo/client/core';
10
+ import { Observable } from '@apollo/client/core';
@@ -1,100 +1,100 @@
1
- import { ApolloLink, Observable } from '@apollo/client/core'
2
-
3
- // Inspired by https://github.com/rmosolgo/graphql-ruby/blob/master/javascript_client/src/subscriptions/PusherLink.ts
4
- class PusherLink extends ApolloLink {
5
- constructor (options) {
6
- super()
7
-
8
- this.pusher = options.pusher
9
- }
10
-
11
- request (operation, forward) {
12
- const subscribeObservable = new Observable((_observer) => {
13
- //
14
- })
15
-
16
- // Capture the super method
17
- const prevSubscribe =
18
- subscribeObservable.subscribe.bind(subscribeObservable)
19
-
20
- // Override subscribe to return an `unsubscribe` object, see
21
- // https://github.com/apollographql/subscriptions-transport-ws/blob/master/src/client.ts#L182-L212
22
- subscribeObservable.subscribe = (observerOrNext, onError, onComplete) => {
23
- prevSubscribe(observerOrNext, onError, onComplete)
24
-
25
- const observer = getObserver(observerOrNext, onError, onComplete)
26
-
27
- let subscriptionChannel
28
-
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
40
- }
41
- const event = data?.extensions?.lighthouse_subscriptions.event ?? 'lighthouse-subscription'
42
- this.subscribeToChannel(subscriptionChannel, event, observer)
43
- }
44
- })
45
-
46
- // Return an object that will unsubscribe_if the query was a subscription
47
- return {
48
- closed: false,
49
- unsubscribe: () => {
50
- subscriptionChannel &&
51
- this.unsubscribeFromChannel(subscriptionChannel)
52
- }
53
- }
54
- }
55
-
56
- return subscribeObservable
57
- }
58
-
59
- subscribeToChannel (subscriptionChannel, event = 'lighthouse-subscription', observer) {
60
- this.pusher
61
- .subscribe(subscriptionChannel)
62
- .bind(event, (payload) => {
63
- const { result } = payload
64
- if (result) {
65
- observer.next(result)
66
- }
67
- if (!payload.more) {
68
- this.unsubscribeFromChannel(subscriptionChannel)
69
-
70
- observer.complete()
71
- }
72
- })
73
- }
74
-
75
- unsubscribeFromChannel (subscriptionChannel) {
76
- this.pusher.unsubscribe(subscriptionChannel)
77
- }
78
- }
79
-
80
- // Turn `subscribe` arguments into an observer-like thing, see getObserver
81
- // https://github.com/apollographql/subscriptions-transport-ws/blob/master/src/client.ts#L329-L343
82
- function getObserver (observerOrNext, onError, onComplete) {
83
- if (typeof observerOrNext === 'function') {
84
- // Duck-type an observer
85
- return {
86
- next: v => observerOrNext(v),
87
- error: e => onError && onError(e),
88
- complete: () => onComplete && onComplete()
89
- }
90
- } else {
91
- // Make an object that calls to the given object, with safety checks
92
- return {
93
- next: v => observerOrNext.next && observerOrNext.next(v),
94
- error: e => observerOrNext.error && observerOrNext.error(e),
95
- complete: () => observerOrNext.complete && observerOrNext.complete()
96
- }
97
- }
98
- }
99
-
100
- export default PusherLink
1
+ import { ApolloLink, Observable } from '@apollo/client/core'
2
+
3
+ // Inspired by https://github.com/rmosolgo/graphql-ruby/blob/master/javascript_client/src/subscriptions/PusherLink.ts
4
+ class PusherLink extends ApolloLink {
5
+ constructor (options) {
6
+ super()
7
+
8
+ this.pusher = options.pusher
9
+ }
10
+
11
+ request (operation, forward) {
12
+ const subscribeObservable = new Observable((_observer) => {
13
+ //
14
+ })
15
+
16
+ // Capture the super method
17
+ const prevSubscribe =
18
+ subscribeObservable.subscribe.bind(subscribeObservable)
19
+
20
+ // Override subscribe to return an `unsubscribe` object, see
21
+ // https://github.com/apollographql/subscriptions-transport-ws/blob/master/src/client.ts#L182-L212
22
+ subscribeObservable.subscribe = (observerOrNext, onError, onComplete) => {
23
+ prevSubscribe(observerOrNext, onError, onComplete)
24
+
25
+ const observer = getObserver(observerOrNext, onError, onComplete)
26
+
27
+ let subscriptionChannel
28
+
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
40
+ }
41
+ const event = data?.extensions?.lighthouse_subscriptions.event ?? 'lighthouse-subscription'
42
+ this.subscribeToChannel(subscriptionChannel, event, observer)
43
+ }
44
+ })
45
+
46
+ // Return an object that will unsubscribe_if the query was a subscription
47
+ return {
48
+ closed: false,
49
+ unsubscribe: () => {
50
+ subscriptionChannel &&
51
+ this.unsubscribeFromChannel(subscriptionChannel)
52
+ }
53
+ }
54
+ }
55
+
56
+ return subscribeObservable
57
+ }
58
+
59
+ subscribeToChannel (subscriptionChannel, event = 'lighthouse-subscription', observer) {
60
+ this.pusher
61
+ .subscribe(subscriptionChannel)
62
+ .bind(event, (payload) => {
63
+ const { result } = payload
64
+ if (result) {
65
+ observer.next(result)
66
+ }
67
+ if (!payload.more) {
68
+ this.unsubscribeFromChannel(subscriptionChannel)
69
+
70
+ observer.complete()
71
+ }
72
+ })
73
+ }
74
+
75
+ unsubscribeFromChannel (subscriptionChannel) {
76
+ this.pusher.unsubscribe(subscriptionChannel)
77
+ }
78
+ }
79
+
80
+ // Turn `subscribe` arguments into an observer-like thing, see getObserver
81
+ // https://github.com/apollographql/subscriptions-transport-ws/blob/master/src/client.ts#L329-L343
82
+ function getObserver (observerOrNext, onError, onComplete) {
83
+ if (typeof observerOrNext === 'function') {
84
+ // Duck-type an observer
85
+ return {
86
+ next: v => observerOrNext(v),
87
+ error: e => onError && onError(e),
88
+ complete: () => onComplete && onComplete()
89
+ }
90
+ } else {
91
+ // Make an object that calls to the given object, with safety checks
92
+ return {
93
+ next: v => observerOrNext.next && observerOrNext.next(v),
94
+ error: e => observerOrNext.error && observerOrNext.error(e),
95
+ complete: () => observerOrNext.complete && observerOrNext.complete()
96
+ }
97
+ }
98
+ }
99
+
100
+ export default PusherLink
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gambalabs/apollo",
3
- "version": "6.0.0-alpha.7",
3
+ "version": "6.0.0-alpha.9",
4
4
  "license": "MIT",
5
5
  "repository": "https://github.com/GambaLabs/apollo",
6
6
  "homepage": "https://apollo.nuxtjs.org",
@@ -17,28 +17,29 @@
17
17
  "dist"
18
18
  ],
19
19
  "dependencies": {
20
- "@apollo/client": "^3.7.10",
21
- "@nuxt/kit": "^3.3.1",
22
- "@rollup/plugin-graphql": "^2.0.3",
20
+ "@apollo/client": "^3.8.7",
21
+ "@nuxt/kit": "^3.8.2",
22
+ "@rollup/plugin-graphql": "^2.0.4",
23
23
  "@vue/apollo-composable": "4.0.0-beta.4",
24
+ "apollo-upload-client": "^18.0.1",
24
25
  "crypto-hash": "^2.0.1",
25
- "defu": "^6.1.2",
26
+ "defu": "^6.1.3",
26
27
  "destr": "^1.2.2",
27
- "graphql": "^16.6.0",
28
+ "graphql": "^16.8.1",
28
29
  "graphql-tag": "^2.12.6",
29
- "graphql-ws": "^5.12.0",
30
- "jiti": "^1.18.2",
31
- "ohash": "^1.0.0",
30
+ "graphql-ws": "^5.14.2",
31
+ "jiti": "^1.21.0",
32
+ "ohash": "^1.1.3",
32
33
  "pusher-js": "^8.3.0"
33
34
  },
34
35
  "devDependencies": {
35
36
  "@nuxt/module-builder": "^0.2.1",
36
- "@nuxt/schema": "^3.3.1",
37
+ "@nuxt/schema": "^3.8.2",
37
38
  "@nuxt/ui": "^0.4.1",
38
- "@nuxtjs/eslint-config-typescript": "^12.0.0",
39
- "@types/node": "^18.15.3",
40
- "eslint": "^8.36.0",
41
- "nuxt": "^3.3.1"
39
+ "@nuxtjs/eslint-config-typescript": "^12.1.0",
40
+ "@types/node": "^18.18.13",
41
+ "eslint": "^8.54.0",
42
+ "nuxt": "^3.8.2"
42
43
  },
43
44
  "publishConfig": {
44
45
  "access": "public"
@@ -49,7 +50,7 @@
49
50
  "packageManager": "pnpm@7.29.1",
50
51
  "scripts": {
51
52
  "build": "nuxt-module-build",
52
- "dev": "nuxi dev playground --dotenv .env",
53
+ "dev": "nuxi dev playground --dotenv .env --host",
53
54
  "dev:build": "nuxi build playground",
54
55
  "dev:prepare": "nuxt-module-build --stub && nuxi prepare playground",
55
56
  "release": "standard-version --prerelease alpha && git push --follow-tags && pnpm publish --tag next"