nuxt-graphql-middleware 4.1.0 → 4.2.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.
Files changed (33) hide show
  1. package/dist/client/200.html +9 -9
  2. package/dist/client/404.html +9 -9
  3. package/dist/client/_nuxt/{Bk31qVW4.js → BBbivCOF.js} +1 -1
  4. package/dist/client/_nuxt/BKf42UCq.js +2 -0
  5. package/dist/client/_nuxt/CaoFd9E8.js +25 -0
  6. package/dist/client/_nuxt/Ch07F_Ul.js +1 -0
  7. package/dist/client/_nuxt/DbuEOF3O.js +1 -0
  8. package/dist/client/_nuxt/builds/latest.json +1 -1
  9. package/dist/client/_nuxt/builds/meta/fff2eb15-13a3-4063-86e7-990068006f7e.json +1 -0
  10. package/dist/client/_nuxt/entry.DlumAtbg.css +1 -0
  11. package/dist/client/_nuxt/error-404.C_4C5G96.css +1 -0
  12. package/dist/client/_nuxt/error-500.CBAEdpZV.css +1 -0
  13. package/dist/client/index.html +9 -9
  14. package/dist/module.d.mts +3 -3
  15. package/dist/module.d.ts +3 -3
  16. package/dist/module.json +3 -3
  17. package/dist/module.mjs +151 -63
  18. package/dist/runtime/composables/useGraphqlState.d.ts +2 -1
  19. package/dist/runtime/plugins/provideState.d.ts +6 -1
  20. package/dist/runtime/serverHandler/helpers/index.d.ts +1 -1
  21. package/dist/runtime/serverHandler/tsconfig.json +3 -0
  22. package/dist/runtime/serverHandler/upload.js +0 -1
  23. package/dist/types.d.mts +0 -4
  24. package/dist/types.d.ts +0 -4
  25. package/package.json +12 -9
  26. package/dist/client/_nuxt/CHM3Rz8p.js +0 -1
  27. package/dist/client/_nuxt/CUKk0hSk.js +0 -24
  28. package/dist/client/_nuxt/Ca6k-hEN.js +0 -2
  29. package/dist/client/_nuxt/KmIjpfWJ.js +0 -1
  30. package/dist/client/_nuxt/builds/meta/debd7d31-13de-43c8-a23f-9d618b1b6aee.json +0 -1
  31. package/dist/client/_nuxt/entry.BMcZ91J5.css +0 -1
  32. package/dist/client/_nuxt/error-404.CjTTbIxB.css +0 -1
  33. package/dist/client/_nuxt/error-500.B4KzowuE.css +0 -1
@@ -1,11 +1,11 @@
1
1
  <!DOCTYPE html><html data-capo=""><head><meta charset="utf-8">
2
2
  <meta name="viewport" content="width=device-width, initial-scale=1">
