nuxt-graphql-middleware 5.0.0-alpha.9 → 5.1.0
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 +101 -19
- package/dist/client/200.html +8 -8
- package/dist/client/404.html +8 -8
- package/dist/client/_nuxt/{C9pb_2rp.js → CPiV13Ng.js} +2 -2
- package/dist/client/_nuxt/CQCiRbEL.js +1 -0
- package/dist/client/_nuxt/CYI2eNUl.js +1 -0
- package/dist/client/_nuxt/UAIVpYSK.js +25 -0
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/48332277-c4ad-4d6a-8f09-7a58a109c32d.json +1 -0
- package/dist/client/_nuxt/error-404.Bbd2eCoc.css +1 -0
- package/dist/client/_nuxt/error-500.Cd2cwFc3.css +1 -0
- package/dist/client/_nuxt/{BLvMh1Ga.js → u1b7LyOw.js} +1 -1
- package/dist/client/index.html +8 -8
- package/dist/client-options.d.mts +6 -0
- package/dist/client-options.mjs +5 -0
- package/dist/module.d.mts +63 -181
- package/dist/module.json +4 -4
- package/dist/module.mjs +435 -92
- package/dist/runtime/components/CodeFrame.vue +19 -28
- package/dist/runtime/components/CodeFrame.vue.d.ts +7 -0
- package/dist/runtime/components/DevModeOverlay.vue +25 -33
- package/dist/runtime/components/DevModeOverlay.vue.d.ts +3 -0
- package/dist/runtime/components/ErrorExtensions.vue +9 -11
- package/dist/runtime/components/ErrorExtensions.vue.d.ts +5 -0
- package/dist/runtime/components/ErrorGroup.vue +28 -39
- package/dist/runtime/components/ErrorGroup.vue.d.ts +9 -0
- package/dist/runtime/composables/nuxtApp.d.ts +30 -2
- package/dist/runtime/composables/nuxtApp.js +66 -24
- package/dist/runtime/composables/useAsyncGraphqlQuery.js +28 -25
- package/dist/runtime/composables/useGraphqlMutation.d.ts +1 -1
- package/dist/runtime/composables/useGraphqlMutation.js +11 -16
- package/dist/runtime/composables/useGraphqlQuery.d.ts +1 -1
- package/dist/runtime/composables/useGraphqlQuery.js +7 -25
- package/dist/runtime/composables/useGraphqlUploadMutation.js +1 -1
- package/dist/runtime/helpers/ClientCache.d.ts +1 -0
- package/dist/runtime/helpers/ClientCache.js +12 -0
- package/dist/runtime/helpers/composables.d.ts +8 -0
- package/dist/runtime/helpers/composables.js +27 -0
- package/dist/runtime/helpers/index.d.ts +0 -4
- package/dist/runtime/helpers/index.js +0 -13
- package/dist/runtime/helpers/queryEncoding.d.ts +11 -0
- package/dist/runtime/helpers/queryEncoding.js +89 -0
- package/dist/runtime/plugins/devMode.js +2 -1
- package/dist/runtime/server/api/mutation.js +2 -1
- package/dist/runtime/server/api/query.js +7 -8
- package/dist/runtime/server/utils/doGraphqlRequest.js +5 -4
- package/dist/runtime/server/utils/useGraphqlQuery.js +2 -2
- package/dist/runtime/settings/index.d.ts +1 -0
- package/dist/runtime/settings/index.js +1 -0
- package/dist/runtime/types.d.ts +2 -2
- package/dist/server-options.d.mts +8 -0
- package/dist/server-options.mjs +5 -0
- package/dist/shared/nuxt-graphql-middleware.-BeiPV4H.d.mts +566 -0
- package/dist/types.d.mts +1 -7
- package/dist/utils.d.mts +15 -0
- package/dist/utils.mjs +18 -0
- package/package.json +36 -32
- package/dist/client/_nuxt/CBwfSTyQ.js +0 -1
- package/dist/client/_nuxt/CPyoLiCY.js +0 -1
- package/dist/client/_nuxt/VpkRx2_e.js +0 -25
- package/dist/client/_nuxt/builds/meta/826a43da-d42c-4fbf-8dfd-2572141eaf8f.json +0 -1
- package/dist/client/_nuxt/error-404.BJkSn6RI.css +0 -1
- package/dist/client/_nuxt/error-500.TOCKLquH.css +0 -1
- package/dist/module.cjs +0 -5
- package/dist/module.d.ts +0 -210
- package/dist/runtime/clientOptions/index.d.ts +0 -2
- package/dist/runtime/clientOptions/index.js +0 -3
- package/dist/runtime/serverOptions/defineGraphqlServerOptions.d.ts +0 -4
- package/dist/runtime/serverOptions/defineGraphqlServerOptions.js +0 -3
- package/dist/runtime/serverOptions/index.d.ts +0 -2
- package/dist/runtime/serverOptions/index.js +0 -2
- package/dist/types.d.ts +0 -7
|
@@ -0,0 +1,566 @@
|
|
|
1
|
+
import { GraphQLSchema, GraphQLNamedType } from 'graphql';
|
|
2
|
+
import { Nuxt, ResolvedNuxtTemplate, WatchEvent } from 'nuxt/schema';
|
|
3
|
+
import { Resolver } from '@nuxt/kit';
|
|
4
|
+
import { RouterMethod } from 'h3';
|
|
5
|
+
import { Types } from '@graphql-codegen/plugin-helpers';
|
|
6
|
+
import { SchemaASTConfig } from '@graphql-codegen/schema-ast';
|
|
7
|
+
import { GeneratorOptions, GeneratorOutput } from 'graphql-typescript-deluxe';
|
|
8
|
+
|
|
9
|
+
type RpcItem = {
|
|
10
|
+
id: string;
|
|
11
|
+
timestamp?: number;
|
|
12
|
+
source: string;
|
|
13
|
+
name: string;
|
|
14
|
+
identifier: 'fragment' | 'query' | 'mutation';
|
|
15
|
+
filePath: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
interface ModuleOptions {
|
|
19
|
+
/**
|
|
20
|
+
* File glob patterns for the auto import feature.
|
|
21
|
+
*
|
|
22
|
+
* If left empty, no documents are auto imported.
|
|
23
|
+
*
|
|
24
|
+
* @default
|
|
25
|
+
* ```json
|
|
26
|
+
* ["**\/.{gql,graphql}", "!node_modules"]
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* // Load .graphql files from pages folder and from a node_modules dependency.
|
|
32
|
+
* const autoImportPatterns = [
|
|
33
|
+
* './pages/**\/*.graphql',
|
|
34
|
+
* 'node_modules/my_library/dist/**\/*.graphql'
|
|
35
|
+
* ]
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
autoImportPatterns?: string[];
|
|
39
|
+
/**
|
|
40
|
+
* The path where your graphql.config.ts is, relative to the location of nuxt.config.ts.
|
|
41
|
+
*
|
|
42
|
+
* Used to generate the correct paths in the graphql.config.ts file generated by the module.
|
|
43
|
+
*
|
|
44
|
+
* @default "./graphql.config.ts"
|
|
45
|
+
*/
|
|
46
|
+
graphqlConfigFilePath?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Additional raw documents to include.
|
|
49
|
+
*
|
|
50
|
+
* Useful if for example you need to generate queries during build time.
|
|
51
|
+
*
|
|
52
|
+
* @default []
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* const documents = [`
|
|
57
|
+
* query myQuery {
|
|
58
|
+
* articles {
|
|
59
|
+
* title
|
|
60
|
+
* id
|
|
61
|
+
* }
|
|
62
|
+
* }`,
|
|
63
|
+
* ...getGeneratedDocuments()
|
|
64
|
+
* ]
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
documents?: string[];
|
|
68
|
+
/**
|
|
69
|
+
* Wether the useGraphqlQuery, useGraphqlMutation and useGraphqlState
|
|
70
|
+
* composables should be included.
|
|
71
|
+
*
|
|
72
|
+
* @default ```ts
|
|
73
|
+
* true
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
includeComposables?: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Enable support for uploading files via GraphQL.
|
|
79
|
+
*
|
|
80
|
+
* When enabled, an additional `useGraphqlUploadMutation` composable is
|
|
81
|
+
* included, in addition to a new server endpoint that handles multi part
|
|
82
|
+
* file uploads for GraphQL mutations.
|
|
83
|
+
*/
|
|
84
|
+
enableFileUploads?: boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Enable detailled debugging messages.
|
|
87
|
+
*
|
|
88
|
+
* @default false
|
|
89
|
+
*/
|
|
90
|
+
debug?: boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Displays GraphQL response errors in an overlay in dev mode.
|
|
93
|
+
*/
|
|
94
|
+
errorOverlay?: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* The URL of the GraphQL server.
|
|
97
|
+
*
|
|
98
|
+
* For the runtime execution you can provide a method that determines the endpoint
|
|
99
|
+
* during runtime. See the server/graphqlMiddleware.serverOptions.ts documentation
|
|
100
|
+
* for more information.
|
|
101
|
+
*/
|
|
102
|
+
graphqlEndpoint: string;
|
|
103
|
+
/**
|
|
104
|
+
* Download the GraphQL schema and store it on disk.
|
|
105
|
+
*
|
|
106
|
+
* Usually you'll want to only enable this during dev mode.
|
|
107
|
+
*
|
|
108
|
+
* @default true
|
|
109
|
+
*/
|
|
110
|
+
downloadSchema?: boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Path to the GraphQL schema file.
|
|
113
|
+
*
|
|
114
|
+
* If `downloadSchema` is `true`, the downloaded schema is written to this specified path.
|
|
115
|
+
* If `downloadSchema` is `false`, this file must be present in order to generate types.
|
|
116
|
+
*
|
|
117
|
+
* @default './schema.graphql'
|
|
118
|
+
*/
|
|
119
|
+
schemaPath?: string;
|
|
120
|
+
/**
|
|
121
|
+
* The prefix for the server route.
|
|
122
|
+
*
|
|
123
|
+
* @default ```ts
|
|
124
|
+
* "/api/graphql_middleware"
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
serverApiPrefix?: string;
|
|
128
|
+
/**
|
|
129
|
+
* Logs only errors.
|
|
130
|
+
*
|
|
131
|
+
* When enabled only errors are logged to the console when generating the GraphQL operations.
|
|
132
|
+
* If false, all operations are logged, including valid ones.
|
|
133
|
+
*/
|
|
134
|
+
logOnlyErrors?: boolean;
|
|
135
|
+
/**
|
|
136
|
+
* Options for graphql-typescript-deluxe code generator.
|
|
137
|
+
*
|
|
138
|
+
* @see [GeneratorOptions](https://github.com/dulnan/graphql-typescript-deluxe/blob/main/src/types/options.ts#L193)
|
|
139
|
+
*/
|
|
140
|
+
codegenConfig?: GeneratorOptions;
|
|
141
|
+
/**
|
|
142
|
+
* Configuration for graphql-codegen when downloading the schema.
|
|
143
|
+
*/
|
|
144
|
+
codegenSchemaConfig?: {
|
|
145
|
+
/**
|
|
146
|
+
* Configure how the schema.graphql file should be generated.
|
|
147
|
+
*
|
|
148
|
+
* @see [SchemaASTConfig](https://github.com/dotansimha/graphql-code-generator/blob/master/packages/plugins/other/schema-ast/src/index.ts#L23)
|
|
149
|
+
*/
|
|
150
|
+
schemaAstConfig?: SchemaASTConfig;
|
|
151
|
+
/**
|
|
152
|
+
* Configure how the schema-ast introspection request should be made.
|
|
153
|
+
*
|
|
154
|
+
* Usually this is where you can provide a custom authentication header:
|
|
155
|
+
*
|
|
156
|
+
* ```typescript
|
|
157
|
+
* const codegenSchemaConfig = {
|
|
158
|
+
* urlSchemaOptions: {
|
|
159
|
+
* headers: {
|
|
160
|
+
* authentication: 'foobar',
|
|
161
|
+
* }
|
|
162
|
+
* }
|
|
163
|
+
* }
|
|
164
|
+
* ```
|
|
165
|
+
*
|
|
166
|
+
* @see [Types.UrlSchemaOptions](https://github.com/dotansimha/graphql-code-generator/blob/master/packages/utils/plugins-helpers/src/types.ts#L82)
|
|
167
|
+
*/
|
|
168
|
+
urlSchemaOptions?: Types.UrlSchemaOptions;
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* Enable Nuxt DevTools integration.
|
|
172
|
+
*
|
|
173
|
+
* @default true
|
|
174
|
+
*/
|
|
175
|
+
devtools?: boolean;
|
|
176
|
+
/**
|
|
177
|
+
* Client caching configuration.
|
|
178
|
+
*/
|
|
179
|
+
clientCache?: {
|
|
180
|
+
/**
|
|
181
|
+
* Whether client caching should be enabled.
|
|
182
|
+
*
|
|
183
|
+
* Note that if you set this to false during build, the cache will not be
|
|
184
|
+
* available at all. If you intend to enable/disable it using app config at
|
|
185
|
+
* runtime, it *must* be enabled at build!
|
|
186
|
+
*
|
|
187
|
+
* @default false
|
|
188
|
+
*/
|
|
189
|
+
enabled?: boolean;
|
|
190
|
+
/**
|
|
191
|
+
* The maximum number of cache entries.
|
|
192
|
+
*
|
|
193
|
+
* @default 100
|
|
194
|
+
*/
|
|
195
|
+
maxSize?: number;
|
|
196
|
+
};
|
|
197
|
+
/**
|
|
198
|
+
* Experimental features.
|
|
199
|
+
*/
|
|
200
|
+
experimental?: {
|
|
201
|
+
/**
|
|
202
|
+
* Enables improved encoding for GraphQL query param encoding.
|
|
203
|
+
*
|
|
204
|
+
* If enabled, query variables that are non-strings such as numbers or
|
|
205
|
+
* booleans are encoded as strings, with a prefix in their name to indicate
|
|
206
|
+
* the type.
|
|
207
|
+
*
|
|
208
|
+
* For example, given this object definining query variables:
|
|
209
|
+
*
|
|
210
|
+
* ```
|
|
211
|
+
* {
|
|
212
|
+
* name: 'John',
|
|
213
|
+
* age: 35,
|
|
214
|
+
* isUser: false
|
|
215
|
+
* }
|
|
216
|
+
* ```
|
|
217
|
+
*
|
|
218
|
+
* This would be encoded as:
|
|
219
|
+
*
|
|
220
|
+
* ```
|
|
221
|
+
* name=John&n:age=35&b:isUser=false
|
|
222
|
+
* ```
|
|
223
|
+
*
|
|
224
|
+
* This only works for flat primitive values. Nested objects or arrays are
|
|
225
|
+
* still encoded using the __variables fallback where all variables are
|
|
226
|
+
* JSON encoded.
|
|
227
|
+
*/
|
|
228
|
+
improvedQueryParamEncoding?: boolean;
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
declare const defaultOptions: ModuleOptions;
|
|
233
|
+
|
|
234
|
+
declare class ConsolePrompt {
|
|
235
|
+
private abortController;
|
|
236
|
+
confirm(message: string): Promise<'yes' | 'no' | 'cancel'>;
|
|
237
|
+
abort(): void;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
type TemplateOptions = {
|
|
241
|
+
path: string;
|
|
242
|
+
virtual?: boolean;
|
|
243
|
+
isFullPath?: boolean;
|
|
244
|
+
};
|
|
245
|
+
type GeneratorTemplateCallback = (output: GeneratorOutput, helper: ModuleHelper, collector: Collector) => string;
|
|
246
|
+
type StaticTemplateCallback = (helper: ModuleHelper) => string;
|
|
247
|
+
type GeneratorTemplate = {
|
|
248
|
+
type: 'generator';
|
|
249
|
+
options: TemplateOptions;
|
|
250
|
+
build: GeneratorTemplateCallback | null;
|
|
251
|
+
buildTypes: GeneratorTemplateCallback | null;
|
|
252
|
+
virtual?: boolean;
|
|
253
|
+
};
|
|
254
|
+
type StaticTemplate = {
|
|
255
|
+
type: 'static';
|
|
256
|
+
options: TemplateOptions;
|
|
257
|
+
build: StaticTemplateCallback | null;
|
|
258
|
+
buildTypes: StaticTemplateCallback | null;
|
|
259
|
+
virtual?: boolean;
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
type WithRequired<T, K extends keyof T> = T & {
|
|
263
|
+
[P in K]-?: T[P];
|
|
264
|
+
};
|
|
265
|
+
type RequiredModuleOptions = WithRequired<ModuleOptions, keyof typeof defaultOptions>;
|
|
266
|
+
type ModuleHelperResolvers = {
|
|
267
|
+
/**
|
|
268
|
+
* Resolver for paths relative to the module root.
|
|
269
|
+
*/
|
|
270
|
+
module: Resolver;
|
|
271
|
+
/**
|
|
272
|
+
* Resolve relative to the app's server directory.
|
|
273
|
+
*/
|
|
274
|
+
server: Resolver;
|
|
275
|
+
/**
|
|
276
|
+
* Resolve relative to the Nuxt src folder.
|
|
277
|
+
*/
|
|
278
|
+
src: Resolver;
|
|
279
|
+
/**
|
|
280
|
+
* Resolve relative to the Nuxt app directory.
|
|
281
|
+
*/
|
|
282
|
+
app: Resolver;
|
|
283
|
+
/**
|
|
284
|
+
* Resolve relative to the Nuxt root.
|
|
285
|
+
*
|
|
286
|
+
* Should be where nuxt.config.ts is located.
|
|
287
|
+
*/
|
|
288
|
+
root: Resolver;
|
|
289
|
+
};
|
|
290
|
+
type ModuleHelperPaths = {
|
|
291
|
+
runtimeTypes: string;
|
|
292
|
+
root: string;
|
|
293
|
+
nuxtConfig: string;
|
|
294
|
+
serverDir: string;
|
|
295
|
+
schema: string;
|
|
296
|
+
serverOptions: string | null;
|
|
297
|
+
clientOptions: string | null;
|
|
298
|
+
moduleBuildDir: string;
|
|
299
|
+
moduleTypesDir: string;
|
|
300
|
+
};
|
|
301
|
+
declare class ModuleHelper {
|
|
302
|
+
readonly nuxt: Nuxt;
|
|
303
|
+
readonly resolvers: ModuleHelperResolvers;
|
|
304
|
+
readonly paths: ModuleHelperPaths;
|
|
305
|
+
readonly isDev: boolean;
|
|
306
|
+
readonly options: RequiredModuleOptions;
|
|
307
|
+
readonly prompt: ConsolePrompt;
|
|
308
|
+
private nitroExternals;
|
|
309
|
+
private tsPaths;
|
|
310
|
+
constructor(nuxt: Nuxt, moduleUrl: string, options: ModuleOptions);
|
|
311
|
+
/**
|
|
312
|
+
* Find the path to the graphqlMiddleware.serverOptions.ts file.
|
|
313
|
+
*/
|
|
314
|
+
private findServerOptions;
|
|
315
|
+
private findClientOptions;
|
|
316
|
+
/**
|
|
317
|
+
* Transform the path relative to the module's build directory.
|
|
318
|
+
*
|
|
319
|
+
* @param path - The absolute path.
|
|
320
|
+
*
|
|
321
|
+
* @returns The path relative to the module's build directory.
|
|
322
|
+
*/
|
|
323
|
+
toModuleBuildRelative(path: string): string;
|
|
324
|
+
/**
|
|
325
|
+
* Transform the path relative to the Nuxt build directory.
|
|
326
|
+
*
|
|
327
|
+
* @param path - The absolute path.
|
|
328
|
+
*
|
|
329
|
+
* @returns The path relative to the module's build directory.
|
|
330
|
+
*/
|
|
331
|
+
toBuildRelative(path: string): string;
|
|
332
|
+
/**
|
|
333
|
+
* Get all file paths that match the import patterns.
|
|
334
|
+
*/
|
|
335
|
+
getImportPatternFiles(): Promise<string[]>;
|
|
336
|
+
matchesImportPattern(filePath: string): boolean;
|
|
337
|
+
addAlias(name: string, path: string): void;
|
|
338
|
+
inlineNitroExternals(arg: ResolvedNuxtTemplate | string): void;
|
|
339
|
+
transpile(path: string): void;
|
|
340
|
+
applyBuildConfig(): void;
|
|
341
|
+
processTemplate(path: string, content: string): string;
|
|
342
|
+
addTemplate(template: StaticTemplate): void;
|
|
343
|
+
addPlugin(name: string): void;
|
|
344
|
+
addServerHandler(name: string, path: string, method: RouterMethod): void;
|
|
345
|
+
addComposable(name: string): void;
|
|
346
|
+
addServerUtil(name: string): void;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
type CollectorWatchEventResult = {
|
|
350
|
+
hasChanged: boolean;
|
|
351
|
+
affectedOperations: string[];
|
|
352
|
+
error?: {
|
|
353
|
+
message: string;
|
|
354
|
+
};
|
|
355
|
+
};
|
|
356
|
+
declare class Collector {
|
|
357
|
+
private schema;
|
|
358
|
+
private helper;
|
|
359
|
+
/**
|
|
360
|
+
* All collected files.
|
|
361
|
+
*/
|
|
362
|
+
private files;
|
|
363
|
+
/**
|
|
364
|
+
* All documents provided by hooks.
|
|
365
|
+
*/
|
|
366
|
+
private hookDocuments;
|
|
367
|
+
/**
|
|
368
|
+
* All file paths provided by hooks.
|
|
369
|
+
*/
|
|
370
|
+
private hookFiles;
|
|
371
|
+
/**
|
|
372
|
+
* The code generator.
|
|
373
|
+
*/
|
|
374
|
+
private generator;
|
|
375
|
+
/**
|
|
376
|
+
* A map of operation name and timestamp when the operation was last validated.
|
|
377
|
+
*/
|
|
378
|
+
private operationTimestamps;
|
|
379
|
+
/**
|
|
380
|
+
* The generated operations and fragments.
|
|
381
|
+
*/
|
|
382
|
+
readonly rpcItems: Map<string, RpcItem>;
|
|
383
|
+
/**
|
|
384
|
+
* The registered templates.
|
|
385
|
+
*/
|
|
386
|
+
private templates;
|
|
387
|
+
/**
|
|
388
|
+
* The generated template contents.
|
|
389
|
+
*/
|
|
390
|
+
private templateResult;
|
|
391
|
+
private isInitialised;
|
|
392
|
+
constructor(schema: GraphQLSchema, helper: ModuleHelper);
|
|
393
|
+
reset(): Promise<void>;
|
|
394
|
+
updateSchema(schema: GraphQLSchema): Promise<void>;
|
|
395
|
+
private filePathToBuildRelative;
|
|
396
|
+
private filePathToSourceRelative;
|
|
397
|
+
private operationToLogEntry;
|
|
398
|
+
private getTemplate;
|
|
399
|
+
/**
|
|
400
|
+
* Executes code gen and performs validation for operations.
|
|
401
|
+
*/
|
|
402
|
+
private buildState;
|
|
403
|
+
private buildErrorMessage;
|
|
404
|
+
private logError;
|
|
405
|
+
/**
|
|
406
|
+
* Initialise the collector.
|
|
407
|
+
*
|
|
408
|
+
* In dev mode, the method will call itself recursively until all documents
|
|
409
|
+
* are valid.
|
|
410
|
+
*
|
|
411
|
+
* If not in dev mode the method will throw an error when documents are not
|
|
412
|
+
* valid.
|
|
413
|
+
*/
|
|
414
|
+
init(): Promise<void>;
|
|
415
|
+
addHookDocument(identifier: string, source: string): void;
|
|
416
|
+
addOrUpdateHookDocument(identifier: string, source: string): Promise<void>;
|
|
417
|
+
addHookFile(filePath: string): void;
|
|
418
|
+
/**
|
|
419
|
+
* Initialise the collector.
|
|
420
|
+
*/
|
|
421
|
+
private initDocuments;
|
|
422
|
+
/**
|
|
423
|
+
* Add a file.
|
|
424
|
+
*/
|
|
425
|
+
private addFile;
|
|
426
|
+
private matchesPatternOrExists;
|
|
427
|
+
private handleAdd;
|
|
428
|
+
private handleChange;
|
|
429
|
+
private handleUnlink;
|
|
430
|
+
private handleUnlinkDir;
|
|
431
|
+
/**
|
|
432
|
+
* Handle the watcher event for the given file path.
|
|
433
|
+
*/
|
|
434
|
+
handleWatchEvent(event: WatchEvent, filePath: string): Promise<CollectorWatchEventResult>;
|
|
435
|
+
/**
|
|
436
|
+
* Adds a virtual template (not written to disk) for both Nuxt and Nitro.
|
|
437
|
+
*
|
|
438
|
+
* For some reason a template written to disk works for both Nuxt and Nitro,
|
|
439
|
+
* but a virtual template requires adding two templates.
|
|
440
|
+
*/
|
|
441
|
+
private addVirtualTemplate;
|
|
442
|
+
/**
|
|
443
|
+
* Adds a template that dependes on Collector state.
|
|
444
|
+
*/
|
|
445
|
+
addTemplate(template: GeneratorTemplate): void;
|
|
446
|
+
/**
|
|
447
|
+
* Get the hook documents.
|
|
448
|
+
*/
|
|
449
|
+
getHookDocuments(): {
|
|
450
|
+
identifier: string;
|
|
451
|
+
source: string;
|
|
452
|
+
}[];
|
|
453
|
+
/**
|
|
454
|
+
* Get the hook documents.
|
|
455
|
+
*/
|
|
456
|
+
getHookFiles(): string[];
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Handles downloading, loading and saving the GraphQL schema.
|
|
461
|
+
*/
|
|
462
|
+
declare class SchemaProvider {
|
|
463
|
+
private helper;
|
|
464
|
+
/**
|
|
465
|
+
* The raw schema content.
|
|
466
|
+
*/
|
|
467
|
+
private schemaContent;
|
|
468
|
+
/**
|
|
469
|
+
* The parsed schema object.
|
|
470
|
+
*/
|
|
471
|
+
private schema;
|
|
472
|
+
constructor(helper: ModuleHelper);
|
|
473
|
+
init(): Promise<void>;
|
|
474
|
+
private loadFromDiskFallback;
|
|
475
|
+
/**
|
|
476
|
+
* Loads the schema from disk.
|
|
477
|
+
*
|
|
478
|
+
* @returns The schema contents from disk.
|
|
479
|
+
*/
|
|
480
|
+
private loadSchemaFromDisk;
|
|
481
|
+
/**
|
|
482
|
+
* Downloads the schema and saves it to disk.
|
|
483
|
+
*
|
|
484
|
+
* @returns The schema contents.
|
|
485
|
+
*/
|
|
486
|
+
private downloadSchema;
|
|
487
|
+
/**
|
|
488
|
+
* Determine if the schema exists on disk.
|
|
489
|
+
*
|
|
490
|
+
* @returns True if the schema file exists on disk.
|
|
491
|
+
*/
|
|
492
|
+
hasSchemaOnDisk(): Promise<boolean>;
|
|
493
|
+
/**
|
|
494
|
+
* Load the schema either from disk or by downloading it.
|
|
495
|
+
*
|
|
496
|
+
* @param forceDownload - Forces downloading the schema.
|
|
497
|
+
*/
|
|
498
|
+
loadSchema(opts?: {
|
|
499
|
+
forceDownload?: boolean;
|
|
500
|
+
forceDisk?: boolean;
|
|
501
|
+
}): Promise<void>;
|
|
502
|
+
/**
|
|
503
|
+
* Get the schema.
|
|
504
|
+
*
|
|
505
|
+
* @returns The parsed GraphQL schema object.
|
|
506
|
+
*/
|
|
507
|
+
getSchema(): GraphQLSchema;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* The public module context class.
|
|
512
|
+
*/
|
|
513
|
+
declare class ModuleContext {
|
|
514
|
+
private schemaProvider;
|
|
515
|
+
private collector;
|
|
516
|
+
constructor(schemaProvider: SchemaProvider, collector: Collector);
|
|
517
|
+
/**
|
|
518
|
+
* Return the GraphQL schema.
|
|
519
|
+
*
|
|
520
|
+
* Note that the schema may be updated during development, so it can become
|
|
521
|
+
* stale. Prefer using methods like `schemaHasType()` to query the schema.
|
|
522
|
+
*
|
|
523
|
+
* @returns The GraphQL schema.
|
|
524
|
+
*/
|
|
525
|
+
getSchema(): GraphQLSchema;
|
|
526
|
+
/**
|
|
527
|
+
* Check if the given GraphQL type (interface, concrete type, enum, input type)
|
|
528
|
+
* exists in the schema.
|
|
529
|
+
*
|
|
530
|
+
* @param name - The name of the type.
|
|
531
|
+
*
|
|
532
|
+
* @returns True if the type exists in the schema.
|
|
533
|
+
*/
|
|
534
|
+
schemaHasType(name: string): boolean;
|
|
535
|
+
/**
|
|
536
|
+
* Get a type from the schema.
|
|
537
|
+
*
|
|
538
|
+
* @param name - The name of the type.
|
|
539
|
+
*
|
|
540
|
+
* @returns The type.
|
|
541
|
+
*/
|
|
542
|
+
schemaGetType(name: string): GraphQLNamedType | undefined;
|
|
543
|
+
/**
|
|
544
|
+
* Add an additional static document.
|
|
545
|
+
*
|
|
546
|
+
* @param identifier - The unique identifier for your document.
|
|
547
|
+
* @param source - The document source.
|
|
548
|
+
*/
|
|
549
|
+
addDocument(identifier: string, source: string): ModuleContext;
|
|
550
|
+
/**
|
|
551
|
+
* Add or update an additional static document.
|
|
552
|
+
*
|
|
553
|
+
* @param identifier - The unique identifier for your document.
|
|
554
|
+
* @param source - The document source.
|
|
555
|
+
*/
|
|
556
|
+
addOrUpdateDocument(identifier: string, source: string): Promise<ModuleContext>;
|
|
557
|
+
/**
|
|
558
|
+
* Add an additional GraphQL file to import.
|
|
559
|
+
*
|
|
560
|
+
* @param filePath - The absolute path to the file.
|
|
561
|
+
*/
|
|
562
|
+
addImportFile(filePath: string): ModuleContext;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
export { ModuleContext as M };
|
|
566
|
+
export type { ModuleOptions as a };
|
package/dist/types.d.mts
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import type { default as Module } from './module.js'
|
|
4
|
-
|
|
5
|
-
export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
|
|
6
|
-
|
|
7
|
-
export { type GraphqlMiddlewareServerOptions } from './module.js'
|
|
1
|
+
export { type ModuleOptions, default } from './module.mjs'
|
package/dist/utils.d.mts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { M as ModuleContext } from './shared/nuxt-graphql-middleware.-BeiPV4H.mjs';
|
|
2
|
+
import 'graphql';
|
|
3
|
+
import 'nuxt/schema';
|
|
4
|
+
import '@nuxt/kit';
|
|
5
|
+
import 'h3';
|
|
6
|
+
import '@graphql-codegen/plugin-helpers';
|
|
7
|
+
import '@graphql-codegen/schema-ast';
|
|
8
|
+
import 'graphql-typescript-deluxe';
|
|
9
|
+
|
|
10
|
+
declare function useGraphqlModuleContext(): ModuleContext;
|
|
11
|
+
declare function useGraphqlModuleContext(options: {
|
|
12
|
+
nullOnMissing: true;
|
|
13
|
+
}): ModuleContext | null;
|
|
14
|
+
|
|
15
|
+
export { ModuleContext, useGraphqlModuleContext };
|
package/dist/utils.mjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useNuxt } from '@nuxt/kit';
|
|
2
|
+
|
|
3
|
+
const CONTEXT_KEY = "_nuxt_graphql_middleware";
|
|
4
|
+
function useGraphqlModuleContext(options) {
|
|
5
|
+
const nuxt = useNuxt();
|
|
6
|
+
const context = nuxt[CONTEXT_KEY];
|
|
7
|
+
if (!context) {
|
|
8
|
+
if (options?.nullOnMissing) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
throw new Error(
|
|
12
|
+
"nuxt-graphql-middleware context is not available. Make sure you call this method only after nuxt-graphql-middleware has been setup. If you call this in a module, make sure your module is declared after nuxt-graphql-middleware in your `modules` Nuxt config."
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
return context;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { useGraphqlModuleContext };
|