@gambalabs/apollo 6.0.0-alpha.17 → 6.0.0-alpha.19
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/README.md +1 -1
- package/dist/config.d.mts +8 -0
- package/dist/config.d.ts +8 -0
- package/dist/config.mjs +3 -0
- package/dist/module.d.mts +31 -0
- package/dist/module.d.ts +21 -225
- package/dist/module.json +1 -1
- package/dist/module.mjs +36 -14
- package/dist/runtime/composables.d.ts +73 -21
- package/dist/runtime/composables.mjs +59 -38
- package/dist/runtime/plugin.d.ts +32 -0
- package/dist/runtime/plugin.mjs +13 -5
- package/dist/shared/apollo.32d05cc9.d.mts +201 -0
- package/dist/shared/apollo.32d05cc9.d.ts +201 -0
- package/dist/types.d.mts +20 -0
- package/dist/types.d.ts +12 -2
- package/package.json +23 -16
package/README.md
CHANGED
package/dist/config.d.ts
ADDED
package/dist/config.mjs
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
+
import { N as NuxtApolloConfig, C as ClientConfig } from './shared/apollo.32d05cc9.mjs';
|
|
3
|
+
export { ErrorResponse } from '@apollo/client/link/error';
|
|
4
|
+
import 'graphql-ws';
|
|
5
|
+
import '@apollo/client';
|
|
6
|
+
import 'nuxt/app';
|
|
7
|
+
|
|
8
|
+
type ModuleOptions = NuxtApolloConfig;
|
|
9
|
+
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
|
|
10
|
+
|
|
11
|
+
declare const defineApolloClient: (config: ClientConfig) => ClientConfig;
|
|
12
|
+
interface ModuleRuntimeConfig {
|
|
13
|
+
apollo: NuxtApolloConfig<any>;
|
|
14
|
+
}
|
|
15
|
+
interface ModulePublicRuntimeConfig {
|
|
16
|
+
apollo: NuxtApolloConfig<any>;
|
|
17
|
+
}
|
|
18
|
+
declare module '@nuxt/schema' {
|
|
19
|
+
interface NuxtConfig {
|
|
20
|
+
['apollo']?: Partial<ModuleOptions>;
|
|
21
|
+
}
|
|
22
|
+
interface NuxtOptions {
|
|
23
|
+
['apollo']?: ModuleOptions;
|
|
24
|
+
}
|
|
25
|
+
interface RuntimeConfig extends ModuleRuntimeConfig {
|
|
26
|
+
}
|
|
27
|
+
interface PublicRuntimeConfig extends ModulePublicRuntimeConfig {
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { ClientConfig, type ModuleOptions, type ModulePublicRuntimeConfig, type ModuleRuntimeConfig, _default as default, defineApolloClient };
|
package/dist/module.d.ts
CHANGED
|
@@ -1,235 +1,31 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
-
import {
|
|
3
|
-
import { DefaultContext } from '@apollo/client/core';
|
|
4
|
-
import { ClientOptions } from 'graphql-ws';
|
|
5
|
-
import { HttpOptions, DefaultOptions, InMemoryCacheConfig } from '@apollo/client';
|
|
6
|
-
import { CookieOptions } from 'nuxt/dist/app/composables';
|
|
7
|
-
import { ErrorResponse } from '@apollo/client/link/error';
|
|
2
|
+
import { N as NuxtApolloConfig, C as ClientConfig } from './shared/apollo.32d05cc9.js';
|
|
8
3
|
export { ErrorResponse } from '@apollo/client/link/error';
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
}
|
|
4
|
+
import 'graphql-ws';
|
|
5
|
+
import '@apollo/client';
|
|
6
|
+
import 'nuxt/app';
|
|
205
7
|
|
|
206
8
|
type ModuleOptions = NuxtApolloConfig;
|
|
207
|
-
declare const _default: _nuxt_schema.NuxtModule<
|
|
9
|
+
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
|
|
208
10
|
|
|
209
11
|
declare const defineApolloClient: (config: ClientConfig) => ClientConfig;
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
12
|
+
interface ModuleRuntimeConfig {
|
|
13
|
+
apollo: NuxtApolloConfig<any>;
|
|
14
|
+
}
|
|
15
|
+
interface ModulePublicRuntimeConfig {
|
|
16
|
+
apollo: NuxtApolloConfig<any>;
|
|
17
|
+
}
|
|
18
|
+
declare module '@nuxt/schema' {
|
|
19
|
+
interface NuxtConfig {
|
|
20
|
+
['apollo']?: Partial<ModuleOptions>;
|
|
21
|
+
}
|
|
22
|
+
interface NuxtOptions {
|
|
23
|
+
['apollo']?: ModuleOptions;
|
|
24
|
+
}
|
|
25
|
+
interface RuntimeConfig extends ModuleRuntimeConfig {
|
|
216
26
|
}
|
|
217
|
-
interface
|
|
218
|
-
'apollo:auth': (params: {
|
|
219
|
-
client: string;
|
|
220
|
-
token: Ref<string | null>;
|
|
221
|
-
}) => void;
|
|
222
|
-
'apollo:error': (error: ErrorResponse) => void;
|
|
223
|
-
'apollo:csrf': (params: {
|
|
224
|
-
client: string;
|
|
225
|
-
token: Ref<string | null>;
|
|
226
|
-
}) => void;
|
|
227
|
-
'apollo:link': (params: {
|
|
228
|
-
client: string;
|
|
229
|
-
context: Ref<DefaultContext | null>;
|
|
230
|
-
prevContextContext: DefaultContext | null;
|
|
231
|
-
}) => void;
|
|
27
|
+
interface PublicRuntimeConfig extends ModulePublicRuntimeConfig {
|
|
232
28
|
}
|
|
233
29
|
}
|
|
234
30
|
|
|
235
|
-
export { ClientConfig, ModuleOptions, _default as default, defineApolloClient };
|
|
31
|
+
export { ClientConfig, type ModuleOptions, type ModulePublicRuntimeConfig, type ModuleRuntimeConfig, _default as default, defineApolloClient };
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -5,7 +5,21 @@ 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.19";
|
|
9
|
+
|
|
10
|
+
const serializeConfig = (obj) => {
|
|
11
|
+
if (typeof obj === "function") {
|
|
12
|
+
return obj.toString();
|
|
13
|
+
}
|
|
14
|
+
if (typeof obj === "object") {
|
|
15
|
+
if (Array.isArray(obj)) {
|
|
16
|
+
return `[${obj.map(serializeConfig).join(", ")}]`;
|
|
17
|
+
} else {
|
|
18
|
+
return `{${Object.entries(obj).map(([key, value]) => `${serializeConfig(key)}: ${serializeConfig(value)}`).join(", ")}}`;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return JSON.stringify(obj);
|
|
22
|
+
};
|
|
9
23
|
|
|
10
24
|
const logger = useLogger(name);
|
|
11
25
|
async function readConfigFile(path) {
|
|
@@ -29,19 +43,22 @@ const module = defineNuxtModule({
|
|
|
29
43
|
proxyCookies: true,
|
|
30
44
|
cookieAttributes: {
|
|
31
45
|
maxAge: 60 * 60 * 24 * 7,
|
|
32
|
-
secure: process.env.NODE_ENV === "production"
|
|
46
|
+
secure: process.env.NODE_ENV === "production",
|
|
47
|
+
sameSite: "lax"
|
|
33
48
|
},
|
|
34
49
|
clientAwareness: false
|
|
35
50
|
},
|
|
36
51
|
async setup(options, nuxt) {
|
|
37
52
|
if (!options.clients || !Object.keys(options.clients).length) {
|
|
38
|
-
|
|
53
|
+
logger.warn("No apollo clients configured.");
|
|
54
|
+
return;
|
|
39
55
|
}
|
|
40
56
|
const { resolve } = createResolver(import.meta.url);
|
|
41
57
|
const rootResolver = createResolver(nuxt.options.rootDir);
|
|
42
58
|
nuxt.options.build.transpile = nuxt.options.build.transpile || [];
|
|
43
59
|
nuxt.options.build.transpile.push(
|
|
44
60
|
resolve("runtime"),
|
|
61
|
+
"tslib",
|
|
45
62
|
"@wry/context",
|
|
46
63
|
"@apollo/client",
|
|
47
64
|
"@vue/apollo-composable",
|
|
@@ -63,7 +80,7 @@ const module = defineNuxtModule({
|
|
|
63
80
|
configPaths[k] = path;
|
|
64
81
|
}
|
|
65
82
|
}
|
|
66
|
-
v.authType =
|
|
83
|
+
v.authType = (v?.authType === void 0 ? options.authType : v?.authType) || null;
|
|
67
84
|
v.authHeader = v?.authHeader || options.authHeader;
|
|
68
85
|
v.csrfHeader = v?.csrfHeader || options.csrfHeader;
|
|
69
86
|
v.tokenName = v?.tokenName || `apollo:${k}.token`;
|
|
@@ -82,24 +99,29 @@ const module = defineNuxtModule({
|
|
|
82
99
|
filename: "apollo.d.ts",
|
|
83
100
|
getContents: () => [
|
|
84
101
|
'import type { ClientConfig } from "@nuxtjs/apollo"',
|
|
85
|
-
"declare
|
|
86
|
-
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
-
"
|
|
102
|
+
"declare module '#apollo' {",
|
|
103
|
+
` export type ApolloClientKeys = '${Object.keys(clients).join("' | '")}'`,
|
|
104
|
+
" export const NuxtApollo: {",
|
|
105
|
+
" clients: Record<ApolloClientKeys, ClientConfig>",
|
|
106
|
+
" clientAwareness: boolean",
|
|
107
|
+
" proxyCookies: boolean",
|
|
108
|
+
" cookieAttributes: ClientConfig['cookieAttributes']",
|
|
109
|
+
" }",
|
|
110
|
+
"}"
|
|
90
111
|
].join("\n")
|
|
91
112
|
});
|
|
92
|
-
|
|
113
|
+
addTemplate({
|
|
93
114
|
filename: "apollo.mjs",
|
|
94
115
|
getContents: () => [
|
|
95
|
-
"export
|
|
116
|
+
"export const NuxtApollo = {",
|
|
96
117
|
` proxyCookies: ${options.proxyCookies},`,
|
|
97
118
|
` clientAwareness: ${options.clientAwareness},`,
|
|
98
|
-
` cookieAttributes: ${
|
|
99
|
-
` clients: ${
|
|
119
|
+
` cookieAttributes: ${serializeConfig(options.cookieAttributes)},`,
|
|
120
|
+
` clients: ${serializeConfig(clients)}`,
|
|
100
121
|
"}"
|
|
101
122
|
].join("\n")
|
|
102
|
-
})
|
|
123
|
+
});
|
|
124
|
+
nuxt.options.alias["#apollo"] = resolve(nuxt.options.buildDir, "apollo");
|
|
103
125
|
addPlugin(resolve("runtime/plugin"));
|
|
104
126
|
addImports([
|
|
105
127
|
{ name: "gql", from: "graphql-tag" },
|
|
@@ -1,45 +1,97 @@
|
|
|
1
|
-
import type { OperationVariables, QueryOptions } from '@apollo/client';
|
|
2
|
-
import type { AsyncData } from 'nuxt/
|
|
1
|
+
import type { ApolloClient, OperationVariables, QueryOptions, DefaultContext } from '@apollo/client';
|
|
2
|
+
import type { AsyncData, AsyncDataOptions, NuxtError } from 'nuxt/app';
|
|
3
|
+
import type { ApolloClientKeys } from '#apollo';
|
|
4
|
+
type PickFrom<T, K extends Array<string>> = T extends Array<any> ? T : T extends Record<string, any> ? keyof T extends K[number] ? T : K[number] extends never ? T : Pick<T, K[number]> : T;
|
|
5
|
+
type KeysOf<T> = Array<T extends T ? keyof T extends string ? keyof T : never : never>;
|
|
3
6
|
type TQuery<T> = QueryOptions<OperationVariables, T>['query'];
|
|
4
|
-
type TVariables<T> = QueryOptions<OperationVariables, T>['variables'];
|
|
7
|
+
type TVariables<T> = QueryOptions<OperationVariables, T>['variables'] | null;
|
|
5
8
|
type TAsyncQuery<T> = {
|
|
9
|
+
/**
|
|
10
|
+
* A unique key to ensure the query can be properly de-duplicated across requests. Defaults to a hash of the query and variables.
|
|
11
|
+
*/
|
|
12
|
+
key?: string;
|
|
13
|
+
/**
|
|
14
|
+
* A GraphQL query string parsed into an AST with the gql template literal.
|
|
15
|
+
*/
|
|
6
16
|
query: TQuery<T>;
|
|
17
|
+
/**
|
|
18
|
+
* An object containing all of the GraphQL variables your query requires to execute.
|
|
19
|
+
*
|
|
20
|
+
* Each key in the object corresponds to a variable name, and that key's value corresponds to the variable value.
|
|
21
|
+
*/
|
|
7
22
|
variables?: TVariables<T>;
|
|
8
|
-
|
|
23
|
+
/**
|
|
24
|
+
* The name of the Apollo Client to use. Defaults to `default`.
|
|
25
|
+
*/
|
|
26
|
+
clientId?: ApolloClientKeys;
|
|
27
|
+
/**
|
|
28
|
+
* If you're using Apollo Link, this object is the initial value of the context object that's passed along your link chain.
|
|
29
|
+
*/
|
|
30
|
+
context?: DefaultContext;
|
|
31
|
+
/**
|
|
32
|
+
* If `true`, this overrides the default fetchPolicy for the Apollo Client to `cache-first`.
|
|
33
|
+
* */
|
|
9
34
|
cache?: boolean;
|
|
10
|
-
clientId?: string;
|
|
11
35
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
export declare
|
|
36
|
+
/**
|
|
37
|
+
* `useAsyncQuery` resolves the GraphQL query asynchronously in a SSR-friendly composable.
|
|
38
|
+
*
|
|
39
|
+
* @param opts An object containing the query, variables, clientId, context, and cache options.
|
|
40
|
+
* @param options Customize the underlying `useAsyncData` composable.
|
|
41
|
+
*/
|
|
42
|
+
export declare function useAsyncQuery<T, DataT = T, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = null, NuxtErrorDataT = unknown>(opts: TAsyncQuery<T>, options?: AsyncDataOptions<T, DataT, PickKeys, DefaultT>): AsyncData<PickFrom<DataT, PickKeys> | DefaultT, (NuxtErrorDataT extends Error | NuxtError ? NuxtErrorDataT : NuxtError<NuxtErrorDataT>) | null>;
|
|
43
|
+
/**
|
|
44
|
+
* `useAsyncQuery` resolves the GraphQL query asynchronously in a SSR-friendly composable.
|
|
45
|
+
*
|
|
46
|
+
* @param query A GraphQL query string parsed into an AST with the gql template literal.
|
|
47
|
+
* @param variables An object containing all of the GraphQL variables your query requires to execute.
|
|
48
|
+
* @param clientId The name of the Apollo Client to use. Defaults to `default`.
|
|
49
|
+
* @param context The context object that's passed along your link chain.
|
|
50
|
+
* @param options Customize the underlying `useAsyncData` composable.
|
|
51
|
+
*/
|
|
52
|
+
export declare function useAsyncQuery<T, DataT = T, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = null, NuxtErrorDataT = unknown>(query: TQuery<T>, variables?: TVariables<T>, clientId?: ApolloClientKeys, context?: DefaultContext, options?: AsyncDataOptions<T, DataT, PickKeys, DefaultT>): AsyncData<PickFrom<DataT, PickKeys> | DefaultT, (NuxtErrorDataT extends Error | NuxtError ? NuxtErrorDataT : NuxtError<NuxtErrorDataT>) | null>;
|
|
53
|
+
/**
|
|
54
|
+
* `useLazyAsyncQuery` resolves the GraphQL query after loading the route, instead of blocking client-side navigation.
|
|
55
|
+
*
|
|
56
|
+
* @param opts An object containing the query, variables, clientId, context, and cache options.
|
|
57
|
+
* @param options Customize the underlying `useAsyncData` composable.
|
|
58
|
+
*/
|
|
59
|
+
export declare function useLazyAsyncQuery<T, DataT = T, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = null, NuxtErrorDataT = unknown>(opts: TAsyncQuery<T>, options?: AsyncDataOptions<T, DataT, PickKeys, DefaultT>): AsyncData<PickFrom<DataT, PickKeys> | DefaultT, (NuxtErrorDataT extends Error | NuxtError ? NuxtErrorDataT : NuxtError<NuxtErrorDataT>) | null>;
|
|
60
|
+
/**
|
|
61
|
+
* `useLazyAsyncQuery` resolves the GraphQL query after loading the route, instead of blocking client-side navigation.
|
|
62
|
+
*
|
|
63
|
+
* @param query A GraphQL query string parsed into an AST with the gql template literal.
|
|
64
|
+
* @param variables An object containing all of the GraphQL variables your query requires to execute.
|
|
65
|
+
* @param clientId The name of the Apollo Client to use. Defaults to `default`.
|
|
66
|
+
* @param context The context object that's passed along your link chain.
|
|
67
|
+
* @param options Customize the underlying `useAsyncData` composable.
|
|
68
|
+
*/
|
|
69
|
+
export declare function useLazyAsyncQuery<T, DataT = T, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = null, NuxtErrorDataT = unknown>(query: TQuery<T>, variables?: TVariables<T>, clientId?: string, context?: DefaultContext, options?: AsyncDataOptions<T, DataT, PickKeys, DefaultT>): AsyncData<PickFrom<DataT, PickKeys> | DefaultT, (NuxtErrorDataT extends Error | NuxtError ? NuxtErrorDataT : NuxtError<NuxtErrorDataT>) | null>;
|
|
70
|
+
export declare function useApollo(): {
|
|
71
|
+
/**
|
|
72
|
+
* Access the configured apollo clients.
|
|
73
|
+
*/
|
|
74
|
+
clients: Record<ApolloClientKeys, ApolloClient<any>> | undefined;
|
|
19
75
|
/**
|
|
20
76
|
* Retrieve the auth token for the specified client. Adheres to the `apollo:auth` hook.
|
|
21
77
|
*
|
|
22
78
|
* @param {string} client The client who's token to retrieve. Defaults to `default`.
|
|
23
79
|
*/
|
|
24
|
-
getToken: (client?:
|
|
25
|
-
/**
|
|
26
|
-
* Access the configured apollo clients.
|
|
27
|
-
*/
|
|
28
|
-
clients: Record<string, import("@apollo/client").ApolloClient<any>> | undefined;
|
|
80
|
+
getToken: (client?: ApolloClientKeys) => Promise<string | null | undefined>;
|
|
29
81
|
/**
|
|
30
82
|
* Apply auth token to the specified Apollo client, and optionally reset it's cache.
|
|
31
83
|
*
|
|
32
84
|
* @param {string} token The token to be applied.
|
|
33
85
|
* @param {string} client - Name of the Apollo client. Defaults to `default`.
|
|
34
|
-
* @param {boolean} skipResetStore - If `
|
|
86
|
+
* @param {boolean} skipResetStore - If `false`, Resets your entire store by clearing out your cache and then re-executing all of your active queries.
|
|
35
87
|
* */
|
|
36
|
-
onLogin: (token?: string, client?:
|
|
88
|
+
onLogin: (token?: string, client?: ApolloClientKeys, skipResetStore?: boolean) => Promise<void>;
|
|
37
89
|
/**
|
|
38
90
|
* Remove the auth token from the Apollo client, and optionally reset it's cache.
|
|
39
91
|
*
|
|
40
92
|
* @param {string} client - Name of the Apollo client. Defaults to `default`.
|
|
41
|
-
* @param {boolean} skipResetStore - If `
|
|
93
|
+
* @param {boolean} skipResetStore - If `false`, Resets your entire store by clearing out your cache and then re-executing all of your active queries.
|
|
42
94
|
* */
|
|
43
|
-
onLogout: (client?:
|
|
95
|
+
onLogout: (client?: ApolloClientKeys, skipResetStore?: boolean) => Promise<void>;
|
|
44
96
|
};
|
|
45
97
|
export {};
|
|
@@ -1,44 +1,86 @@
|
|
|
1
1
|
import { hash } from "ohash";
|
|
2
2
|
import { print } from "graphql";
|
|
3
|
-
import { ref, useCookie, useNuxtApp, useAsyncData } from "#imports";
|
|
4
|
-
import NuxtApollo from "#
|
|
3
|
+
import { ref, unref, isRef, reactive, useCookie, useNuxtApp, useAsyncData } from "#imports";
|
|
4
|
+
import { NuxtApollo } from "#apollo";
|
|
5
5
|
export function useAsyncQuery(...args) {
|
|
6
|
-
const { key, fn } = prep(...args);
|
|
7
|
-
return useAsyncData(key, fn);
|
|
6
|
+
const { key, fn, options } = prep(...args);
|
|
7
|
+
return useAsyncData(key, fn, options);
|
|
8
8
|
}
|
|
9
9
|
export function useLazyAsyncQuery(...args) {
|
|
10
|
-
const { key, fn } = prep(...args);
|
|
11
|
-
return useAsyncData(key, fn, { lazy: true });
|
|
10
|
+
const { key, fn, options } = prep(...args);
|
|
11
|
+
return useAsyncData(key, fn, { ...options, lazy: true });
|
|
12
12
|
}
|
|
13
13
|
const prep = (...args) => {
|
|
14
14
|
const { clients } = useApollo();
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
let clientId
|
|
15
|
+
let query;
|
|
16
|
+
let variables;
|
|
17
|
+
let cache;
|
|
18
|
+
let clientId;
|
|
19
|
+
let context;
|
|
20
|
+
let options = {};
|
|
21
|
+
if (typeof args?.[0] === "object" && "query" in args[0]) {
|
|
22
|
+
query = args?.[0]?.query;
|
|
23
|
+
variables = args?.[0]?.variables;
|
|
24
|
+
cache = args?.[0]?.cache;
|
|
25
|
+
context = args?.[0]?.context;
|
|
26
|
+
clientId = args?.[0]?.clientId;
|
|
27
|
+
if (typeof args?.[1] === "object") {
|
|
28
|
+
options = args?.[1];
|
|
29
|
+
}
|
|
30
|
+
} else {
|
|
31
|
+
query = args?.[0];
|
|
32
|
+
variables = args?.[1];
|
|
33
|
+
clientId = args?.[2];
|
|
34
|
+
context = args?.[3];
|
|
35
|
+
if (typeof args?.[4] === "object") {
|
|
36
|
+
options = args?.[4];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (!query) {
|
|
40
|
+
throw new Error("@nuxtjs/apollo: no query provided");
|
|
41
|
+
}
|
|
19
42
|
if (!clientId || !clients?.[clientId]) {
|
|
20
|
-
clientId = clients?.default ? "default" : Object.keys(clients)[0];
|
|
43
|
+
clientId = clients?.default ? "default" : Object.keys(clients)?.[0];
|
|
44
|
+
if (!clientId) {
|
|
45
|
+
throw new Error("@nuxtjs/apollo: no client found");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (variables) {
|
|
49
|
+
variables = isRef(variables) ? variables : reactive(variables);
|
|
50
|
+
options.watch = options.watch || [];
|
|
51
|
+
options.watch.push(variables);
|
|
21
52
|
}
|
|
22
|
-
const key = args?.[0]?.key || hash({ query: print(query), variables, clientId });
|
|
23
|
-
const fn = () => clients[clientId]?.query({
|
|
24
|
-
|
|
53
|
+
const key = args?.[0]?.key || hash({ query: print(query), variables: unref(variables), clientId });
|
|
54
|
+
const fn = () => clients[clientId]?.query({
|
|
55
|
+
query,
|
|
56
|
+
variables: unref(variables) || void 0,
|
|
57
|
+
...cache && { fetchPolicy: "cache-first" },
|
|
58
|
+
context
|
|
59
|
+
}).then((r) => r.data);
|
|
60
|
+
return { key, query, clientId, variables, fn, options };
|
|
25
61
|
};
|
|
26
|
-
export
|
|
62
|
+
export function useApollo() {
|
|
27
63
|
const nuxtApp = useNuxtApp();
|
|
28
64
|
const getToken = async (client) => {
|
|
29
65
|
client = client || "default";
|
|
30
66
|
const conf = NuxtApollo?.clients?.[client];
|
|
67
|
+
if (!conf) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
31
70
|
const token = ref(null);
|
|
32
71
|
await nuxtApp.callHook("apollo:auth", { token, client });
|
|
33
72
|
if (token.value) {
|
|
34
73
|
return token.value;
|
|
35
74
|
}
|
|
36
75
|
const tokenName = conf.tokenName;
|
|
37
|
-
return conf?.tokenStorage === "cookie" ? useCookie(tokenName).value : process.client && localStorage.getItem(tokenName) || null;
|
|
76
|
+
return conf?.tokenStorage === "cookie" ? nuxtApp.runWithContext(() => useCookie(tokenName).value) : process.client && localStorage.getItem(tokenName) || null;
|
|
38
77
|
};
|
|
39
78
|
const updateAuth = async ({ token, client, mode, skipResetStore }) => {
|
|
40
79
|
client = client || "default";
|
|
41
80
|
const conf = NuxtApollo?.clients?.[client];
|
|
81
|
+
if (!conf) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
42
84
|
const tokenName = client && conf.tokenName;
|
|
43
85
|
if (conf?.tokenStorage === "cookie") {
|
|
44
86
|
const cookieOpts = client && conf?.cookieAttributes || NuxtApollo?.cookieAttributes;
|
|
@@ -63,30 +105,9 @@ export const useApollo = () => {
|
|
|
63
105
|
await nuxtApp?._apolloClients?.[client].resetStore().catch((e) => console.log("%cError on cache reset", "color: orange;", e.message));
|
|
64
106
|
};
|
|
65
107
|
return {
|
|
66
|
-
/**
|
|
67
|
-
* Retrieve the auth token for the specified client. Adheres to the `apollo:auth` hook.
|
|
68
|
-
*
|
|
69
|
-
* @param {string} client The client who's token to retrieve. Defaults to `default`.
|
|
70
|
-
*/
|
|
71
108
|
getToken,
|
|
72
|
-
/**
|
|
73
|
-
* Access the configured apollo clients.
|
|
74
|
-
*/
|
|
75
109
|
clients: nuxtApp?._apolloClients,
|
|
76
|
-
/**
|
|
77
|
-
* Apply auth token to the specified Apollo client, and optionally reset it's cache.
|
|
78
|
-
*
|
|
79
|
-
* @param {string} token The token to be applied.
|
|
80
|
-
* @param {string} client - Name of the Apollo client. Defaults to `default`.
|
|
81
|
-
* @param {boolean} skipResetStore - If `true`, the cache will not be reset.
|
|
82
|
-
* */
|
|
83
110
|
onLogin: (token, client, skipResetStore) => updateAuth({ token, client, skipResetStore, mode: "login" }),
|
|
84
|
-
/**
|
|
85
|
-
* Remove the auth token from the Apollo client, and optionally reset it's cache.
|
|
86
|
-
*
|
|
87
|
-
* @param {string} client - Name of the Apollo client. Defaults to `default`.
|
|
88
|
-
* @param {boolean} skipResetStore - If `true`, the cache will not be reset.
|
|
89
|
-
* */
|
|
90
111
|
onLogout: (client, skipResetStore) => updateAuth({ client, skipResetStore, mode: "logout" })
|
|
91
112
|
};
|
|
92
|
-
}
|
|
113
|
+
}
|
package/dist/runtime/plugin.d.ts
CHANGED
|
@@ -1,2 +1,34 @@
|
|
|
1
|
+
import { ApolloClient } from '@apollo/client/core';
|
|
2
|
+
import type { ErrorResponse } from '../types';
|
|
3
|
+
import { useApollo } from './composables';
|
|
4
|
+
import type { Ref } from '#imports';
|
|
5
|
+
import type { ApolloClientKeys } from '#apollo';
|
|
1
6
|
declare const _default: any;
|
|
2
7
|
export default _default;
|
|
8
|
+
export interface ModuleRuntimeHooks {
|
|
9
|
+
'apollo:auth': (params: {
|
|
10
|
+
client: ApolloClientKeys;
|
|
11
|
+
token: Ref<string | null>;
|
|
12
|
+
}) => void;
|
|
13
|
+
'apollo:error': (error: ErrorResponse) => void;
|
|
14
|
+
}
|
|
15
|
+
interface DollarApolloHelpers extends ReturnType<typeof useApollo> {
|
|
16
|
+
}
|
|
17
|
+
interface DollarApollo {
|
|
18
|
+
clients: Record<ApolloClientKeys, ApolloClient<any>>;
|
|
19
|
+
defaultClient: ApolloClient<any>;
|
|
20
|
+
}
|
|
21
|
+
declare module '#app' {
|
|
22
|
+
interface RuntimeNuxtHooks extends ModuleRuntimeHooks {
|
|
23
|
+
}
|
|
24
|
+
interface NuxtApp {
|
|
25
|
+
$apolloHelpers: DollarApolloHelpers;
|
|
26
|
+
$apollo: DollarApollo;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
declare module 'vue' {
|
|
30
|
+
interface ComponentCustomProperties {
|
|
31
|
+
$apolloHelpers: DollarApolloHelpers;
|
|
32
|
+
$apollo: DollarApollo;
|
|
33
|
+
}
|
|
34
|
+
}
|
package/dist/runtime/plugin.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import destr from "destr";
|
|
1
|
+
import { destr } from "destr";
|
|
2
2
|
import { onError } from "@apollo/client/link/error";
|
|
3
3
|
import { getMainDefinition } from "@apollo/client/utilities";
|
|
4
|
+
import { createApolloProvider } from "@vue/apollo-option";
|
|
4
5
|
import { ApolloClients, provideApolloClients } from "@vue/apollo-composable";
|
|
5
6
|
import { ApolloClient, ApolloLink, InMemoryCache, split } from "@apollo/client/core";
|
|
6
7
|
import createUploadLink from "apollo-upload-client/createUploadLink.mjs";
|
|
@@ -13,20 +14,26 @@ import createRestartableClient from "./ws.mjs";
|
|
|
13
14
|
import { useApollo } from "./composables.mjs";
|
|
14
15
|
import PusherLink from "./pusher.mjs";
|
|
15
16
|
import { ref, useCookie, defineNuxtPlugin, useRequestHeaders } from "#imports";
|
|
16
|
-
import NuxtApollo from "#apollo";
|
|
17
|
+
import { NuxtApollo } from "#apollo";
|
|
17
18
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
18
19
|
const requestCookies = process.server && NuxtApollo.proxyCookies && useRequestHeaders(["cookie"]) || void 0;
|
|
19
20
|
const clients = {};
|
|
20
21
|
for (const [key, clientConfig] of Object.entries(NuxtApollo.clients)) {
|
|
21
22
|
const getAuth = async () => {
|
|
22
|
-
const token = ref();
|
|
23
|
+
const token = ref(null);
|
|
23
24
|
await nuxtApp.callHook("apollo:auth", { token, client: key });
|
|
24
25
|
if (!token.value) {
|
|
25
26
|
if (clientConfig.tokenStorage === "cookie") {
|
|
26
27
|
if (process.client) {
|
|
27
|
-
|
|
28
|
+
const t = useCookie(clientConfig.tokenName).value;
|
|
29
|
+
if (t) {
|
|
30
|
+
token.value = t;
|
|
31
|
+
}
|
|
28
32
|
} else if (requestCookies?.cookie) {
|
|
29
|
-
|
|
33
|
+
const t = requestCookies.cookie.split(";").find((c) => c.trim().startsWith(`${clientConfig.tokenName}=`))?.split("=")?.[1];
|
|
34
|
+
if (t) {
|
|
35
|
+
token.value = t;
|
|
36
|
+
}
|
|
30
37
|
}
|
|
31
38
|
} else if (process.client && clientConfig.tokenStorage === "localStorage") {
|
|
32
39
|
token.value = localStorage.getItem(clientConfig.tokenName);
|
|
@@ -187,6 +194,7 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
187
194
|
}
|
|
188
195
|
provideApolloClients(clients);
|
|
189
196
|
nuxtApp.vueApp.provide(ApolloClients, clients);
|
|
197
|
+
nuxtApp.vueApp.use(createApolloProvider({ defaultClient: clients?.default }));
|
|
190
198
|
nuxtApp._apolloClients = clients;
|
|
191
199
|
const defaultClient = clients?.default;
|
|
192
200
|
return {
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { ClientOptions } from 'graphql-ws';
|
|
2
|
+
import { HttpOptions, DefaultOptions, InMemoryCacheConfig } from '@apollo/client';
|
|
3
|
+
import { CookieOptions } from 'nuxt/app';
|
|
4
|
+
|
|
5
|
+
type CookieAttributes = Omit< CookieOptions, 'encode' | 'decode' | 'expires' | 'default'>;
|
|
6
|
+
|
|
7
|
+
type Pusher = {
|
|
8
|
+
cluster: string;
|
|
9
|
+
wsHost: string;
|
|
10
|
+
wsPort: number;
|
|
11
|
+
forceTLS: boolean;
|
|
12
|
+
channelEndpoint: string;
|
|
13
|
+
pusherAppKey: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type ClientConfig = {
|
|
17
|
+
/**
|
|
18
|
+
* The GraphQL endpoint.
|
|
19
|
+
* @type {string}
|
|
20
|
+
*/
|
|
21
|
+
httpEndpoint: string;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Provide a GraphQL endpoint to be used client-side. Overrides `httpEndpoint`.
|
|
25
|
+
* @type {string}
|
|
26
|
+
**/
|
|
27
|
+
browserHttpEndpoint?: string;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Provide additional configuration for the `HttpLink`.
|
|
31
|
+
* See https://www.apollographql.com/docs/link/links/http.html#options
|
|
32
|
+
* @type {HttpOptions}
|
|
33
|
+
**/
|
|
34
|
+
httpLinkOptions?: Omit<HttpOptions, 'uri'>;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Provide additional configuration for the `GraphQLWsLink`.
|
|
38
|
+
* See https://github.com/enisdenjo/graphql-ws/blob/master/docs/interfaces/client.ClientOptions.md
|
|
39
|
+
**/
|
|
40
|
+
wsLinkOptions?: Omit<ClientOptions, 'url' | 'connectionParams'>;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Specify a websocket endpoint to be used for subscriptions.
|
|
44
|
+
* The `wss` protocol is recommended in production.
|
|
45
|
+
* @type {string}
|
|
46
|
+
**/
|
|
47
|
+
wsEndpoint?: string;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Specify if the client should solely use WebSocket.
|
|
51
|
+
* requires `wsEndpoint`.
|
|
52
|
+
* @type {boolean}
|
|
53
|
+
* @default false
|
|
54
|
+
**/
|
|
55
|
+
websocketsOnly?: boolean;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Specify a pusher config to be used for subscriptions.
|
|
59
|
+
* @type {Pusher}
|
|
60
|
+
**/
|
|
61
|
+
pusher?: Pusher
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Specify if the client should be able to connect to the Apollo Client Devtools in production mode.
|
|
65
|
+
* @type {boolean}
|
|
66
|
+
* @default false
|
|
67
|
+
**/
|
|
68
|
+
connectToDevTools?: boolean;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Configure default options to be applied to the apollo client.
|
|
72
|
+
**/
|
|
73
|
+
defaultOptions?: DefaultOptions;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Configure the in-memory cache.
|
|
77
|
+
**/
|
|
78
|
+
inMemoryCacheOptions?: InMemoryCacheConfig;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Specify the name under which the token will be stored.
|
|
82
|
+
* as in either a cookie or localStorage.
|
|
83
|
+
* @type {string}
|
|
84
|
+
* @default "apollo:<client-name>.token"
|
|
85
|
+
*/
|
|
86
|
+
tokenName?: string;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Specify if the auth token should be stored in `cookie` or `localStorage`.
|
|
90
|
+
* `Cookie` storage is required for SSR.
|
|
91
|
+
* @type {string}
|
|
92
|
+
* @default "cookie"
|
|
93
|
+
**/
|
|
94
|
+
tokenStorage?: 'cookie' | 'localStorage';
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Specify the Authentication scheme.
|
|
98
|
+
* @type {string}
|
|
99
|
+
* @default "Bearer"
|
|
100
|
+
**/
|
|
101
|
+
authType?: string | null;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Name of the Authentication token header.
|
|
105
|
+
* @type {string}
|
|
106
|
+
* @default "Authorization"
|
|
107
|
+
*/
|
|
108
|
+
authHeader?: string;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Configuration for the auth cookie.
|
|
112
|
+
**/
|
|
113
|
+
cookieAttributes?: CookieAttributes;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Name of the CSRF token header.
|
|
117
|
+
* @type {string}
|
|
118
|
+
* @default "X-CSRF-TOKEN"
|
|
119
|
+
*/
|
|
120
|
+
csrfHeader?: string
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Enable automatic persisted queries.
|
|
124
|
+
* @type {boolean}
|
|
125
|
+
* @default false
|
|
126
|
+
*/
|
|
127
|
+
persistedQueries?: boolean
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
interface NuxtApolloConfig<T = false> {
|
|
131
|
+
/**
|
|
132
|
+
* Determine if vue-apollo composables should be automatically imported.
|
|
133
|
+
* @type {boolean}
|
|
134
|
+
* @default true
|
|
135
|
+
**/
|
|
136
|
+
autoImports?: boolean;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Configuration of the Apollo clients.
|
|
140
|
+
**/
|
|
141
|
+
clients?: Record< string, T extends false ? string | ClientConfig : ClientConfig >;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Default options to be applied to all Apollo clients.
|
|
145
|
+
* This is useful for setting global defaults, and is overridden by `defaultOptions` passed directly to clients.
|
|
146
|
+
**/
|
|
147
|
+
defaultOptions?: DefaultOptions;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Pass cookies from the browser to the GraphQL API in SSR mode.
|
|
151
|
+
*
|
|
152
|
+
* @type boolean
|
|
153
|
+
* @default true
|
|
154
|
+
* */
|
|
155
|
+
proxyCookies?: boolean;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Specify the Authentication scheme.
|
|
159
|
+
* @type {string}
|
|
160
|
+
* @default 'Bearer'
|
|
161
|
+
**/
|
|
162
|
+
authType?: string;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Name of the Authentication token header.
|
|
166
|
+
* @type {string}
|
|
167
|
+
* @default "Authorization"
|
|
168
|
+
*/
|
|
169
|
+
authHeader?: string;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Name of the CSRF token header.
|
|
173
|
+
* @type {string}
|
|
174
|
+
* @default "X-CSRF-TOKEN"
|
|
175
|
+
*/
|
|
176
|
+
csrfHeader?: string;
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Specify if the auth token should be stored in `cookie` or `localStorage`.
|
|
180
|
+
* `Cookie` storage is required for SSR.
|
|
181
|
+
* @type {string}
|
|
182
|
+
* @default "cookie"
|
|
183
|
+
**/
|
|
184
|
+
tokenStorage?: 'cookie' | 'localStorage';
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Configuration for the auth cookie.
|
|
188
|
+
**/
|
|
189
|
+
cookieAttributes?: CookieAttributes;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Apollo client awareness instructs the client to send two additional headers
|
|
193
|
+
* `apollographql-client-name` and `apollographql-client-version` in each HTTP request.
|
|
194
|
+
* This behavior is disabled by default.
|
|
195
|
+
* @type {boolean}
|
|
196
|
+
* @default false
|
|
197
|
+
*/
|
|
198
|
+
clientAwareness?: boolean
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export type { ClientConfig as C, NuxtApolloConfig as N };
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { ClientOptions } from 'graphql-ws';
|
|
2
|
+
import { HttpOptions, DefaultOptions, InMemoryCacheConfig } from '@apollo/client';
|
|
3
|
+
import { CookieOptions } from 'nuxt/app';
|
|
4
|
+
|
|
5
|
+
type CookieAttributes = Omit< CookieOptions, 'encode' | 'decode' | 'expires' | 'default'>;
|
|
6
|
+
|
|
7
|
+
type Pusher = {
|
|
8
|
+
cluster: string;
|
|
9
|
+
wsHost: string;
|
|
10
|
+
wsPort: number;
|
|
11
|
+
forceTLS: boolean;
|
|
12
|
+
channelEndpoint: string;
|
|
13
|
+
pusherAppKey: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type ClientConfig = {
|
|
17
|
+
/**
|
|
18
|
+
* The GraphQL endpoint.
|
|
19
|
+
* @type {string}
|
|
20
|
+
*/
|
|
21
|
+
httpEndpoint: string;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Provide a GraphQL endpoint to be used client-side. Overrides `httpEndpoint`.
|
|
25
|
+
* @type {string}
|
|
26
|
+
**/
|
|
27
|
+
browserHttpEndpoint?: string;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Provide additional configuration for the `HttpLink`.
|
|
31
|
+
* See https://www.apollographql.com/docs/link/links/http.html#options
|
|
32
|
+
* @type {HttpOptions}
|
|
33
|
+
**/
|
|
34
|
+
httpLinkOptions?: Omit<HttpOptions, 'uri'>;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Provide additional configuration for the `GraphQLWsLink`.
|
|
38
|
+
* See https://github.com/enisdenjo/graphql-ws/blob/master/docs/interfaces/client.ClientOptions.md
|
|
39
|
+
**/
|
|
40
|
+
wsLinkOptions?: Omit<ClientOptions, 'url' | 'connectionParams'>;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Specify a websocket endpoint to be used for subscriptions.
|
|
44
|
+
* The `wss` protocol is recommended in production.
|
|
45
|
+
* @type {string}
|
|
46
|
+
**/
|
|
47
|
+
wsEndpoint?: string;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Specify if the client should solely use WebSocket.
|
|
51
|
+
* requires `wsEndpoint`.
|
|
52
|
+
* @type {boolean}
|
|
53
|
+
* @default false
|
|
54
|
+
**/
|
|
55
|
+
websocketsOnly?: boolean;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Specify a pusher config to be used for subscriptions.
|
|
59
|
+
* @type {Pusher}
|
|
60
|
+
**/
|
|
61
|
+
pusher?: Pusher
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Specify if the client should be able to connect to the Apollo Client Devtools in production mode.
|
|
65
|
+
* @type {boolean}
|
|
66
|
+
* @default false
|
|
67
|
+
**/
|
|
68
|
+
connectToDevTools?: boolean;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Configure default options to be applied to the apollo client.
|
|
72
|
+
**/
|
|
73
|
+
defaultOptions?: DefaultOptions;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Configure the in-memory cache.
|
|
77
|
+
**/
|
|
78
|
+
inMemoryCacheOptions?: InMemoryCacheConfig;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Specify the name under which the token will be stored.
|
|
82
|
+
* as in either a cookie or localStorage.
|
|
83
|
+
* @type {string}
|
|
84
|
+
* @default "apollo:<client-name>.token"
|
|
85
|
+
*/
|
|
86
|
+
tokenName?: string;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Specify if the auth token should be stored in `cookie` or `localStorage`.
|
|
90
|
+
* `Cookie` storage is required for SSR.
|
|
91
|
+
* @type {string}
|
|
92
|
+
* @default "cookie"
|
|
93
|
+
**/
|
|
94
|
+
tokenStorage?: 'cookie' | 'localStorage';
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Specify the Authentication scheme.
|
|
98
|
+
* @type {string}
|
|
99
|
+
* @default "Bearer"
|
|
100
|
+
**/
|
|
101
|
+
authType?: string | null;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Name of the Authentication token header.
|
|
105
|
+
* @type {string}
|
|
106
|
+
* @default "Authorization"
|
|
107
|
+
*/
|
|
108
|
+
authHeader?: string;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Configuration for the auth cookie.
|
|
112
|
+
**/
|
|
113
|
+
cookieAttributes?: CookieAttributes;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Name of the CSRF token header.
|
|
117
|
+
* @type {string}
|
|
118
|
+
* @default "X-CSRF-TOKEN"
|
|
119
|
+
*/
|
|
120
|
+
csrfHeader?: string
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Enable automatic persisted queries.
|
|
124
|
+
* @type {boolean}
|
|
125
|
+
* @default false
|
|
126
|
+
*/
|
|
127
|
+
persistedQueries?: boolean
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
interface NuxtApolloConfig<T = false> {
|
|
131
|
+
/**
|
|
132
|
+
* Determine if vue-apollo composables should be automatically imported.
|
|
133
|
+
* @type {boolean}
|
|
134
|
+
* @default true
|
|
135
|
+
**/
|
|
136
|
+
autoImports?: boolean;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Configuration of the Apollo clients.
|
|
140
|
+
**/
|
|
141
|
+
clients?: Record< string, T extends false ? string | ClientConfig : ClientConfig >;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Default options to be applied to all Apollo clients.
|
|
145
|
+
* This is useful for setting global defaults, and is overridden by `defaultOptions` passed directly to clients.
|
|
146
|
+
**/
|
|
147
|
+
defaultOptions?: DefaultOptions;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Pass cookies from the browser to the GraphQL API in SSR mode.
|
|
151
|
+
*
|
|
152
|
+
* @type boolean
|
|
153
|
+
* @default true
|
|
154
|
+
* */
|
|
155
|
+
proxyCookies?: boolean;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Specify the Authentication scheme.
|
|
159
|
+
* @type {string}
|
|
160
|
+
* @default 'Bearer'
|
|
161
|
+
**/
|
|
162
|
+
authType?: string;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Name of the Authentication token header.
|
|
166
|
+
* @type {string}
|
|
167
|
+
* @default "Authorization"
|
|
168
|
+
*/
|
|
169
|
+
authHeader?: string;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Name of the CSRF token header.
|
|
173
|
+
* @type {string}
|
|
174
|
+
* @default "X-CSRF-TOKEN"
|
|
175
|
+
*/
|
|
176
|
+
csrfHeader?: string;
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Specify if the auth token should be stored in `cookie` or `localStorage`.
|
|
180
|
+
* `Cookie` storage is required for SSR.
|
|
181
|
+
* @type {string}
|
|
182
|
+
* @default "cookie"
|
|
183
|
+
**/
|
|
184
|
+
tokenStorage?: 'cookie' | 'localStorage';
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Configuration for the auth cookie.
|
|
188
|
+
**/
|
|
189
|
+
cookieAttributes?: CookieAttributes;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Apollo client awareness instructs the client to send two additional headers
|
|
193
|
+
* `apollographql-client-name` and `apollographql-client-version` in each HTTP request.
|
|
194
|
+
* This behavior is disabled by default.
|
|
195
|
+
* @type {boolean}
|
|
196
|
+
* @default false
|
|
197
|
+
*/
|
|
198
|
+
clientAwareness?: boolean
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export type { ClientConfig as C, NuxtApolloConfig as N };
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
|
|
2
|
+
import type { ModuleOptions, ModuleRuntimeConfig, ModulePublicRuntimeConfig } from './module.js'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
declare module '@nuxt/schema' {
|
|
6
|
+
interface NuxtConfig { ['apollo']?: Partial<ModuleOptions> }
|
|
7
|
+
interface NuxtOptions { ['apollo']?: ModuleOptions }
|
|
8
|
+
interface RuntimeConfig extends ModuleRuntimeConfig {}
|
|
9
|
+
interface PublicRuntimeConfig extends ModulePublicRuntimeConfig {}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
declare module 'nuxt/schema' {
|
|
13
|
+
interface NuxtConfig { ['apollo']?: Partial<ModuleOptions> }
|
|
14
|
+
interface NuxtOptions { ['apollo']?: ModuleOptions }
|
|
15
|
+
interface RuntimeConfig extends ModuleRuntimeConfig {}
|
|
16
|
+
interface PublicRuntimeConfig extends ModulePublicRuntimeConfig {}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
export type { ErrorResponse } from './module.js'
|
package/dist/types.d.ts
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
|
|
2
|
-
import { ModuleOptions } from './module'
|
|
2
|
+
import type { ModuleOptions, ModuleRuntimeConfig, ModulePublicRuntimeConfig } from './module'
|
|
3
|
+
|
|
3
4
|
|
|
4
5
|
declare module '@nuxt/schema' {
|
|
5
6
|
interface NuxtConfig { ['apollo']?: Partial<ModuleOptions> }
|
|
6
7
|
interface NuxtOptions { ['apollo']?: ModuleOptions }
|
|
8
|
+
interface RuntimeConfig extends ModuleRuntimeConfig {}
|
|
9
|
+
interface PublicRuntimeConfig extends ModulePublicRuntimeConfig {}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
declare module 'nuxt/schema' {
|
|
13
|
+
interface NuxtConfig { ['apollo']?: Partial<ModuleOptions> }
|
|
14
|
+
interface NuxtOptions { ['apollo']?: ModuleOptions }
|
|
15
|
+
interface RuntimeConfig extends ModuleRuntimeConfig {}
|
|
16
|
+
interface PublicRuntimeConfig extends ModulePublicRuntimeConfig {}
|
|
7
17
|
}
|
|
8
18
|
|
|
9
19
|
|
|
10
|
-
export { ErrorResponse } from './module'
|
|
20
|
+
export type { ErrorResponse } from './module'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gambalabs/apollo",
|
|
3
|
-
"version": "6.0.0-alpha.
|
|
3
|
+
"version": "6.0.0-alpha.19",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": "https://github.com/GambaLabs/apollo",
|
|
6
6
|
"homepage": "https://apollo.nuxtjs.org",
|
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
".": {
|
|
10
10
|
"types": "./dist/types.d.ts",
|
|
11
11
|
"import": "./dist/module.mjs"
|
|
12
|
+
},
|
|
13
|
+
"./config": {
|
|
14
|
+
"types": "./dist/config.d.ts",
|
|
15
|
+
"import": "./dist/config.mjs"
|
|
12
16
|
}
|
|
13
17
|
},
|
|
14
18
|
"main": "./dist/module.mjs",
|
|
@@ -17,29 +21,30 @@
|
|
|
17
21
|
"dist"
|
|
18
22
|
],
|
|
19
23
|
"dependencies": {
|
|
20
|
-
"@apollo/client": "^3.
|
|
21
|
-
"@nuxt/kit": "^3.
|
|
24
|
+
"@apollo/client": "^3.9.5",
|
|
25
|
+
"@nuxt/kit": "^3.10.3",
|
|
22
26
|
"@rollup/plugin-graphql": "^2.0.4",
|
|
23
|
-
"@vue/apollo-composable": "4.0.
|
|
27
|
+
"@vue/apollo-composable": "^4.0.1",
|
|
24
28
|
"apollo-upload-client": "^18.0.1",
|
|
25
29
|
"crypto-hash": "^2.0.1",
|
|
26
|
-
"
|
|
27
|
-
"
|
|
30
|
+
"@vue/apollo-option": "^4.0.0",
|
|
31
|
+
"defu": "^6.1.4",
|
|
32
|
+
"destr": "^2.0.3",
|
|
28
33
|
"graphql": "^16.8.1",
|
|
29
34
|
"graphql-tag": "^2.12.6",
|
|
30
|
-
"graphql-ws": "^5.
|
|
35
|
+
"graphql-ws": "^5.15.0",
|
|
31
36
|
"jiti": "^1.21.0",
|
|
32
37
|
"ohash": "^1.1.3",
|
|
33
38
|
"pusher-js": "^8.3.0"
|
|
34
39
|
},
|
|
35
40
|
"devDependencies": {
|
|
36
|
-
"@nuxt/module-builder": "^0.
|
|
37
|
-
"@nuxt/schema": "^3.
|
|
38
|
-
"@nuxt/ui": "^
|
|
41
|
+
"@nuxt/module-builder": "^0.5.5",
|
|
42
|
+
"@nuxt/schema": "^3.10.3",
|
|
43
|
+
"@nuxt/ui": "^2.14.1",
|
|
39
44
|
"@nuxtjs/eslint-config-typescript": "^12.1.0",
|
|
40
|
-
"@types/node": "^
|
|
41
|
-
"eslint": "^8.
|
|
42
|
-
"nuxt": "^3.
|
|
45
|
+
"@types/node": "^20.11.24",
|
|
46
|
+
"eslint": "^8.57.0",
|
|
47
|
+
"nuxt": "^3.10.3"
|
|
43
48
|
},
|
|
44
49
|
"publishConfig": {
|
|
45
50
|
"access": "public"
|
|
@@ -47,12 +52,14 @@
|
|
|
47
52
|
"resolutions": {
|
|
48
53
|
"@nuxtjs/apollo": "link:."
|
|
49
54
|
},
|
|
50
|
-
"packageManager": "pnpm@
|
|
55
|
+
"packageManager": "pnpm@8.15.2",
|
|
51
56
|
"scripts": {
|
|
52
|
-
"build": "nuxt-module-build",
|
|
57
|
+
"build": "nuxt-module-build build",
|
|
53
58
|
"dev": "nuxi dev playground --dotenv .env --host",
|
|
54
59
|
"dev:build": "nuxi build playground",
|
|
55
|
-
"dev:prepare": "nuxt-module-build --stub && nuxi prepare playground",
|
|
60
|
+
"dev:prepare": "nuxt-module-build build --stub && nuxi prepare playground",
|
|
61
|
+
"lint": "eslint --ext .js,.ts,.vue --ignore-path .gitignore .",
|
|
62
|
+
"lint:fix": "eslint --fix --ext .js,.ts,.vue --ignore-path .gitignore .",
|
|
56
63
|
"release": "standard-version --prerelease alpha && git push --follow-tags && pnpm publish --tag next"
|
|
57
64
|
}
|
|
58
65
|
}
|