3
- <link rel="stylesheet" href="/__nuxt-graphql-middleware/_nuxt/entry.BMcZ91J5.css">
4
- <link rel="modulepreload" as="script" crossorigin href="/__nuxt-graphql-middleware/_nuxt/CUKk0hSk.js">
5
- <link rel="prefetch" as="style" href="/__nuxt-graphql-middleware/_nuxt/error-404.CjTTbIxB.css">
6
- <link rel="prefetch" as="script" crossorigin href="/__nuxt-graphql-middleware/_nuxt/CHM3Rz8p.js">
7
- <link rel="prefetch" as="script" crossorigin href="/__nuxt-graphql-middleware/_nuxt/Bk31qVW4.js">
8
- <link rel="prefetch" as="style" href="/__nuxt-graphql-middleware/_nuxt/error-500.B4KzowuE.css">
9
- <link rel="prefetch" as="script" crossorigin href="/__nuxt-graphql-middleware/_nuxt/KmIjpfWJ.js">
10
- <script type="module" src="/__nuxt-graphql-middleware/_nuxt/CUKk0hSk.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script type="application/json" id="__NUXT_DATA__" data-ssr="false">[{"serverRendered":1},false]</script>
11
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-graphql-middleware",buildId:"debd7d31-13de-43c8-a23f-9d618b1b6aee",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
3
+ <link rel="stylesheet" href="/__nuxt-graphql-middleware/_nuxt/entry.DlumAtbg.css">
4
+ <link rel="modulepreload" as="script" crossorigin href="/__nuxt-graphql-middleware/_nuxt/CaoFd9E8.js">
5
+ <link rel="prefetch" as="style" crossorigin href="/__nuxt-graphql-middleware/_nuxt/error-404.C_4C5G96.css">
6
+ <link rel="prefetch" as="script" crossorigin href="/__nuxt-graphql-middleware/_nuxt/Ch07F_Ul.js">
7
+ <link rel="prefetch" as="script" crossorigin href="/__nuxt-graphql-middleware/_nuxt/BBbivCOF.js">
8
+ <link rel="prefetch" as="style" crossorigin href="/__nuxt-graphql-middleware/_nuxt/error-500.CBAEdpZV.css">
9
+ <link rel="prefetch" as="script" crossorigin href="/__nuxt-graphql-middleware/_nuxt/DbuEOF3O.js">
10
+ <script type="module" src="/__nuxt-graphql-middleware/_nuxt/CaoFd9E8.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},1729345409102,false]</script>
11
+ <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-graphql-middleware",buildId:"fff2eb15-13a3-4063-86e7-990068006f7e",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
package/dist/module.d.mts CHANGED
@@ -273,7 +273,7 @@ interface ModuleOptions {
273
273
  * The URL of the GraphQL server.
274
274
  *
275
275
  * For the runtime execution you can provide a method that determines the endpoint
276
- * during runtime. See the app/graphqlMiddleware.serverOptions.ts documentation
276
+ * during runtime. See the server/graphqlMiddleware.serverOptions.ts documentation
277
277
  * for more information.
278
278
  */
279
279
  graphqlEndpoint: string;
@@ -365,9 +365,9 @@ interface ModuleOptions {
365
365
  }
366
366
  interface ModuleHooks {
367
367
  }
368
- declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
368
+ declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
369
369
 
370
- declare module 'nuxt/schema' {
370
+ declare module '@nuxt/schema' {
371
371
  interface AppConfig {
372
372
  graphqlMiddleware: {
373
373
  clientCacheEnabled: boolean;
package/dist/module.d.ts CHANGED
@@ -273,7 +273,7 @@ interface ModuleOptions {
273
273
  * The URL of the GraphQL server.
274
274
  *
275
275
  * For the runtime execution you can provide a method that determines the endpoint
276
- * during runtime. See the app/graphqlMiddleware.serverOptions.ts documentation
276
+ * during runtime. See the server/graphqlMiddleware.serverOptions.ts documentation
277
277
  * for more information.
278
278
  */
279
279
  graphqlEndpoint: string;
@@ -365,9 +365,9 @@ interface ModuleOptions {
365
365
  }
366
366
  interface ModuleHooks {
367
367
  }
368
- declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
368
+ declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
369
369
 
370
- declare module 'nuxt/schema' {
370
+ declare module '@nuxt/schema' {
371
371
  interface AppConfig {
372
372
  graphqlMiddleware: {
373
373
  clientCacheEnabled: boolean;
package/dist/module.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "nuxt-graphql-middleware",
3
3
  "configKey": "graphqlMiddleware",
4
- "version": "4.1.0",
4
+ "version": "4.2.0",
5
5
  "compatibility": {
6
- "nuxt": ">=3.1.0"
6
+ "nuxt": ">=3.13.0"
7
7
  },
8
8
  "builder": {
9
- "@nuxt/module-builder": "0.8.1",
9
+ "@nuxt/module-builder": "0.8.4",
10
10
  "unbuild": "2.0.0"
11
11
  }
12
12
  }
package/dist/module.mjs CHANGED
@@ -11,8 +11,6 @@ import { promises, existsSync as existsSync$1 } from 'node:fs';
11
11
  import { oldVisit } from '@graphql-codegen/plugin-helpers';
12
12
  import { validateGraphQlDocuments } from '@graphql-tools/utils';
13
13
  import { loadSchema } from '@graphql-tools/load';
14
- import Table from 'cli-table';
15
- import chalk from 'chalk';
16
14
  import { concatAST, parse, print, visit, Kind, Source } from 'graphql';
17
15
  import { falsy } from '../dist/runtime/helpers/index.js';
18
16
  import { generate as generate$1, executeCodegen } from '@graphql-codegen/cli';
@@ -20,9 +18,10 @@ import * as PluginTypescript from '@graphql-codegen/typescript';
20
18
  import * as PluginTypescriptOperations from '@graphql-codegen/typescript-operations';
21
19
  import * as PluginSchemaAst from '@graphql-codegen/schema-ast';
22
20
  import { pascalCase } from 'change-case-all';
21
+ import colors from 'picocolors';
23
22
 
24
23
  const name = "nuxt-graphql-middleware";
25
- const version = "4.1.0";
24
+ const version = "4.2.0";
26
25
 
27
26
  const DEVTOOLS_UI_ROUTE = "/__nuxt-graphql-middleware";
28
27
  const DEVTOOLS_UI_LOCAL_PORT = 3300;
@@ -345,6 +344,48 @@ function generateTemplates(documents, schemaPath, options) {
345
344
  });
346
345
  }
347
346
 
347
+ function getMaxLengths(documents) {
348
+ let longestOperation = 0;
349
+ let longestName = 0;
350
+ let longestPath = 0;
351
+ for (const { operation, name, relativePath } of documents) {
352
+ if (operation && operation.length > longestOperation) {
353
+ longestOperation = operation.length;
354
+ }
355
+ if (name && name.length > longestName) {
356
+ longestName = name.length;
357
+ }
358
+ if (relativePath && relativePath.length > longestPath) {
359
+ longestPath = relativePath.length;
360
+ }
361
+ }
362
+ return { longestOperation, longestName, longestPath };
363
+ }
364
+ function logDocuments(logger, documents, logEverything) {
365
+ const { longestOperation, longestName, longestPath } = getMaxLengths(documents);
366
+ logger.log(colors.green("GraphQL Document Validation"));
367
+ for (const { operation, name, relativePath, isValid, errors } of documents) {
368
+ if (logEverything || !isValid) {
369
+ let log = "";
370
+ log += (operation || "").padEnd(longestOperation + 2);
371
+ log += colors.cyan((name || "").padEnd(longestName + 2));
372
+ log += colors.dim((relativePath || "").padEnd(longestPath + 2));
373
+ log += isValid ? colors.green("\u2713") : colors.red("x");
374
+ if (!isValid && errors) {
375
+ log += "\n" + errors.map((error) => colors.red(error)).join("\n");
376
+ }
377
+ logger.log(log);
378
+ }
379
+ }
380
+ process.stdout.write("\n");
381
+ logger.restoreStd();
382
+ if (documents.some((v) => !v.isValid)) {
383
+ logger.error("GraphQL document validation failed with errors.");
384
+ } else {
385
+ logger.success("GraphQL document validation completed successfully.");
386
+ }
387
+ }
388
+
348
389
  const logger = useLogger("nuxt-graphql-middleware");
349
390
  const defaultOptions = {
350
391
  codegenConfig: {
@@ -359,13 +400,12 @@ const defaultOptions = {
359
400
  }
360
401
  },
361
402
  downloadSchema: true,
362
- schemaPath: "./schema.graphql",
403
+ schemaPath: "~~/schema.graphql",
363
404
  serverApiPrefix: "/api/graphql_middleware",
364
405
  graphqlEndpoint: "",
365
406
  debug: false,
366
407
  includeComposables: true,
367
408
  documents: [],
368
- autoImportPatterns: [],
369
409
  devtools: true
370
410
  };
371
411
  function inlineFragments(source, resolver) {
@@ -383,8 +423,8 @@ function validateOptions(options) {
383
423
  throw new Error("Missing graphqlEndpoint.");
384
424
  }
385
425
  }
386
- async function getSchemaPath(options, resolver, writeToDisk = false) {
387
- const dest = resolver(options.schemaPath);
426
+ async function getSchemaPath(schemaPath, options, resolver, writeToDisk = false) {
427
+ const dest = resolver(schemaPath);
388
428
  if (!options.downloadSchema) {
389
429
  const fileExists2 = await promises.access(dest).then(() => true).catch(() => false);
390
430
  if (!fileExists2) {
@@ -405,6 +445,7 @@ async function autoImportDocuments(patterns = [], srcResolver) {
405
445
  if (!patterns.length) {
406
446
  return Promise.resolve([]);
407
447
  }
448
+ console.log({ patterns });
408
449
  const files = (await resolveFiles(srcResolver(), patterns, {
409
450
  followSymbolicLinks: false
410
451
  })).filter((path) => {
@@ -465,6 +506,9 @@ async function buildDocuments(providedDocuments = [], autoImportPatterns, resolv
465
506
  return documents2;
466
507
  }
467
508
  return documents2.map((v) => {
509
+ if (!v.content.trim()) {
510
+ return null;
511
+ }
468
512
  try {
469
513
  return {
470
514
  content: inlineFragments(v.content, resolveAlias),
@@ -478,6 +522,8 @@ async function buildDocuments(providedDocuments = [], autoImportPatterns, resolv
478
522
  }
479
523
  return null;
480
524
  }).filter(falsy);
525
+ }).then((docs) => {
526
+ return docs.filter((v) => v.content.trim());
481
527
  });
482
528
  if (!autoInlineFragments) {
483
529
  return documents;
@@ -496,23 +542,23 @@ async function buildDocuments(providedDocuments = [], autoImportPatterns, resolv
496
542
  });
497
543
  return documents;
498
544
  }
499
- function parseDocument(document, srcDir) {
500
- let name = document.filename ? document.filename.replace(srcDir, "") : "";
545
+ function parseDocument(document, rootDir) {
546
+ let name = document.filename ? document.filename.replace(rootDir, "") : "";
501
547
  if (name.charAt(0) === "/") {
502
548
  name = name.slice(1);
503
549
  }
504
550
  const source = new Source(document.content, name);
505
551
  return parse(source);
506
552
  }
507
- function validateDocuments(schema, documents, srcDir) {
553
+ function validateDocuments(schema, documents, rootDir) {
508
554
  const validated = [];
509
555
  for (let i = 0; i < documents.length; i++) {
510
556
  const document = { ...documents[i] };
511
557
  if (document.filename) {
512
- document.relativePath = document.filename.replace(srcDir + "/", "");
558
+ document.relativePath = document.filename.replace(rootDir + "/", "");
513
559
  }
514
560
  try {
515
- const node = parseDocument(document, srcDir);
561
+ const node = parseDocument(document, rootDir);
516
562
  document.content = print(node);
517
563
  document.errors = validateGraphQlDocuments(schema, [
518
564
  node
@@ -586,7 +632,7 @@ function cleanGraphqlDocument(graphqlContent, operationName) {
586
632
  ]
587
633
  };
588
634
  }
589
- async function generate(options, schemaPath, resolver, srcDir, logEverything = false) {
635
+ async function generate(options, schemaPath, resolver, rootDir, logEverything = false) {
590
636
  const schemaContent = await promises.readFile(schemaPath).then((v) => v.toString());
591
637
  const schema = await loadSchema(schemaContent, { loaders: [] });
592
638
  const documents = await buildDocuments(
@@ -595,12 +641,15 @@ async function generate(options, schemaPath, resolver, srcDir, logEverything = f
595
641
  resolver,
596
642
  !!options.autoInlineFragments
597
643
  );
598
- const validated = validateDocuments(schema, documents, srcDir);
644
+ const validated = validateDocuments(schema, documents, rootDir);
599
645
  const extracted = validated.filter(
600
646
  (v) => !v.operation
601
647
  );
602
648
  for (let i = 0; i < validated.length; i++) {
603
649
  const v = validated[i];
650
+ if (!v) {
651
+ continue;
652
+ }
604
653
  if (v.isValid) {
605
654
  try {
606
655
  const node = parse(v.content);
@@ -647,27 +696,7 @@ async function generate(options, schemaPath, resolver, srcDir, logEverything = f
647
696
  );
648
697
  const hasErrors = extracted.some((v) => !v.isValid) || validated.some((v) => !v.isValid);
649
698
  if (hasErrors || logEverything) {
650
- const table = new Table({
651
- head: ["Operation", "Name", "File", "Errors"].map((v) => chalk.white(v))
652
- });
653
- extracted.forEach((document) => {
654
- if (logEverything || !document.isValid) {
655
- table.push(
656
- [
657
- document.operation || "",
658
- document.name || "",
659
- document.relativePath || "",
660
- document.errors?.join("\n\n") || ""
661
- ].map((v) => {
662
- if (document.isValid) {
663
- return v;
664
- }
665
- return chalk.red(v);
666
- })
667
- );
668
- }
669
- });
670
- logger.log("GraphQL code generation table:\n" + table.toString());
699
+ logDocuments(logger, extracted, logEverything);
671
700
  }
672
701
  process.stdout.write("\n");
673
702
  logger.restoreStd();
@@ -684,7 +713,7 @@ async function generate(options, schemaPath, resolver, srcDir, logEverything = f
684
713
  })
685
714
  };
686
715
  }
687
- const fileExists = (path, extensions = ["js", "ts"]) => {
716
+ const fileExists = (path, extensions = ["js", "ts", "mjs"]) => {
688
717
  if (!path) {
689
718
  return null;
690
719
  } else if (existsSync$1(path)) {
@@ -713,22 +742,44 @@ const module = defineNuxtModule({
713
742
  configKey: "graphqlMiddleware",
714
743
  version,
715
744
  compatibility: {
716
- nuxt: ">=3.1.0"
745
+ nuxt: ">=3.13.0"
717
746
  }
718
747
  },
719
748
  defaults: defaultOptions,
720
749
  async setup(passedOptions, nuxt) {
721
750
  const options = defu({}, passedOptions, defaultOptions);
751
+ const isModuleBuild = process.env.MODULE_BUILD === "true" && nuxt.options._prepare;
752
+ if (isModuleBuild) {
753
+ options.graphqlEndpoint = "http://localhost";
754
+ options.downloadSchema = false;
755
+ options.schemaPath = "~~/schema.graphql";
756
+ options.autoInlineFragments = true;
757
+ options.autoImportPatterns = [
758
+ "~~/playground/**/*.{gql,graphql}",
759
+ "!node_modules"
760
+ ];
761
+ }
722
762
  if (!passedOptions.autoImportPatterns) {
723
- options.autoImportPatterns = ["**/*.{gql,graphql}", "!node_modules"];
763
+ options.autoImportPatterns = ["~~/**/*.{gql,graphql}", "!node_modules"];
764
+ }
765
+ options.autoImportPatterns = (options.autoImportPatterns || []).map(
766
+ (pattern) => {
767
+ return resolveAlias(pattern);
768
+ }
769
+ );
770
+ if (!nuxt.options._prepare) {
771
+ validateOptions(options);
724
772
  }
725
- validateOptions(options);
773
+ const schemaPathReplaced = resolveAlias(options.schemaPath);
726
774
  const moduleResolver = createResolver(import.meta.url);
727
- const srcDir = nuxt.options.srcDir;
728
- const srcResolver = createResolver(srcDir).resolve;
775
+ const serverResolver = createResolver(nuxt.options.serverDir);
776
+ const srcResolver = createResolver(nuxt.options.srcDir);
777
+ const rootDir = nuxt.options.rootDir;
778
+ const rootResolver = createResolver(rootDir);
729
779
  const schemaPath = await getSchemaPath(
780
+ schemaPathReplaced,
730
781
  options,
731
- srcResolver,
782
+ rootResolver.resolve,
732
783
  options.downloadSchema
733
784
  );
734
785
  const runtimeDir = fileURLToPath(new URL("./runtime", import.meta.url));
@@ -770,8 +821,8 @@ const module = defineNuxtModule({
770
821
  const { templates, hasErrors, documents } = await generate(
771
822
  options,
772
823
  schemaPath,
773
- srcResolver,
774
- srcDir,
824
+ rootResolver.resolve,
825
+ rootDir,
775
826
  isFirst
776
827
  );
777
828
  ctx.templates = templates;
@@ -811,7 +862,12 @@ const module = defineNuxtModule({
811
862
  });
812
863
  prompt.then(async ({ accept }) => {
813
864
  if (accept) {
814
- await getSchemaPath(options, srcResolver, true);
865
+ await getSchemaPath(
866
+ schemaPathReplaced,
867
+ options,
868
+ rootResolver.resolve,
869
+ true
870
+ );
815
871
  await generateHandler();
816
872
  }
817
873
  });
@@ -899,22 +955,54 @@ declare module '#graphql-documents' {
899
955
  `;
900
956
  }
901
957
  });
902
- const extensions = ["js", "mjs", "ts"];
903
- const resolvedPath = "~/app/graphqlMiddleware.serverOptions".replace(/^(~~|@@)/, nuxt.options.rootDir).replace(/^(~|@)/, nuxt.options.srcDir);
904
- const template = (() => {
905
- const resolvedFilename = `graphqlMiddleware.serverOptions.ts`;
906
- const maybeUserFile = fileExists(resolvedPath, extensions);
907
- const moduleTypesPath = relative(
908
- nuxt.options.buildDir,
909
- moduleResolver.resolve("./types")
910
- );
911
- const serverOptionsLine = maybeUserFile ? `import serverOptions from './../app/graphqlMiddleware.serverOptions'` : `const serverOptions: GraphqlMiddlewareServerOptions = {}`;
912
- return addTemplate({
913
- filename: resolvedFilename,
914
- write: true,
915
- getContents: () => `
916
- import type { GraphqlMiddlewareServerOptions } from '${moduleTypesPath}'
958
+ const findServerOptions = () => {
959
+ const newPath = serverResolver.resolve("graphqlMiddleware.serverOptions");
960
+ const serverPath = fileExists(newPath);
961
+ if (serverPath) {
962
+ return serverPath;
963
+ }
964
+ const candidates = [
965
+ rootResolver.resolve("graphqlMiddleware.serverOptions"),
966
+ rootResolver.resolve("app/graphqlMiddleware.serverOptions"),
967
+ srcResolver.resolve("graphqlMiddleware.serverOptions")
968
+ ];
969
+ for (let i = 0; i < candidates.length; i++) {
970
+ const path = candidates[i];
971
+ const filePath = fileExists(path);
972
+ if (filePath) {
973
+ logger.warn(
974
+ `The graphqlMiddleware.serverOptions file should be placed in Nuxt's <serverDir> ("${nuxt.options.serverDir}/graphqlMiddleware.serverOptions.ts"). The new path will be enforced in the next major release.`
975
+ );
976
+ return filePath;
977
+ }
978
+ }
979
+ logger.info("No graphqlMiddleware.serverOptions file found.");
980
+ };
981
+ const resolvedPath = findServerOptions();
982
+ const moduleTypesPath = relative(
983
+ nuxt.options.buildDir,
984
+ moduleResolver.resolve("./types")
985
+ );
986
+ const resolvedPathRelative = resolvedPath ? relative(nuxt.options.buildDir, resolvedPath) : null;
987
+ const template = addTemplate({
988
+ filename: "graphqlMiddleware.serverOptions.mjs",
989
+ write: true,
990
+ getContents: () => {
991
+ const serverOptionsLine = resolvedPathRelative ? `import serverOptions from '${resolvedPathRelative}'` : `const serverOptions = {}`;
992
+ return `
917
993
  ${serverOptionsLine}
994
+ export { serverOptions }
995
+ `;
996
+ }
997
+ });
998
+ addTemplate({
999
+ filename: "graphqlMiddleware.serverOptions.d.ts",
1000
+ write: true,
1001
+ getContents: () => {
1002
+ const serverOptionsLineTypes = resolvedPathRelative ? `import serverOptions from '${resolvedPathRelative}'` : `const serverOptions: GraphqlMiddlewareServerOptions = {}`;
1003
+ return `
1004
+ import type { GraphqlMiddlewareServerOptions } from '${moduleTypesPath}'
1005
+ ${serverOptionsLineTypes}
918
1006
  import type { GraphqlServerResponse } from '#graphql-middleware/types'
919
1007
  import type { GraphqlMiddlewareResponseUnion } from '#build/nuxt-graphql-middleware'
920
1008
 
@@ -926,9 +1014,9 @@ export type GraphqlResponse<T> = GraphqlServerResponse<T> & GraphqlResponseAddit
926
1014
  export type GraphqlResponseTyped = GraphqlResponse<GraphqlMiddlewareResponseUnion>
927
1015
 
928
1016
  export { serverOptions }
929
- `
930
- });
931
- })();
1017
+ `;
1018
+ }
1019
+ });
932
1020
  nuxt.options.nitro.externals = nuxt.options.nitro.externals || {};
933
1021
  nuxt.options.nitro.externals.inline = nuxt.options.nitro.externals.inline || [];
934
1022
  nuxt.options.nitro.externals.inline.push(template.dst);
@@ -1,2 +1,3 @@
1
+ import type { NuxtApp } from '#app';
1
2
  import type { GraphqlMiddlewareState } from '#graphql-middleware/types';
2
- export declare const useGraphqlState: (providedApp?: any) => GraphqlMiddlewareState | null;
3
+ export declare const useGraphqlState: (providedApp?: NuxtApp) => GraphqlMiddlewareState | null;
@@ -1,5 +1,10 @@
1
+ import { type GraphqlMiddlewareState } from '#graphql-middleware/types';
1
2
  /**
2
3
  * Create and provide the state singleton for the composables.
3
4
  */
4
- declare const _default: any;
5
+ declare const _default: import("#app").Plugin<{
6
+ graphqlState: GraphqlMiddlewareState;
7
+ }> & import("#app").ObjectPlugin<{
8
+ graphqlState: GraphqlMiddlewareState;
9
+ }>;
5
10
  export default _default;
@@ -2,7 +2,7 @@ import { type QueryObject } from 'ufo';
2
2
  import type { H3Event } from 'h3';
3
3
  import type { FetchOptions, FetchResponse, FetchError } from 'ofetch';
4
4
  import type { GraphqlMiddlewareRuntimeConfig, GraphqlMiddlewareServerOptions } from './../../../types.js';
5
- import { GraphqlMiddlewareOperation } from './../../settings.js';
5
+ import { GraphqlMiddlewareOperation } from './../../settings/index.js';
6
6
  import { type Documents } from '#graphql-documents';
7
7
  export declare function queryParamToVariables(query: QueryObject): any;
8
8
  /**
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": "../../../.nuxt/tsconfig.server.json"
3
+ }
@@ -78,7 +78,6 @@ export default defineEventHandler(async (event) => {
78
78
  );
79
79
  return $fetch.raw(endpoint, {
80
80
  ...fetchOptions,
81
- // @todo: Remove any once https://github.com/unjs/nitro/pull/883 is released.
82
81
  method: "POST",
83
82
  body: formData
84
83
  }).then((response) => {
package/dist/types.d.mts CHANGED
@@ -4,8 +4,4 @@ declare module '@nuxt/schema' {
4
4
  interface NuxtHooks extends ModuleHooks {}
5
5
  }
6
6
 
7
- declare module 'nuxt/schema' {
8
- interface NuxtHooks extends ModuleHooks {}
9
- }
10
-
11
7
  export { type GraphqlMiddlewareServerOptions, type ModuleHooks, type ModuleOptions, default } from './module.js'
package/dist/types.d.ts CHANGED
@@ -4,8 +4,4 @@ declare module '@nuxt/schema' {
4
4
  interface NuxtHooks extends ModuleHooks {}
5
5
  }
6
6
 
7
- declare module 'nuxt/schema' {
8
- interface NuxtHooks extends ModuleHooks {}
9
- }
10
-
11
7
  export { type GraphqlMiddlewareServerOptions, type ModuleHooks, type ModuleOptions, default } from './module'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-graphql-middleware",
3
- "version": "4.1.0",
3
+ "version": "4.2.0",
4
4
  "description": "Module to perform GraphQL requests as a server middleware.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -33,14 +33,16 @@
33
33
  "scripts": {
34
34
  "prepack": "nuxt-module-build build && npm run client:build",
35
35
  "dev": "nuxi dev playground --trace-warnings",
36
+ "dev:layers": "nuxi dev playground-layers --trace-warnings",
36
37
  "debug": "nuxi dev playground --inspect",
37
38
  "dev:build": "nuxi build playground",
38
- "dev:prepare": "nuxt-module-build --stub && nuxi prepare playground",
39
+ "dev:layers:build": "nuxi build playground-layers",
40
+ "dev:prepare": "MODULE_BUILD=true nuxt-module-build build --stub && MODULE_BUILD=true nuxt-module-build prepare && nuxi prepare playground && nuxi prepare playground-layers",
39
41
  "dev:start": "node ./playground/.output/server/index.mjs",
40
42
  "client:build": "nuxi generate client",
41
43
  "client:dev": "nuxi dev client --port 3300",
42
44
  "typedoc": "typedoc --plugin typedoc-plugin-markdown --out foobar",
43
- "typecheck": "nuxi typecheck",
45
+ "typecheck": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit",
44
46
  "docs:dev": "vitepress dev docs --port 5000",
45
47
  "docs:build": "vitepress build docs",
46
48
  "docs:serve": "vitepress serve docs --port 5000",
@@ -64,17 +66,17 @@
64
66
  "@graphql-tools/utils": "^10.2.2",
65
67
  "@nuxt/devtools-kit": "1.3.7",
66
68
  "@nuxt/kit": "^3.12.2",
67
- "cli-table": "^0.3.11",
68
69
  "inquirer": "^9.3.2",
69
- "minisearch": "^6.3.0"
70
+ "minisearch": "^6.3.0",
71
+ "picocolors": "^1.0.1"
70
72
  },
71
73
  "devDependencies": {
72
74
  "@iconify-json/carbon": "^1.1.36",
73
75
  "@nuxt/devtools": "^1.3.7",
74
76
  "@nuxt/devtools-ui-kit": "1.3.7",
75
77
  "@nuxt/eslint": "^0.3.13",
76
- "@nuxt/module-builder": "^0.8.1",
77
- "@nuxt/schema": "^3.12.2",
78
+ "@nuxt/module-builder": "^0.8.4",
79
+ "@nuxt/schema": "^3.13.2",
78
80
  "@types/capture-console": "^1.0.5",
79
81
  "@types/cli-table": "^0.3.4",
80
82
  "@types/inquirer": "^9.0.7",
@@ -83,12 +85,13 @@
83
85
  "eslint-config-prettier": "^9.1.0",
84
86
  "eslint-plugin-prettier": "^5.1.3",
85
87
  "jsdoc-to-markdown": "^8.0.1",
86
- "nuxt": "^3.12.2",
88
+ "nuxt": "^3.13.2",
87
89
  "prettier": "^3.3.2",
88
90
  "strip-ansi": "^7.1.0",
89
91
  "typedoc": "^0.26.3",
90
92
  "typedoc-plugin-markdown": "^4.1.1",
91
93
  "vitepress": "^1.2.3",
92
- "vitest": "^1.6.0"
94
+ "vitest": "^1.6.0",
95
+ "vue-tsc": "^2.1.6"
93
96
  }
94
97
  }
@@ -1 +0,0 @@
1
- import{u as w,d as E,r as S,a as A,o as I,b as T,c as U,e as V,f as D,h as P,g as N,p as H,n as O,w as F,i as b,j as z,k as $,l as M,m as Q,q as G,s as W,_ as J,t as K,v as X,x as _,y as k,z as Y,A as Z,B as ee,C as te,D as ae}from"./CUKk0hSk.js";import{u as ne}from"./Bk31qVW4.js";async function j(t,a=w()){const{path:i,matched:v}=a.resolve(t);if(!v.length||(a._routePreloaded||(a._routePreloaded=new Set),a._routePreloaded.has(i)))return;const e=a._preloadPromises=a._preloadPromises||[];if(e.length>4)return Promise.all(e).then(()=>j(t,a));a._routePreloaded.add(i);const n=v.map(l=>{var r;return(r=l.components)==null?void 0:r.default}).filter(l=>typeof l=="function");for(const l of n){const r=Promise.resolve(l()).catch(()=>{}).finally(()=>e.splice(e.indexOf(r)));e.push(r)}await Promise.all(e)}const re=(...t)=>t.find(a=>a!==void 0);function oe(t){const a=t.componentName||"NuxtLink";function i(e,n){if(!e||t.trailingSlash!=="append"&&t.trailingSlash!=="remove")return e;if(typeof e=="string")return R(e,t.trailingSlash);const l="path"in e&&e.path!==void 0?e.path:n(e).path;return{...e,name:void 0,path:R(l,t.trailingSlash)}}function v(e){const n=w(),l=Q(),r=b(()=>!!e.target&&e.target!=="_self"),u=b(()=>{const c=e.to||e.href||"";return typeof c=="string"&&z(c,{acceptRelative:!0})}),m=N("RouterLink"),p=m&&typeof m!="string"?m.useLink:void 0,h=b(()=>{if(e.external)return!0;const c=e.to||e.href||"";return typeof c=="object"?!1:c===""||u.value}),s=b(()=>{const c=e.to||e.href||"";return h.value?c:i(c,n.resolve)}),d=h.value||p==null?void 0:p({...e,to:s}),g=b(()=>{var c;if(!s.value||u.value)return s.value;if(h.value){const f=typeof s.value=="object"?q(s.value):s.value;return i(f,n.resolve)}return typeof s.value=="object"?((c=n.resolve(s.value))==null?void 0:c.href)??null:i($(l.app.baseURL,s.value),n.resolve)});return{to:s,hasTarget:r,isAbsoluteUrl:u,isExternal:h,href:g,isActive:(d==null?void 0:d.isActive)??b(()=>s.value===n.currentRoute.value.path),isExactActive:(d==null?void 0:d.isExactActive)??b(()=>s.value===n.currentRoute.value.path),route:(d==null?void 0:d.route)??b(()=>n.resolve(s.value)),async navigate(){await M(g.value,{replace:e.replace,external:h.value||r.value})}}}return E({name:a,props:{to:{type:[String,Object],default:void 0,required:!1},href:{type:[String,Object],default:void 0,required:!1},target:{type:String,default:void 0,required:!1},rel:{type:String,default:void 0,required:!1},noRel:{type:Boolean,default:void 0,required:!1},prefetch:{type:Boolean,default:void 0,required:!1},noPrefetch:{type:Boolean,default:void 0,required:!1},activeClass:{type:String,default:void 0,required:!1},exactActiveClass:{type:String,default:void 0,required:!1},prefetchedClass:{type:String,default:void 0,required:!1},replace:{type:Boolean,default:void 0,required:!1},ariaCurrentValue:{type:String,default:void 0,required:!1},external:{type:Boolean,default:void 0,required:!1},custom:{type:Boolean,default:void 0,required:!1}},useLink:v,setup(e,{slots:n}){const l=w(),{to:r,href:u,navigate:m,isExternal:p,hasTarget:h,isAbsoluteUrl:s}=v(e),d=S(!1),g=S(null),c=f=>{var x;g.value=e.custom?(x=f==null?void 0:f.$el)==null?void 0:x.nextElementSibling:f==null?void 0:f.$el};if(e.prefetch!==!1&&e.noPrefetch!==!0&&e.target!=="_blank"&&!le()){const x=A();let y,o=null;I(()=>{const L=ie();T(()=>{y=U(()=>{var C;(C=g==null?void 0:g.value)!=null&&C.tagName&&(o=L.observe(g.value,async()=>{o==null||o(),o=null;const B=typeof r.value=="string"?r.value:p.value?q(r.value):l.resolve(r.value).fullPath;await Promise.all([x.hooks.callHook("link:prefetch",B).catch(()=>{}),!p.value&&!h.value&&j(r.value,l).catch(()=>{})]),d.value=!0}))})})}),V(()=>{y&&D(y),o==null||o(),o=null})}return()=>{var y;if(!p.value&&!h.value){const o={ref:c,to:r.value,activeClass:e.activeClass||t.activeClass,exactActiveClass:e.exactActiveClass||t.exactActiveClass,replace:e.replace,ariaCurrentValue:e.ariaCurrentValue,custom:e.custom};return e.custom||(d.value&&(o.class=e.prefetchedClass||t.prefetchedClass),o.rel=e.rel||void 0),P(N("RouterLink"),o,n.default)}const f=e.target||null,x=re(e.noRel?"":e.rel,t.externalRelAttribute,s.value||h.value?"noopener noreferrer":"")||null;return e.custom?n.default?n.default({href:u.value,navigate:m,get route(){if(!u.value)return;const o=new URL(u.value,window.location.href);return{path:o.pathname,fullPath:o.pathname,get query(){return H(o.search)},hash:o.hash,params:{},name:void 0,matched:[],redirectedFrom:void 0,meta:{},href:u.value}},rel:x,target:f,isExternal:p.value||h.value,isActive:!1,isExactActive:!1}):null:P("a",{ref:g,href:u.value||null,rel:x,target:f},(y=n.default)==null?void 0:y.call(n))}}})}const se=oe(O);function R(t,a){const i=a==="append"?G:W;return z(t)&&!t.startsWith("http")?t:i(t,!0)}function ie(){const t=A();if(t._observer)return t._observer;let a=null;const i=new Map,v=(n,l)=>(a||(a=new IntersectionObserver(r=>{for(const u of r){const m=i.get(u.target);(u.isIntersecting||u.intersectionRatio>0)&&m&&m()}})),i.set(n,l),a.observe(n),()=>{i.delete(n),a.unobserve(n),i.size===0&&(a.disconnect(),a=null)});return t._observer={observe:v}}function le(){const t=navigator.connection;return!!(t&&(t.saveData||/2g/.test(t.effectiveType)))}function q(t){return F(t.path||"",t.query||{})+(t.hash?"#"+t.hash:"")}const ue=t=>(te("data-v-c6c1efc1"),t=t(),ae(),t),ce={class:"font-sans antialiased bg-white dark:bg-black text-black dark:text-white grid min-h-screen place-content-center overflow-hidden"},de=ue(()=>_("div",{class:"fixed left-0 right-0 spotlight z-10"},null,-1)),fe={class:"max-w-520px text-center z-20"},he=["textContent"],ve=["textContent"],pe={class:"w-full flex items-center justify-center"},ge={__name:"error-404",props:{appName:{type:String,default:"Nuxt"},version:{type:String,default:""},statusCode:{type:Number,default:404},statusMessage:{type:String,default:"Not Found"},description:{type:String,default:"Sorry, the page you are looking for could not be found."},backHome:{type:String,default:"Go back home"}},setup(t){const a=t;return ne({title:`${a.statusCode} - ${a.statusMessage} | ${a.appName}`,script:[],style:[{children:'*,:before,:after{box-sizing:border-box;border-width:0;border-style:solid;border-color:var(--un-default-border-color, #e5e7eb)}:before,:after{--un-content:""}html{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;tab-size:4;font-family:ui-sans-serif,system-ui,sans-serif,"Apple Color Emoji","Segoe UI Emoji",Segoe UI Symbol,"Noto Color Emoji";font-feature-settings:normal;font-variation-settings:normal;-webkit-tap-highlight-color:transparent}body{margin:0;line-height:inherit}h1{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}h1,p{margin:0}*,:before,:after{--un-rotate:0;--un-rotate-x:0;--un-rotate-y:0;--un-rotate-z:0;--un-scale-x:1;--un-scale-y:1;--un-scale-z:1;--un-skew-x:0;--un-skew-y:0;--un-translate-x:0;--un-translate-y:0;--un-translate-z:0;--un-pan-x: ;--un-pan-y: ;--un-pinch-zoom: ;--un-scroll-snap-strictness:proximity;--un-ordinal: ;--un-slashed-zero: ;--un-numeric-figure: ;--un-numeric-spacing: ;--un-numeric-fraction: ;--un-border-spacing-x:0;--un-border-spacing-y:0;--un-ring-offset-shadow:0 0 rgb(0 0 0 / 0);--un-ring-shadow:0 0 rgb(0 0 0 / 0);--un-shadow-inset: ;--un-shadow:0 0 rgb(0 0 0 / 0);--un-ring-inset: ;--un-ring-offset-width:0px;--un-ring-offset-color:#fff;--un-ring-width:0px;--un-ring-color:rgb(147 197 253 / .5);--un-blur: ;--un-brightness: ;--un-contrast: ;--un-drop-shadow: ;--un-grayscale: ;--un-hue-rotate: ;--un-invert: ;--un-saturate: ;--un-sepia: ;--un-backdrop-blur: ;--un-backdrop-brightness: ;--un-backdrop-contrast: ;--un-backdrop-grayscale: ;--un-backdrop-hue-rotate: ;--un-backdrop-invert: ;--un-backdrop-opacity: ;--un-backdrop-saturate: ;--un-backdrop-sepia: }'}]}),(i,v)=>{const e=se;return K(),X("div",ce,[de,_("div",fe,[_("h1",{class:"text-8xl sm:text-10xl font-medium mb-8",textContent:k(t.statusCode)},null,8,he),_("p",{class:"text-xl px-8 sm:px-0 sm:text-4xl font-light mb-16 leading-tight",textContent:k(t.description)},null,8,ve),_("div",pe,[Y(e,{to:"/",class:"gradient-border text-md sm:text-xl py-2 px-4 sm:py-3 sm:px-6 cursor-pointer"},{default:Z(()=>[ee(k(t.backHome),1)]),_:1})])])])}}},xe=J(ge,[["__scopeId","data-v-c6c1efc1"]]);export{xe as default};