nuxt-graphql-middleware 5.0.0-alpha.18 → 5.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.
@@ -7,5 +7,5 @@
7
7
  <link rel="prefetch" as="script" crossorigin href="/__nuxt-graphql-middleware/_nuxt/FTbv7CO6.js">
8
8
  <link rel="prefetch" as="style" crossorigin href="/__nuxt-graphql-middleware/_nuxt/error-500._g0akJim.css">
9
9
  <link rel="prefetch" as="script" crossorigin href="/__nuxt-graphql-middleware/_nuxt/CROlboVl.js">
10
- <script type="module" src="/__nuxt-graphql-middleware/_nuxt/D5hBL5aZ.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},1744782267600,false]</script>
11
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-graphql-middleware",buildId:"f9591c09-e7d8-4bd8-85b5-0987cee82c28",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
10
+ <script type="module" src="/__nuxt-graphql-middleware/_nuxt/D5hBL5aZ.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},1745300017261,false]</script>
11
+ <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-graphql-middleware",buildId:"e592222a-65b2-4446-9ba8-397a070ce25c",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
@@ -7,5 +7,5 @@
7
7
  <link rel="prefetch" as="script" crossorigin href="/__nuxt-graphql-middleware/_nuxt/FTbv7CO6.js">
8
8
  <link rel="prefetch" as="style" crossorigin href="/__nuxt-graphql-middleware/_nuxt/error-500._g0akJim.css">
9
9
  <link rel="prefetch" as="script" crossorigin href="/__nuxt-graphql-middleware/_nuxt/CROlboVl.js">
