nuxt-graphql-middleware 5.0.0-alpha.2 → 5.0.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/200.html +2 -2
- package/dist/client/404.html +2 -2
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/106a09af-649a-473b-b0c7-0e4ce5709429.json +1 -0
- package/dist/client/index.html +2 -2
- package/dist/module.d.mts +6 -0
- package/dist/module.d.ts +6 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +175 -63
- package/dist/runtime/composables/nuxtApp.js +19 -0
- package/dist/runtime/settings/index.d.ts +5 -1
- package/dist/runtime/settings/index.js +2 -1
- package/package.json +2 -6
- package/dist/client/_nuxt/builds/meta/f823ebfd-daab-468f-8f6f-07a236da64bd.json +0 -1
package/dist/client/200.html
CHANGED
|
@@ -7,5 +7,5 @@
|
|
|
7
7
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-graphql-middleware/_nuxt/exxdaCPN.js">
|
|
8
8
|
<link rel="prefetch" as="style" crossorigin href="/__nuxt-graphql-middleware/_nuxt/error-500.TOCKLquH.css">
|
|
9
9
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-graphql-middleware/_nuxt/GOrnHr4p.js">
|
|
10
|
-
<script type="module" src="/__nuxt-graphql-middleware/_nuxt/BS583yk8.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},
|
|
11
|
-
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-graphql-middleware",buildId:"
|
|
10
|
+
<script type="module" src="/__nuxt-graphql-middleware/_nuxt/BS583yk8.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},1741337201293,false]</script>
|
|
11
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-graphql-middleware",buildId:"106a09af-649a-473b-b0c7-0e4ce5709429",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
package/dist/client/404.html
CHANGED
|
@@ -7,5 +7,5 @@
|
|
|
7
7
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-graphql-middleware/_nuxt/exxdaCPN.js">
|
|
8
8
|
<link rel="prefetch" as="style" crossorigin href="/__nuxt-graphql-middleware/_nuxt/error-500.TOCKLquH.css">
|
|
9
9
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-graphql-middleware/_nuxt/GOrnHr4p.js">
|
|
10
|
-
<script type="module" src="/__nuxt-graphql-middleware/_nuxt/BS583yk8.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},
|
|
11
|
-
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-graphql-middleware",buildId:"
|
|
10
|
+
<script type="module" src="/__nuxt-graphql-middleware/_nuxt/BS583yk8.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},1741337201293,false]</script>
|
|
11
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-graphql-middleware",buildId:"106a09af-649a-473b-b0c7-0e4ce5709429",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"id":"
|
|
1
|
+
{"id":"106a09af-649a-473b-b0c7-0e4ce5709429","timestamp":1741337191457}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"id":"106a09af-649a-473b-b0c7-0e4ce5709429","timestamp":1741337191457,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|
package/dist/client/index.html
CHANGED
|
@@ -7,5 +7,5 @@
|
|
|
7
7
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-graphql-middleware/_nuxt/exxdaCPN.js">
|
|
8
8
|
<link rel="prefetch" as="style" crossorigin href="/__nuxt-graphql-middleware/_nuxt/error-500.TOCKLquH.css">
|
|
9
9
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-graphql-middleware/_nuxt/GOrnHr4p.js">
|
|
10
|
-
<script type="module" src="/__nuxt-graphql-middleware/_nuxt/BS583yk8.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},
|
|
11
|
-
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-graphql-middleware",buildId:"
|
|
10
|
+
<script type="module" src="/__nuxt-graphql-middleware/_nuxt/BS583yk8.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},1741337201294,false]</script>
|
|
11
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-graphql-middleware",buildId:"106a09af-649a-473b-b0c7-0e4ce5709429",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
package/dist/module.d.mts
CHANGED
|
@@ -295,6 +295,12 @@ interface ModuleOptions {
|
|
|
295
295
|
* @default './schema.graphql'
|
|
296
296
|
*/
|
|
297
297
|
schemaPath?: string;
|
|
298
|
+
/**
|
|
299
|
+
* Logs only errors.
|
|
300
|
+
*
|
|
301
|
+
* When enabled only errors are logged to the console.
|
|
302
|
+
*/
|
|
303
|
+
logOnlyErrors?: boolean;
|
|
298
304
|
/**
|
|
299
305
|
* Options for graphql-typescript-deluxe code generator.
|
|
300
306
|
*/
|
package/dist/module.d.ts
CHANGED
|
@@ -295,6 +295,12 @@ interface ModuleOptions {
|
|
|
295
295
|
* @default './schema.graphql'
|
|
296
296
|
*/
|
|
297
297
|
schemaPath?: string;
|
|
298
|
+
/**
|
|
299
|
+
* Logs only errors.
|
|
300
|
+
*
|
|
301
|
+
* When enabled only errors are logged to the console.
|
|
302
|
+
*/
|
|
303
|
+
logOnlyErrors?: boolean;
|
|
298
304
|
/**
|
|
299
305
|
* Options for graphql-typescript-deluxe code generator.
|
|
300
306
|
*/
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -6,18 +6,19 @@ import { useLogger, resolveFiles, defineNuxtModule, resolveAlias, createResolver
|
|
|
6
6
|
import { onDevToolsInitialized, extendServerRpc } from '@nuxt/devtools-kit';
|
|
7
7
|
import { existsSync } from 'fs';
|
|
8
8
|
import { GraphqlMiddlewareTemplate } from '../dist/runtime/settings/index.js';
|
|
9
|
-
import
|
|
9
|
+
import fs from 'node:fs/promises';
|
|
10
|
+
import { existsSync as existsSync$1, promises } from 'node:fs';
|
|
10
11
|
import { generate } from '@graphql-codegen/cli';
|
|
11
12
|
import * as PluginSchemaAst from '@graphql-codegen/schema-ast';
|
|
12
13
|
import { basename } from 'node:path';
|
|
13
|
-
import {
|
|
14
|
-
import { Generator } from 'graphql-typescript-deluxe';
|
|
14
|
+
import { printSourceLocation, parse, Source } from 'graphql';
|
|
15
|
+
import { Generator, FieldNotFoundError, TypeNotFoundError, FragmentNotFoundError } from 'graphql-typescript-deluxe';
|
|
15
16
|
import { pascalCase } from 'change-case-all';
|
|
16
17
|
import colors from 'picocolors';
|
|
17
18
|
import { validateGraphQlDocuments } from '@graphql-tools/utils';
|
|
18
19
|
|
|
19
20
|
const name = "nuxt-graphql-middleware";
|
|
20
|
-
const version = "5.0.0-alpha.
|
|
21
|
+
const version = "5.0.0-alpha.4";
|
|
21
22
|
|
|
22
23
|
const DEVTOOLS_UI_ROUTE = "/__nuxt-graphql-middleware";
|
|
23
24
|
const DEVTOOLS_UI_LOCAL_PORT = 3300;
|
|
@@ -107,14 +108,14 @@ function validateOptions(options) {
|
|
|
107
108
|
async function getSchemaPath(schemaPath, options, resolver, writeToDisk = false) {
|
|
108
109
|
const dest = resolver(schemaPath);
|
|
109
110
|
if (!options.downloadSchema) {
|
|
110
|
-
const fileExists2 = await
|
|
111
|
+
const fileExists2 = await fs.access(dest).then(() => true).catch(() => false);
|
|
111
112
|
if (!fileExists2) {
|
|
112
113
|
logger.error(
|
|
113
114
|
'"downloadSchema" is set to false but no schema exists at ' + dest
|
|
114
115
|
);
|
|
115
116
|
throw new Error("Missing GraphQL schema.");
|
|
116
117
|
}
|
|
117
|
-
const schemaContent = await
|
|
118
|
+
const schemaContent = await fs.readFile(dest).then((v) => v.toString());
|
|
118
119
|
return { schemaPath, schemaContent };
|
|
119
120
|
}
|
|
120
121
|
if (!options.graphqlEndpoint) {
|
|
@@ -216,20 +217,21 @@ function generateContextTemplate(collectedOperations, serverApiPrefix) {
|
|
|
216
217
|
queryResult.code,
|
|
217
218
|
mutationResult.code,
|
|
218
219
|
subscriptionResult.code
|
|
219
|
-
].join("\n");
|
|
220
|
+
].filter(Boolean).join("\n");
|
|
220
221
|
const combinedNitroCode = [
|
|
221
222
|
queryResult.nitroCode,
|
|
222
223
|
mutationResult.nitroCode,
|
|
223
224
|
subscriptionResult.nitroCode
|
|
224
225
|
].join("\n");
|
|
226
|
+
const typeImports = allImports.length ? `import type {
|
|
227
|
+
${allImports.join(",\n ")}
|
|
228
|
+
} from './../graphql-operations'` : "";
|
|
225
229
|
return `
|
|
226
230
|
import type { GraphqlResponse } from '#graphql-middleware-server-options-build'
|
|
227
|
-
|
|
228
|
-
${allImports.join(",\n ")}
|
|
229
|
-
} from './../graphql-operations'
|
|
231
|
+
${typeImports}
|
|
230
232
|
|
|
231
233
|
declare module '#nuxt-graphql-middleware/generated-types' {
|
|
232
|
-
export type GraphqlMiddlewareResponseUnion = ${allResultTypes.join(" | ")}
|
|
234
|
+
export type GraphqlMiddlewareResponseUnion = ${allResultTypes.join(" | ") || "never"}
|
|
233
235
|
${combinedCode}
|
|
234
236
|
}
|
|
235
237
|
|
|
@@ -241,6 +243,8 @@ ${combinedNitroCode}
|
|
|
241
243
|
`;
|
|
242
244
|
}
|
|
243
245
|
|
|
246
|
+
const SYMBOL_CROSS = "x";
|
|
247
|
+
const SYMBOL_CHECK = "\u2714";
|
|
244
248
|
function getMaxLengths(entries) {
|
|
245
249
|
let name = 0;
|
|
246
250
|
let path = 0;
|
|
@@ -263,7 +267,7 @@ function logAllEntries(entries) {
|
|
|
263
267
|
let prevHadError = false;
|
|
264
268
|
for (const entry of entries) {
|
|
265
269
|
const hasErrors = entry.errors.length > 0;
|
|
266
|
-
const icon = hasErrors ? colors.red(
|
|
270
|
+
const icon = hasErrors ? colors.red(SYMBOL_CROSS) : colors.green(SYMBOL_CHECK);
|
|
267
271
|
const type = entry.type.padEnd(lengths.type);
|
|
268
272
|
const namePadded = colors.bold(entry.name.padEnd(lengths.name));
|
|
269
273
|
const name = hasErrors ? colors.red(namePadded) : colors.green(namePadded);
|
|
@@ -293,6 +297,7 @@ function logAllEntries(entries) {
|
|
|
293
297
|
}
|
|
294
298
|
logger.restoreStd();
|
|
295
299
|
}
|
|
300
|
+
|
|
296
301
|
class CollectedFile {
|
|
297
302
|
filePath;
|
|
298
303
|
fileContents;
|
|
@@ -324,12 +329,22 @@ class CollectedFile {
|
|
|
324
329
|
return false;
|
|
325
330
|
}
|
|
326
331
|
}
|
|
332
|
+
|
|
327
333
|
class Collector {
|
|
328
|
-
constructor(schema, context, nuxtConfigDocuments = [], generatorOptions) {
|
|
334
|
+
constructor(schema, context, nuxtConfigDocuments = [], generatorOptions = {}) {
|
|
329
335
|
this.schema = schema;
|
|
330
336
|
this.context = context;
|
|
331
337
|
this.nuxtConfigDocuments = nuxtConfigDocuments;
|
|
332
|
-
|
|
338
|
+
const mappedOptions = { ...generatorOptions };
|
|
339
|
+
if (!mappedOptions.output) {
|
|
340
|
+
mappedOptions.output = {};
|
|
341
|
+
}
|
|
342
|
+
if (!mappedOptions.output.buildTypeDocFilePath) {
|
|
343
|
+
mappedOptions.output.buildTypeDocFilePath = (filePath) => {
|
|
344
|
+
return this.filePathToBuildRelative(filePath);
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
this.generator = new Generator(schema, mappedOptions);
|
|
333
348
|
}
|
|
334
349
|
/**
|
|
335
350
|
* All collected files.
|
|
@@ -351,6 +366,10 @@ class Collector {
|
|
|
351
366
|
* The generated TypeScript type template output.
|
|
352
367
|
*/
|
|
353
368
|
outputTypes = "";
|
|
369
|
+
/**
|
|
370
|
+
* The generated TypeScript enum template output.
|
|
371
|
+
*/
|
|
372
|
+
outputEnums = "";
|
|
354
373
|
/**
|
|
355
374
|
* The generated oeprations file.
|
|
356
375
|
*/
|
|
@@ -359,21 +378,31 @@ class Collector {
|
|
|
359
378
|
* The generated context template file.
|
|
360
379
|
*/
|
|
361
380
|
outputContext = "";
|
|
362
|
-
|
|
363
|
-
* Whether we need to rebuild the Generator state.
|
|
364
|
-
*/
|
|
365
|
-
needsRebuild = false;
|
|
366
|
-
filePathToRelative(filePath) {
|
|
381
|
+
filePathToBuildRelative(filePath) {
|
|
367
382
|
return "./" + relative(this.context.buildDir, filePath);
|
|
368
383
|
}
|
|
384
|
+
filePathToSourceRelative(filePath) {
|
|
385
|
+
return "./" + relative(process.cwd(), filePath);
|
|
386
|
+
}
|
|
369
387
|
operationToLogEntry(operation, errors) {
|
|
370
388
|
return {
|
|
371
389
|
name: operation.graphqlName,
|
|
372
390
|
type: operation.operationType,
|
|
373
|
-
path: operation.filePath,
|
|
391
|
+
path: this.filePathToSourceRelative(operation.filePath),
|
|
374
392
|
errors
|
|
375
393
|
};
|
|
376
394
|
}
|
|
395
|
+
buildOutputTypes(file) {
|
|
396
|
+
let output = "";
|
|
397
|
+
const enumImports = file.getTypeScriptEnumDependencies();
|
|
398
|
+
if (enumImports.length) {
|
|
399
|
+
output += `import type { ${enumImports.join(", ")} } from './enums'
|
|
400
|
+
|
|
401
|
+
`;
|
|
402
|
+
}
|
|
403
|
+
output += file.getSource();
|
|
404
|
+
return output;
|
|
405
|
+
}
|
|
377
406
|
/**
|
|
378
407
|
* Executes code gen and performs validation for operations.
|
|
379
408
|
*/
|
|
@@ -381,8 +410,9 @@ class Collector {
|
|
|
381
410
|
const output = this.generator.build();
|
|
382
411
|
const operations = output.getCollectedOperations();
|
|
383
412
|
const generatedCode = output.getGeneratedCode();
|
|
384
|
-
this.outputOperations = output.getOperationsFile();
|
|
385
|
-
this.
|
|
413
|
+
this.outputOperations = output.getOperationsFile().getSource();
|
|
414
|
+
this.outputEnums = output.buildFile(["enum"]).getSource();
|
|
415
|
+
this.outputTypes = this.buildOutputTypes(output.getTypes());
|
|
386
416
|
this.outputContext = generateContextTemplate(
|
|
387
417
|
operations,
|
|
388
418
|
this.context.serverApiPrefix
|
|
@@ -415,7 +445,10 @@ class Collector {
|
|
|
415
445
|
} else {
|
|
416
446
|
this.operationTimestamps.set(operation.graphqlName, operation.timestamp);
|
|
417
447
|
}
|
|
418
|
-
|
|
448
|
+
const shouldLog = errors.length || !this.context.logOnlyErrors;
|
|
449
|
+
if (shouldLog) {
|
|
450
|
+
logEntries.push(this.operationToLogEntry(operation, errors));
|
|
451
|
+
}
|
|
419
452
|
}
|
|
420
453
|
logAllEntries(logEntries);
|
|
421
454
|
if (hasErrors) {
|
|
@@ -439,6 +472,29 @@ class Collector {
|
|
|
439
472
|
}
|
|
440
473
|
}
|
|
441
474
|
}
|
|
475
|
+
buildErrorMessage(error) {
|
|
476
|
+
let output = "";
|
|
477
|
+
if (error instanceof FieldNotFoundError || error instanceof TypeNotFoundError || error instanceof FragmentNotFoundError) {
|
|
478
|
+
const filePath = error.context?.filePath;
|
|
479
|
+
const file = filePath ? this.files.get(filePath) : null;
|
|
480
|
+
if (filePath) {
|
|
481
|
+
output += ` | ${this.filePathToSourceRelative(filePath)}
|
|
482
|
+
`;
|
|
483
|
+
}
|
|
484
|
+
output += "\n" + error.message + "\n\n";
|
|
485
|
+
if (file) {
|
|
486
|
+
output += file.fileContents;
|
|
487
|
+
}
|
|
488
|
+
} else if (error instanceof Error) {
|
|
489
|
+
output += "\n" + error.message;
|
|
490
|
+
}
|
|
491
|
+
return output;
|
|
492
|
+
}
|
|
493
|
+
logError(error) {
|
|
494
|
+
let output = `${SYMBOL_CROSS}`;
|
|
495
|
+
output += this.buildErrorMessage(error);
|
|
496
|
+
logger.error(colors.red(output));
|
|
497
|
+
}
|
|
442
498
|
/**
|
|
443
499
|
* Get all file paths that match the import patterns.
|
|
444
500
|
*/
|
|
@@ -454,21 +510,27 @@ class Collector {
|
|
|
454
510
|
* Initialise the collector.
|
|
455
511
|
*/
|
|
456
512
|
async init() {
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
const
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
513
|
+
try {
|
|
514
|
+
const files = await this.getImportPatternFiles();
|
|
515
|
+
for (const filePath of files) {
|
|
516
|
+
await this.addFile(filePath);
|
|
517
|
+
}
|
|
518
|
+
const nuxtConfigDocuments = this.nuxtConfigDocuments.join("\n\n");
|
|
519
|
+
if (nuxtConfigDocuments.length) {
|
|
520
|
+
const filePath = this.context.nuxtConfigPath;
|
|
521
|
+
const file = new CollectedFile(filePath, nuxtConfigDocuments, false);
|
|
522
|
+
this.files.set(filePath, file);
|
|
523
|
+
this.generator.add({
|
|
524
|
+
filePath,
|
|
525
|
+
documentNode: file.parsed
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
this.buildState();
|
|
529
|
+
logger.success("All GraphQL documents are valid.");
|
|
530
|
+
} catch (e) {
|
|
531
|
+
this.logError(e);
|
|
532
|
+
throw new Error("GraphQL document validation failed.");
|
|
533
|
+
}
|
|
472
534
|
}
|
|
473
535
|
/**
|
|
474
536
|
* Add a file.
|
|
@@ -477,12 +539,16 @@ class Collector {
|
|
|
477
539
|
const file = await CollectedFile.fromFilePath(filePath);
|
|
478
540
|
this.files.set(filePath, file);
|
|
479
541
|
this.generator.add({
|
|
480
|
-
filePath
|
|
542
|
+
filePath,
|
|
481
543
|
documentNode: file.parsed
|
|
482
544
|
});
|
|
483
545
|
return file;
|
|
484
546
|
}
|
|
485
547
|
async handleAdd(filePath) {
|
|
548
|
+
const matching = await this.getImportPatternFiles();
|
|
549
|
+
if (!matching.includes(filePath)) {
|
|
550
|
+
return false;
|
|
551
|
+
}
|
|
486
552
|
await this.addFile(filePath);
|
|
487
553
|
return true;
|
|
488
554
|
}
|
|
@@ -496,7 +562,7 @@ class Collector {
|
|
|
496
562
|
return false;
|
|
497
563
|
}
|
|
498
564
|
this.generator.update({
|
|
499
|
-
filePath
|
|
565
|
+
filePath,
|
|
500
566
|
documentNode: file.parsed
|
|
501
567
|
});
|
|
502
568
|
return true;
|
|
@@ -507,7 +573,7 @@ class Collector {
|
|
|
507
573
|
return false;
|
|
508
574
|
}
|
|
509
575
|
this.files.delete(filePath);
|
|
510
|
-
this.generator.remove(
|
|
576
|
+
this.generator.remove(filePath);
|
|
511
577
|
return true;
|
|
512
578
|
}
|
|
513
579
|
handleUnlinkDir(folderPath) {
|
|
@@ -544,13 +610,16 @@ class Collector {
|
|
|
544
610
|
} catch (e) {
|
|
545
611
|
this.generator.resetCaches();
|
|
546
612
|
logger.error("Failed to update GraphQL code.");
|
|
547
|
-
|
|
548
|
-
return
|
|
613
|
+
this.logError(e);
|
|
614
|
+
return {
|
|
615
|
+
hasChanged: false,
|
|
616
|
+
error: { message: this.buildErrorMessage(e) }
|
|
617
|
+
};
|
|
549
618
|
}
|
|
550
619
|
if (hasChanged) {
|
|
551
|
-
logger.success("Finished GraphQL code update.");
|
|
620
|
+
logger.success("Finished GraphQL code update successfully.");
|
|
552
621
|
}
|
|
553
|
-
return hasChanged;
|
|
622
|
+
return { hasChanged };
|
|
554
623
|
}
|
|
555
624
|
/**
|
|
556
625
|
* Get the TypeScript types template contents.
|
|
@@ -558,6 +627,12 @@ class Collector {
|
|
|
558
627
|
getTemplateTypes() {
|
|
559
628
|
return this.outputTypes;
|
|
560
629
|
}
|
|
630
|
+
/**
|
|
631
|
+
* Get the TypeScript Enums template contents.
|
|
632
|
+
*/
|
|
633
|
+
getTemplateEnums() {
|
|
634
|
+
return this.outputEnums;
|
|
635
|
+
}
|
|
561
636
|
/**
|
|
562
637
|
* Get the context template contents.
|
|
563
638
|
*/
|
|
@@ -572,6 +647,13 @@ class Collector {
|
|
|
572
647
|
}
|
|
573
648
|
}
|
|
574
649
|
|
|
650
|
+
function useViteWebSocket(nuxt) {
|
|
651
|
+
return new Promise((resolve) => {
|
|
652
|
+
nuxt.hooks.hook("vite:serverCreated", (viteServer) => {
|
|
653
|
+
resolve(viteServer.ws);
|
|
654
|
+
});
|
|
655
|
+
});
|
|
656
|
+
}
|
|
575
657
|
const RPC_NAMESPACE = "nuxt-graphql-middleware";
|
|
576
658
|
const module = defineNuxtModule({
|
|
577
659
|
meta: {
|
|
@@ -585,7 +667,8 @@ const module = defineNuxtModule({
|
|
|
585
667
|
defaults: defaultOptions,
|
|
586
668
|
async setup(passedOptions, nuxt) {
|
|
587
669
|
const options = defu({}, passedOptions, defaultOptions);
|
|
588
|
-
function addAlias(name2,
|
|
670
|
+
function addAlias(name2, arg) {
|
|
671
|
+
const aliasPath = typeof arg === "string" ? arg : arg.dst;
|
|
589
672
|
nuxt.options.alias[name2] = aliasPath;
|
|
590
673
|
}
|
|
591
674
|
const isModuleBuild = process.env.MODULE_BUILD === "true" && nuxt.options._prepare;
|
|
@@ -626,16 +709,17 @@ const module = defineNuxtModule({
|
|
|
626
709
|
});
|
|
627
710
|
const runtimeDir = fileURLToPath(new URL("./runtime", import.meta.url));
|
|
628
711
|
nuxt.options.build.transpile.push(runtimeDir);
|
|
629
|
-
const context = {
|
|
630
|
-
patterns: options.autoImportPatterns || [],
|
|
631
|
-
srcDir: nuxt.options.srcDir,
|
|
632
|
-
buildDir: srcResolver.resolve(nuxt.options.buildDir),
|
|
633
|
-
schemaPath,
|
|
634
|
-
serverApiPrefix: options.serverApiPrefix
|
|
635
|
-
};
|
|
636
712
|
const collector = new Collector(
|
|
637
713
|
schema,
|
|
638
|
-
|
|
714
|
+
{
|
|
715
|
+
patterns: options.autoImportPatterns || [],
|
|
716
|
+
srcDir: nuxt.options.srcDir,
|
|
717
|
+
buildDir: srcResolver.resolve(nuxt.options.buildDir),
|
|
718
|
+
nuxtConfigPath: rootResolver.resolve("nuxt.config.ts"),
|
|
719
|
+
schemaPath,
|
|
720
|
+
serverApiPrefix: options.serverApiPrefix,
|
|
721
|
+
logOnlyErrors: !!options.logOnlyErrors
|
|
722
|
+
},
|
|
639
723
|
options.documents,
|
|
640
724
|
options.codegenConfig
|
|
641
725
|
);
|
|
@@ -693,12 +777,22 @@ const module = defineNuxtModule({
|
|
|
693
777
|
);
|
|
694
778
|
addServerImports(serverUtils);
|
|
695
779
|
}
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
780
|
+
addAlias(
|
|
781
|
+
"#graphql-operations",
|
|
782
|
+
addTemplate({
|
|
783
|
+
filename: GraphqlMiddlewareTemplate.OperationTypes,
|
|
784
|
+
write: true,
|
|
785
|
+
getContents: () => collector.getTemplateTypes()
|
|
786
|
+
})
|
|
787
|
+
);
|
|
788
|
+
addAlias(
|
|
789
|
+
"#graphql-operations/enums",
|
|
790
|
+
addTemplate({
|
|
791
|
+
filename: GraphqlMiddlewareTemplate.Enums,
|
|
792
|
+
write: true,
|
|
793
|
+
getContents: () => collector.getTemplateEnums()
|
|
794
|
+
})
|
|
795
|
+
);
|
|
702
796
|
const templateDocuments = addTemplate({
|
|
703
797
|
filename: GraphqlMiddlewareTemplate.Documents,
|
|
704
798
|
write: true,
|
|
@@ -755,12 +849,12 @@ declare module '#graphql-documents' {
|
|
|
755
849
|
}
|
|
756
850
|
logger.info("No graphqlMiddleware.serverOptions file found.");
|
|
757
851
|
};
|
|
758
|
-
const
|
|
852
|
+
const resolvedServerOptionsPath = findServerOptions();
|
|
759
853
|
const moduleTypesPath = relative(
|
|
760
854
|
nuxt.options.buildDir,
|
|
761
855
|
moduleResolver.resolve("./types")
|
|
762
856
|
);
|
|
763
|
-
const resolvedPathRelative =
|
|
857
|
+
const resolvedPathRelative = resolvedServerOptionsPath ? relative(nuxt.options.buildDir, resolvedServerOptionsPath) : null;
|
|
764
858
|
const template = addTemplate({
|
|
765
859
|
filename: "graphqlMiddleware.serverOptions.mjs",
|
|
766
860
|
write: true,
|
|
@@ -870,10 +964,22 @@ export type GraphqlClientContext = {}
|
|
|
870
964
|
);
|
|
871
965
|
});
|
|
872
966
|
if (nuxt.options.dev || nuxt.options._prepare) {
|
|
967
|
+
let sendError = function(error) {
|
|
968
|
+
wsPromise.then((ws) => {
|
|
969
|
+
ws.send({
|
|
970
|
+
type: "error",
|
|
971
|
+
err: {
|
|
972
|
+
message: error.message,
|
|
973
|
+
stack: ""
|
|
974
|
+
}
|
|
975
|
+
});
|
|
976
|
+
});
|
|
977
|
+
};
|
|
873
978
|
addServerHandler({
|
|
874
979
|
handler: moduleResolver.resolve("./runtime/serverHandler/debug"),
|
|
875
980
|
route: options.serverApiPrefix + "/debug"
|
|
876
981
|
});
|
|
982
|
+
const wsPromise = useViteWebSocket(nuxt);
|
|
877
983
|
nuxt.hook("builder:watch", async (event, pathAbsolute) => {
|
|
878
984
|
if (pathAbsolute === schemaPath) {
|
|
879
985
|
return;
|
|
@@ -881,7 +987,13 @@ export type GraphqlClientContext = {}
|
|
|
881
987
|
if (!pathAbsolute.match(/\.(gql|graphql)$/)) {
|
|
882
988
|
return;
|
|
883
989
|
}
|
|
884
|
-
const hasChanged = await collector.handleWatchEvent(
|
|
990
|
+
const { hasChanged, error } = await collector.handleWatchEvent(
|
|
991
|
+
event,
|
|
992
|
+
pathAbsolute
|
|
993
|
+
);
|
|
994
|
+
if (error) {
|
|
995
|
+
sendError(error);
|
|
996
|
+
}
|
|
885
997
|
if (hasChanged && rpc) {
|
|
886
998
|
rpc.broadcast.documentsUpdated([...collector.rpcItems.values()]);
|
|
887
999
|
}
|
|
@@ -3,6 +3,22 @@ import { getEndpoint } from "./../helpers/composables.js";
|
|
|
3
3
|
import { hash } from "ohash";
|
|
4
4
|
import { GraphqlMiddlewareCache } from "../helpers/ClientCache.js";
|
|
5
5
|
import { useNuxtApp, useAppConfig } from "#imports";
|
|
6
|
+
function logGraphQLErrors(operation, operationName, errors) {
|
|
7
|
+
errors.forEach((error) => {
|
|
8
|
+
console.group(
|
|
9
|
+
`Error in GraphQL response for ${operation} "${operationName}"`
|
|
10
|
+
);
|
|
11
|
+
console.error(`Message: ${error.message}`);
|
|
12
|
+
if (error.locations && error.locations.length > 0) {
|
|
13
|
+
const formattedLocations = error.locations.map((loc) => `line ${loc.line}, column ${loc.column}`).join(" | ");
|
|
14
|
+
console.error(`Locations: ${formattedLocations}`);
|
|
15
|
+
}
|
|
16
|
+
if (error.path) {
|
|
17
|
+
console.error(`Path: ${error.path.join(" -> ")}`);
|
|
18
|
+
}
|
|
19
|
+
console.groupEnd();
|
|
20
|
+
});
|
|
21
|
+
}
|
|
6
22
|
export function performRequest(operation, operationName, method, options, cacheOptions) {
|
|
7
23
|
const state = useGraphqlState();
|
|
8
24
|
const app = useNuxtApp();
|
|
@@ -34,6 +50,9 @@ export function performRequest(operation, operationName, method, options, cacheO
|
|
|
34
50
|
method
|
|
35
51
|
}
|
|
36
52
|
).then((v) => {
|
|
53
|
+
if (import.meta.dev && v.errors?.length) {
|
|
54
|
+
logGraphQLErrors(operation, operationName, v.errors);
|
|
55
|
+
}
|
|
37
56
|
return {
|
|
38
57
|
...v,
|
|
39
58
|
data: v.data,
|
|
@@ -2,7 +2,11 @@ export declare enum GraphqlMiddlewareTemplate {
|
|
|
2
2
|
/**
|
|
3
3
|
* Contains the TS definitions for all GraphQL queries, mutations and fragments.
|
|
4
4
|
*/
|
|
5
|
-
OperationTypes = "graphql-operations.ts",
|
|
5
|
+
OperationTypes = "graphql-operations/index.d.ts",
|
|
6
|
+
/**
|
|
7
|
+
* Contains the TS definitions for all GraphQL queries, mutations and fragments.
|
|
8
|
+
*/
|
|
9
|
+
Enums = "graphql-operations/enums.ts",
|
|
6
10
|
/**
|
|
7
11
|
* Signature for the GraphQL composable arguments and return types.
|
|
8
12
|
*/
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export var GraphqlMiddlewareTemplate = /* @__PURE__ */ ((GraphqlMiddlewareTemplate2) => {
|
|
2
|
-
GraphqlMiddlewareTemplate2["OperationTypes"] = "graphql-operations.ts";
|
|
2
|
+
GraphqlMiddlewareTemplate2["OperationTypes"] = "graphql-operations/index.d.ts";
|
|
3
|
+
GraphqlMiddlewareTemplate2["Enums"] = "graphql-operations/enums.ts";
|
|
3
4
|
GraphqlMiddlewareTemplate2["ComposableContext"] = "nuxt-graphql-middleware/generated-types.d.ts";
|
|
4
5
|
GraphqlMiddlewareTemplate2["Documents"] = "nuxt-graphql-middleware/graphql-documents.mjs";
|
|
5
6
|
return GraphqlMiddlewareTemplate2;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-graphql-middleware",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.4",
|
|
4
4
|
"description": "Module to perform GraphQL requests as a server middleware.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -64,13 +64,9 @@
|
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"@graphql-codegen/cli": "^5.0.5",
|
|
66
66
|
"@graphql-codegen/schema-ast": "^4.1.0",
|
|
67
|
-
"@graphql-codegen/typescript": "^4.1.3",
|
|
68
|
-
"@graphql-codegen/typescript-generic-sdk": "^4.0.1",
|
|
69
|
-
"@graphql-codegen/typescript-operations": "^4.4.1",
|
|
70
67
|
"@graphql-tools/utils": "^10.2.2",
|
|
71
68
|
"@nuxt/devtools-kit": "1.3.7",
|
|
72
|
-
"
|
|
73
|
-
"graphql-typescript-deluxe": "^0.0.2",
|
|
69
|
+
"graphql-typescript-deluxe": "^0.0.5",
|
|
74
70
|
"inquirer": "^9.3.2",
|
|
75
71
|
"minisearch": "^6.3.0",
|
|
76
72
|
"picocolors": "^1.0.1"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"id":"f823ebfd-daab-468f-8f6f-07a236da64bd","timestamp":1741248339330,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|