10
- <script type="module" src="/__nuxt-graphql-middleware/_nuxt/D5hBL5aZ.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},1744782267600,false]</script>
11
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-graphql-middleware",buildId:"f9591c09-e7d8-4bd8-85b5-0987cee82c28",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
10
+ <script type="module" src="/__nuxt-graphql-middleware/_nuxt/D5hBL5aZ.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},1745300017261,false]</script>
11
+ <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-graphql-middleware",buildId:"e592222a-65b2-4446-9ba8-397a070ce25c",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
@@ -1 +1 @@
1
- {"id":"f9591c09-e7d8-4bd8-85b5-0987cee82c28","timestamp":1744782265444}
1
+ {"id":"e592222a-65b2-4446-9ba8-397a070ce25c","timestamp":1745300015053}
@@ -0,0 +1 @@
1
+ {"id":"e592222a-65b2-4446-9ba8-397a070ce25c","timestamp":1745300015053,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
@@ -7,5 +7,5 @@
7
7
  <link rel="prefetch" as="script" crossorigin href="/__nuxt-graphql-middleware/_nuxt/FTbv7CO6.js">
8
8
  <link rel="prefetch" as="style" crossorigin href="/__nuxt-graphql-middleware/_nuxt/error-500._g0akJim.css">
9
9
  <link rel="prefetch" as="script" crossorigin href="/__nuxt-graphql-middleware/_nuxt/CROlboVl.js">
10
- <script type="module" src="/__nuxt-graphql-middleware/_nuxt/D5hBL5aZ.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},1744782267601,false]</script>
11
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-graphql-middleware",buildId:"f9591c09-e7d8-4bd8-85b5-0987cee82c28",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
10
+ <script type="module" src="/__nuxt-graphql-middleware/_nuxt/D5hBL5aZ.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},1745300017261,false]</script>
11
+ <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-graphql-middleware",buildId:"e592222a-65b2-4446-9ba8-397a070ce25c",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
package/dist/module.d.mts CHANGED
@@ -1,13 +1,17 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
- import { M as ModuleContext, a as ModuleOptions } from './shared/nuxt-graphql-middleware.DLNGE1zJ.mjs';
2
+ import { M as ModuleContext, a as ModuleOptions } from './shared/nuxt-graphql-middleware.CvAk-Nll.mjs';
3
3
  import { OperationResponseError } from '../dist/runtime/types.js';
4
4
  import { HookResult } from 'nuxt/schema';
5
+ import { GeneratorOutput } from 'graphql-typescript-deluxe';
5
6
  import 'graphql';
6
7
  import '@nuxt/kit';
7
8
  import 'h3';
8
9
  import '@graphql-codegen/plugin-helpers';
9
10
  import '@graphql-codegen/schema-ast';
10
- import 'graphql-typescript-deluxe';
11
+
12
+ type BuildHookContext = {
13
+ output: GeneratorOutput;
14
+ };
11
15
 
12
16
  declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
13
17
 
@@ -72,6 +76,16 @@ declare module '@nuxt/schema' {
72
76
  * ```
73
77
  */
74
78
  'nuxt-graphql-middleware:init': (ctx: ModuleContext) => void | Promise<void>;
79
+ /**
80
+ * Called when building the state and templates.
81
+ *
82
+ * Generally this hook is called from within the builder:watch event, when
83
+ * a GraphQL file change was detected.
84
+ *
85
+ * The received argument is the output from the graphql-typescript-deluxe
86
+ * generator.
87
+ */
88
+ 'nuxt-graphql-middleware:build': (ctx: BuildHookContext) => void | Promise<void>;
75
89
  }
76
90
  }
77
91
 
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-graphql-middleware",
3
3
  "configKey": "graphqlMiddleware",
4
- "version": "5.0.0-alpha.18",
4
+ "version": "5.0.0-alpha.19",
5
5
  "compatibility": {
6
6
  "nuxt": ">=3.15.0"
7
7
  },
package/dist/module.mjs CHANGED
@@ -2,7 +2,7 @@ import { fileURLToPath } from 'url';
2
2
  import { useLogger, addTemplate, addServerTemplate, addTypeTemplate, createResolver, resolveAlias, resolveFiles, addPlugin, addServerHandler, addImports, addServerImports, useNitro, defineNuxtModule } from '@nuxt/kit';
3
3
  import { existsSync, promises } from 'node:fs';
4
4
  import { basename } from 'node:path';
5
- import { relative } from 'pathe';
5
+ import { relative, join } from 'pathe';
6
6
  import { printSourceLocation, parse, Source, OperationTypeNode } from 'graphql';
7
7
  import { Generator, FieldNotFoundError, TypeNotFoundError, FragmentNotFoundError } from 'graphql-typescript-deluxe';
8
8
  import color from 'picocolors';
@@ -19,7 +19,7 @@ import { existsSync as existsSync$1 } from 'fs';
19
19
  import { onDevToolsInitialized, extendServerRpc } from '@nuxt/devtools-kit';
20
20
 
21
21
  const name = "nuxt-graphql-middleware";
22
- const version = "5.0.0-alpha.18";
22
+ const version = "5.0.0-alpha.19";
23
23
 
24
24
  const logger = useLogger("nuxt-graphql-middleware");
25
25
  const defaultOptions = {
@@ -220,8 +220,8 @@ class Collector {
220
220
  errors
221
221
  };
222
222
  }
223
- getTemplate(template) {
224
- const content = this.templateResult.get(template);
223
+ getTemplate(template, type) {
224
+ const content = this.templateResult.get(template + "-" + type);
225
225
  if (content === void 0) {
226
226
  throw new Error(`Missing template content: ${template}`);
227
227
  }
@@ -230,28 +230,27 @@ class Collector {
230
230
  /**
231
231
  * Executes code gen and performs validation for operations.
232
232
  */
233
- buildState() {
233
+ async buildState() {
234
234
  const output = this.generator.build();
235
235
  const operations = output.getCollectedOperations();
236
236
  const generatedCode = output.getGeneratedCode();
237
237
  this.templates.forEach((template) => {
238
+ const path = template.options.path;
238
239
  if (template.build) {
239
- const filename = template.options.path + ".js";
240
240
  this.templateResult.set(
241
- filename,
241
+ path + "-default",
242
242
  this.helper.processTemplate(
243
243
  template.options.path,
244
- template.build(output, this.helper)
244
+ template.build(output, this.helper, this)
245
245
  )
246
246
  );
247
247
  }
248
248
  if (template.buildTypes) {
249
- const filename = template.options.path + ".d.ts";
250
249
  this.templateResult.set(
251
- filename,
250
+ template.options.path + "-types",
252
251
  this.helper.processTemplate(
253
252
  template.options.path,
254
- template.buildTypes(output, this.helper)
253
+ template.buildTypes(output, this.helper, this)
255
254
  )
256
255
  );
257
256
  }
@@ -297,6 +296,7 @@ class Collector {
297
296
  if (hasErrors) {
298
297
  throw new Error("GraphQL errors");
299
298
  }
299
+ await this.helper.nuxt.callHook("nuxt-graphql-middleware:build", { output });
300
300
  if (this.helper.isDev) {
301
301
  for (const code of generatedCode) {
302
302
  const id = `${code.identifier}_${code.graphqlName}`;
@@ -402,7 +402,7 @@ class Collector {
402
402
  for (const filePath of this.hookFiles) {
403
403
  await this.addFile(filePath);
404
404
  }
405
- this.buildState();
405
+ await this.buildState();
406
406
  logger.success("All GraphQL documents are valid.");
407
407
  } catch (e) {
408
408
  this.logError(e);
@@ -494,7 +494,7 @@ class Collector {
494
494
  hasChanged = this.handleUnlinkDir(filePath);
495
495
  }
496
496
  if (hasChanged) {
497
- this.buildState();
497
+ await this.buildState();
498
498
  }
499
499
  } catch (e) {
500
500
  this.generator.resetCaches();
@@ -526,7 +526,7 @@ class Collector {
526
526
  */
527
527
  addVirtualTemplate(template) {
528
528
  const filename = template.options.path + ".js";
529
- const getContents = () => this.getTemplate(filename);
529
+ const getContents = () => this.getTemplate(template.options.path, "default");
530
530
  addTemplate({
531
531
  filename,
532
532
  getContents
@@ -551,21 +551,23 @@ class Collector {
551
551
  if (template.options.virtual) {
552
552
  this.addVirtualTemplate(template);
553
553
  } else {
554
- const filename = template.options.path + ".js";
554
+ const path = template.options.path;
555
+ const filename = template.options.isFullPath ? path : path + ".js";
555
556
  addTemplate({
556
557
  filename,
557
558
  write: true,
558
- getContents: () => this.getTemplate(filename)
559
+ getContents: () => this.getTemplate(path, "default")
559
560
  });
560
561
  }
561
562
  }
562
563
  if (template.buildTypes) {
564
+ const path = template.options.path;
563
565
  const filename = template.options.path + ".d.ts";
564
566
  addTypeTemplate(
565
567
  {
566
568
  filename,
567
569
  write: true,
568
- getContents: () => this.getTemplate(filename)
570
+ getContents: () => this.getTemplate(path, "types")
569
571
  },
570
572
  {
571
573
  nuxt: true,
@@ -574,6 +576,23 @@ class Collector {
574
576
  );
575
577
  }
576
578
  }
579
+ /**
580
+ * Get the hook documents.
581
+ */
582
+ getHookDocuments() {
583
+ return [...this.hookDocuments.entries()].map(([identifier, source]) => {
584
+ return {
585
+ identifier,
586
+ source
587
+ };
588
+ });
589
+ }
590
+ /**
591
+ * Get the hook documents.
592
+ */
593
+ getHookFiles() {
594
+ return [...this.hookFiles.values()];
595
+ }
577
596
  }
578
597
 
579
598
  class SchemaProvider {
@@ -805,6 +824,8 @@ class ModuleHelper {
805
824
  return layerAliases.map((aliases) => resolveAlias(pattern, aliases));
806
825
  }
807
826
  return rootResolver.resolve(pattern);
827
+ }).map((pattern) => {
828
+ return pattern.replace(".{graphql}", ".graphql").replace(".{gql}", ".gql");
808
829
  });
809
830
  this.options = mergedOptions;
810
831
  if (!nuxt.options._prepare) {
@@ -944,7 +965,7 @@ class ModuleHelper {
944
965
  }
945
966
  }
946
967
  processTemplate(path, content) {
947
- if (path.includes("graphql-operations/")) {
968
+ if (path.includes("graphql-operations/") || path.endsWith(".graphql")) {
948
969
  return content.trim();
949
970
  }
950
971
  const name = path.split("/")[1];
@@ -1093,13 +1114,25 @@ const GraphqlConfig = defineStaticTemplate(
1093
1114
  const documents = patterns.filter((v) => !v.includes("!")).map((pattern) => {
1094
1115
  return "./" + relative(configPath, helper.resolvers.root.resolve(pattern));
1095
1116
  });
1096
- return `const schema = ${JSON.stringify(schemaPath)}
1117
+ documents.push(
1118
+ "./" + relative(
1119
+ configPath,
1120
+ join(helper.paths.moduleBuildDir, "hook-documents.graphql")
1121
+ )
1122
+ );
1123
+ return `
1124
+ import { hookFiles } from './hook-files'
1125
+
1126
+ const schema = ${JSON.stringify(schemaPath)}
1097
1127
 
1098
1128
  const documents = ${JSON.stringify(documents, null, 2)};
1099
1129
 
1100
1130
  const config = {
1101
1131
  schema,
1102
- documents,
1132
+ documents: [
1133
+ ...documents,
1134
+ ...hookFiles
1135
+ ]
1103
1136
  }
1104
1137
 
1105
1138
  export default config
@@ -1265,6 +1298,43 @@ export const operationSources = {
1265
1298
  }
1266
1299
  );
1267
1300
 
1301
+ const HookDocuments = defineGeneratorTemplate(
1302
+ {
1303
+ path: "nuxt-graphql-middleware/hook-documents.graphql",
1304
+ virtual: false,
1305
+ isFullPath: true
1306
+ },
1307
+ (_output, _helper, collector) => {
1308
+ return collector.getHookDocuments().map((v) => {
1309
+ return `
1310
+ # ${v.identifier}
1311
+ ${v.source}
1312
+ `;
1313
+ }).join("\n\n");
1314
+ },
1315
+ null
1316
+ );
1317
+
1318
+ const HookFiles = defineGeneratorTemplate(
1319
+ {
1320
+ path: "nuxt-graphql-middleware/hook-files",
1321
+ virtual: false
1322
+ },
1323
+ (_output, helper, collector) => {
1324
+ const configPath = helper.resolvers.root.resolve(
1325
+ (helper.options.graphqlConfigFilePath || "").replace(
1326
+ "/graphql.config.ts",
1327
+ ""
1328
+ )
1329
+ );
1330
+ const files = collector.getHookFiles().map((filePath) => {
1331
+ return "./" + relative(configPath, filePath);
1332
+ });
1333
+ return `export const hookFiles = ${JSON.stringify(files, null, 2)}`;
1334
+ },
1335
+ null
1336
+ );
1337
+
1268
1338
  const TEMPLATES = [
1269
1339
  ClientOptions,
1270
1340
  Documents,
@@ -1275,7 +1345,9 @@ const TEMPLATES = [
1275
1345
  Operations,
1276
1346
  Response,
1277
1347
  ServerOptions,
1278
- Sources
1348
+ Sources,
1349
+ HookDocuments,
1350
+ HookFiles
1279
1351
  ];
1280
1352
 
1281
1353
  const DEVTOOLS_UI_ROUTE = "/__nuxt-graphql-middleware";
@@ -197,8 +197,9 @@ declare class ConsolePrompt {
197
197
  type TemplateOptions = {
198
198
  path: string;
199
199
  virtual?: boolean;
200
+ isFullPath?: boolean;
200
201
  };
201
- type GeneratorTemplateCallback = (output: GeneratorOutput, helper: ModuleHelper) => string;
202
+ type GeneratorTemplateCallback = (output: GeneratorOutput, helper: ModuleHelper, collector: Collector) => string;
202
203
  type StaticTemplateCallback = (helper: ModuleHelper) => string;
203
204
  type GeneratorTemplate = {
204
205
  type: 'generator';
@@ -255,7 +256,7 @@ type ModuleHelperPaths = {
255
256
  moduleTypesDir: string;
256
257
  };
257
258
  declare class ModuleHelper {
258
- private nuxt;
259
+ readonly nuxt: Nuxt;
259
260
  readonly resolvers: ModuleHelperResolvers;
260
261
  readonly paths: ModuleHelperPaths;
261
262
  readonly isDev: boolean;
@@ -397,6 +398,17 @@ declare class Collector {
397
398
  * Adds a template that dependes on Collector state.
398
399
  */
399
400
  addTemplate(template: GeneratorTemplate): void;
401
+ /**
402
+ * Get the hook documents.
403
+ */
404
+ getHookDocuments(): {
405
+ identifier: string;
406
+ source: string;
407
+ }[];
408
+ /**
409
+ * Get the hook documents.
410
+ */
411
+ getHookFiles(): string[];
400
412
  }
401
413
 
402
414
  /**
package/dist/utils.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { M as ModuleContext } from './shared/nuxt-graphql-middleware.DLNGE1zJ.mjs';
1
+ import { M as ModuleContext } from './shared/nuxt-graphql-middleware.CvAk-Nll.mjs';
2
2
  import 'graphql';
3
3
  import 'nuxt/schema';
4
4
  import '@nuxt/kit';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-graphql-middleware",
3
- "version": "5.0.0-alpha.18",
3
+ "version": "5.0.0-alpha.19",
4
4
  "description": "Module to perform GraphQL requests as a server middleware.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -72,7 +72,7 @@
72
72
  "@graphql-codegen/schema-ast": "^4.1.0",
73
73
  "@graphql-tools/utils": "^10.8.6",
74
74
  "@nuxt/devtools-kit": "^2.3.1",
75
- "graphql-typescript-deluxe": "^0.0.12",
75
+ "graphql-typescript-deluxe": "^0.0.13",
76
76
  "minisearch": "^7.1.2",
77
77
  "picocolors": "^1.1.1"
78
78
  },
@@ -1 +0,0 @@
1
- {"id":"f9591c09-e7d8-4bd8-85b5-0987cee82c28","timestamp":1744782265444,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}