nitro-graphql 2.0.0-beta.4 → 2.0.0-beta.40

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 (162) hide show
  1. package/README.md +441 -27
  2. package/dist/cli/commands/generate.d.mts +26 -0
  3. package/dist/cli/commands/generate.mjs +196 -0
  4. package/dist/cli/commands/index.d.mts +4 -0
  5. package/dist/cli/commands/index.mjs +5 -0
  6. package/dist/cli/commands/init.d.mts +46 -0
  7. package/dist/cli/commands/init.mjs +195 -0
  8. package/dist/cli/commands/validate.d.mts +10 -0
  9. package/dist/cli/commands/validate.mjs +69 -0
  10. package/dist/cli/completions.d.mts +7 -0
  11. package/dist/cli/completions.mjs +34 -0
  12. package/dist/cli/config.d.mts +75 -0
  13. package/dist/cli/config.mjs +20 -0
  14. package/dist/cli/index.d.mts +24 -0
  15. package/dist/cli/index.mjs +253 -0
  16. package/dist/core/codegen/client.d.mts +23 -0
  17. package/dist/core/codegen/client.mjs +150 -0
  18. package/dist/core/codegen/document-loader.d.mts +10 -0
  19. package/dist/core/codegen/document-loader.mjs +18 -0
  20. package/dist/core/codegen/index.d.mts +8 -0
  21. package/dist/core/codegen/index.mjs +9 -0
  22. package/dist/core/codegen/plugin.d.mts +20 -0
  23. package/dist/core/codegen/plugin.mjs +30 -0
  24. package/dist/core/codegen/runtime.d.mts +20 -0
  25. package/dist/core/codegen/runtime.mjs +60 -0
  26. package/dist/core/codegen/schema-loader.d.mts +28 -0
  27. package/dist/core/codegen/schema-loader.mjs +128 -0
  28. package/dist/core/codegen/server.d.mts +28 -0
  29. package/dist/core/codegen/server.mjs +143 -0
  30. package/dist/core/codegen/validation.d.mts +13 -0
  31. package/dist/core/codegen/validation.mjs +96 -0
  32. package/dist/core/config.d.mts +50 -0
  33. package/dist/core/config.mjs +82 -0
  34. package/dist/core/constants.d.mts +188 -0
  35. package/dist/core/constants.mjs +210 -0
  36. package/dist/core/index.d.mts +32 -0
  37. package/dist/core/index.mjs +26 -0
  38. package/dist/core/scanning/ast-scanner.d.mts +23 -0
  39. package/dist/core/scanning/ast-scanner.mjs +103 -0
  40. package/dist/core/scanning/common.d.mts +37 -0
  41. package/dist/core/scanning/common.mjs +60 -0
  42. package/dist/core/scanning/directives.d.mts +10 -0
  43. package/dist/core/scanning/directives.mjs +29 -0
  44. package/dist/core/scanning/documents.d.mts +21 -0
  45. package/dist/core/scanning/documents.mjs +43 -0
  46. package/dist/core/scanning/index.d.mts +7 -0
  47. package/dist/core/scanning/index.mjs +8 -0
  48. package/dist/core/scanning/resolvers.d.mts +10 -0
  49. package/dist/core/scanning/resolvers.mjs +58 -0
  50. package/dist/core/scanning/schemas.d.mts +14 -0
  51. package/dist/core/scanning/schemas.mjs +64 -0
  52. package/dist/core/schema/builder.d.mts +53 -0
  53. package/dist/core/schema/builder.mjs +70 -0
  54. package/dist/core/schema/federation.d.mts +34 -0
  55. package/dist/core/schema/federation.mjs +40 -0
  56. package/dist/core/schema/index.d.mts +3 -0
  57. package/dist/core/schema/index.mjs +4 -0
  58. package/dist/core/types/adapter.d.mts +58 -0
  59. package/dist/core/types/codegen.d.mts +133 -0
  60. package/dist/core/types/config.d.mts +212 -0
  61. package/dist/core/types/config.mjs +1 -0
  62. package/dist/{utils/define.d.ts → core/types/define.d.mts} +3 -30
  63. package/dist/core/types/define.mjs +1 -0
  64. package/dist/core/types/index.d.mts +5 -0
  65. package/dist/core/types/index.mjs +1 -0
  66. package/dist/core/types/scanning.d.mts +69 -0
  67. package/dist/core/types/scanning.mjs +1 -0
  68. package/dist/{utils/directive-parser.d.ts → core/utils/directive-parser.d.mts} +21 -4
  69. package/dist/{utils/directive-parser.js → core/utils/directive-parser.mjs} +25 -34
  70. package/dist/core/utils/errors.d.mts +77 -0
  71. package/dist/core/utils/errors.mjs +93 -0
  72. package/dist/core/utils/file-io.d.mts +24 -0
  73. package/dist/core/utils/file-io.mjs +47 -0
  74. package/dist/core/utils/imports.d.mts +15 -0
  75. package/dist/core/utils/imports.mjs +25 -0
  76. package/dist/core/utils/index.d.mts +7 -0
  77. package/dist/core/utils/index.mjs +8 -0
  78. package/dist/core/utils/logger.d.mts +19 -0
  79. package/dist/core/utils/logger.mjs +38 -0
  80. package/dist/core/utils/ofetch-templates.d.mts +30 -0
  81. package/dist/core/utils/ofetch-templates.mjs +135 -0
  82. package/dist/core/validation/external-services.d.mts +11 -0
  83. package/dist/core/validation/external-services.mjs +34 -0
  84. package/dist/core/validation/index.d.mts +2 -0
  85. package/dist/core/validation/index.mjs +3 -0
  86. package/dist/define.d.mts +294 -0
  87. package/dist/define.mjs +323 -0
  88. package/dist/index.d.mts +6 -0
  89. package/dist/index.mjs +6 -0
  90. package/dist/nitro/adapter.d.mts +30 -0
  91. package/dist/nitro/adapter.mjs +97 -0
  92. package/dist/{utils/apollo.d.ts → nitro/apollo.d.mts} +3 -3
  93. package/dist/nitro/apollo.mjs +59 -0
  94. package/dist/nitro/codegen.d.mts +19 -0
  95. package/dist/nitro/codegen.mjs +141 -0
  96. package/dist/nitro/config.d.mts +52 -0
  97. package/dist/nitro/config.mjs +58 -0
  98. package/dist/nitro/index.d.mts +46 -0
  99. package/dist/nitro/index.mjs +65 -0
  100. package/dist/nitro/paths.d.mts +54 -0
  101. package/dist/nitro/paths.mjs +93 -0
  102. package/dist/nitro/rollup.d.mts +6 -0
  103. package/dist/nitro/rollup.mjs +95 -0
  104. package/dist/nitro/routes/apollo-server.d.mts +6 -0
  105. package/dist/nitro/routes/apollo-server.mjs +71 -0
  106. package/dist/nitro/routes/debug-template.d.mts +15 -0
  107. package/dist/nitro/routes/debug-template.mjs +385 -0
  108. package/dist/nitro/routes/debug.d.mts +55 -0
  109. package/dist/nitro/routes/debug.mjs +102 -0
  110. package/dist/nitro/routes/graphql-yoga.d.mts +6 -0
  111. package/dist/nitro/routes/graphql-yoga.mjs +62 -0
  112. package/dist/nitro/routes/health.d.mts +10 -0
  113. package/dist/{routes/health.js → nitro/routes/health.mjs} +4 -3
  114. package/dist/nitro/setup/file-watcher.d.mts +16 -0
  115. package/dist/nitro/setup/file-watcher.mjs +80 -0
  116. package/dist/nitro/setup/logging.d.mts +17 -0
  117. package/dist/nitro/setup/logging.mjs +66 -0
  118. package/dist/nitro/setup/rollup-integration.d.mts +16 -0
  119. package/dist/nitro/setup/rollup-integration.mjs +90 -0
  120. package/dist/nitro/setup/routes.d.mts +10 -0
  121. package/dist/nitro/setup/routes.mjs +35 -0
  122. package/dist/nitro/setup/ts-config.d.mts +11 -0
  123. package/dist/nitro/setup/ts-config.mjs +69 -0
  124. package/dist/nitro/setup.d.mts +12 -0
  125. package/dist/nitro/setup.mjs +231 -0
  126. package/dist/nitro/types.d.mts +378 -0
  127. package/dist/nitro/types.mjs +1 -0
  128. package/dist/nitro/virtual/generators.d.mts +31 -0
  129. package/dist/nitro/virtual/generators.mjs +193 -0
  130. package/dist/nitro/virtual/stubs.d.mts +20 -0
  131. package/dist/nitro/virtual/stubs.mjs +31 -0
  132. package/dist/{ecosystem/nuxt.d.ts → nuxt.d.mts} +1 -1
  133. package/dist/nuxt.mjs +109 -0
  134. package/dist/{graphql/server.d.ts → stubs/index.d.mts} +5 -1
  135. package/dist/stubs/index.mjs +1 -0
  136. package/package.json +97 -78
  137. package/dist/ecosystem/nuxt.js +0 -67
  138. package/dist/graphql/index.d.ts +0 -5
  139. package/dist/index.d.ts +0 -8
  140. package/dist/index.js +0 -264
  141. package/dist/rollup.js +0 -119
  142. package/dist/routes/apollo-server.d.ts +0 -6
  143. package/dist/routes/apollo-server.js +0 -89
  144. package/dist/routes/graphql-yoga.d.ts +0 -6
  145. package/dist/routes/graphql-yoga.js +0 -91
  146. package/dist/routes/health.d.ts +0 -6
  147. package/dist/types/index.d.ts +0 -128
  148. package/dist/types/standard-schema.d.ts +0 -59
  149. package/dist/utils/apollo.js +0 -61
  150. package/dist/utils/client-codegen.d.ts +0 -38
  151. package/dist/utils/client-codegen.js +0 -290
  152. package/dist/utils/define.js +0 -57
  153. package/dist/utils/index.d.ts +0 -39
  154. package/dist/utils/index.js +0 -250
  155. package/dist/utils/server-codegen.d.ts +0 -7
  156. package/dist/utils/server-codegen.js +0 -136
  157. package/dist/utils/type-generation.d.ts +0 -7
  158. package/dist/utils/type-generation.js +0 -287
  159. package/dist/vite.d.ts +0 -25
  160. package/dist/vite.js +0 -40
  161. /package/dist/{graphql/index.js → core/types/adapter.mjs} +0 -0
  162. /package/dist/{graphql/server.js → core/types/codegen.mjs} +0 -0
@@ -0,0 +1,193 @@
1
+ import { getImportId } from "../../core/utils/imports.mjs";
2
+ import { isAbsolute, resolve } from "pathe";
3
+ import { genImport } from "knitwork";
4
+
5
+ //#region src/nitro/virtual/generators.ts
6
+ function normalizeExtendConfig(extend) {
7
+ if (!extend || !Array.isArray(extend) || extend.length === 0) return null;
8
+ const resolvers = [];
9
+ const schemas = [];
10
+ for (const source of extend) if (typeof source === "string") {
11
+ resolvers.push(`${source}/resolvers`);
12
+ schemas.push(`${source}/schema`);
13
+ } else if (source && typeof source === "object") {
14
+ const obj = source;
15
+ if (obj.resolvers) {
16
+ const r = Array.isArray(obj.resolvers) ? obj.resolvers : [obj.resolvers];
17
+ resolvers.push(...r);
18
+ }
19
+ if (obj.schemas) {
20
+ const s = Array.isArray(obj.schemas) ? obj.schemas : [obj.schemas];
21
+ schemas.push(...s);
22
+ }
23
+ }
24
+ if (resolvers.length === 0 && schemas.length === 0) return null;
25
+ return {
26
+ resolvers,
27
+ schemas
28
+ };
29
+ }
30
+ /**
31
+ * Resolve extend path to absolute path
32
+ * Supports: relative paths, absolute paths, package names
33
+ */
34
+ function resolveExtendPath(nitro, inputPath) {
35
+ if (inputPath.startsWith("@") || !inputPath.startsWith(".") && !inputPath.startsWith("/")) return inputPath;
36
+ if (isAbsolute(inputPath)) return inputPath;
37
+ return resolve(nitro.options.rootDir, inputPath);
38
+ }
39
+ function generateImportModule(items, exportName, wrapperKey) {
40
+ if (!items.length) return `export const ${exportName} = []`;
41
+ const imports = items.flatMap(({ specifier, imports: list, options }) => list?.length ? [genImport(specifier, list, options)] : []);
42
+ const data = items.flatMap(({ imports: list }) => list.map((i) => `{ ${wrapperKey}: ${i.as || i.name} }`));
43
+ return `${imports.join("\n")}\n\nexport const ${exportName} = [\n${data.join(",\n")}\n]`;
44
+ }
45
+ function safeGenerateModuleCode(nitro, moduleName) {
46
+ try {
47
+ const generator = nitro.options.virtual?.[moduleName];
48
+ if (generator && typeof generator === "function") return generator();
49
+ return "// Module not found";
50
+ } catch (error) {
51
+ return `// Error: ${error instanceof Error ? error.message : String(error)}`;
52
+ }
53
+ }
54
+ const serverSchemas = {
55
+ id: "#nitro-graphql/server-schemas",
56
+ getCode: (nitro) => {
57
+ const ext = normalizeExtendConfig(nitro.options.graphql?.extend);
58
+ const skipLocalScan = nitro.options.graphql?.skipLocalScan === true;
59
+ if (ext && ext.schemas.length > 0) {
60
+ const schemaPaths = ext.schemas.map((p) => resolveExtendPath(nitro, p));
61
+ const scannedSchemas = [...nitro.scanSchemas, ...nitro.options.graphql?.typedefs ?? []];
62
+ if (!skipLocalScan && scannedSchemas.length > 0) {
63
+ const extImports = schemaPaths.map((p, i) => `import { schemaString as extSchema${i} } from '${p}'`);
64
+ const scannedImports = scannedSchemas.map((s) => `import ${getImportId(s)} from '${s}';`);
65
+ const extDefs = schemaPaths.map((_, i) => `{ def: extSchema${i} }`);
66
+ const scannedDefs = scannedSchemas.map((s) => `{ def: ${getImportId(s)} }`);
67
+ return `${extImports.join("\n")}
68
+ ${scannedImports.join("\n")}
69
+
70
+ export const schemas = [
71
+ ${[...extDefs, ...scannedDefs].join(",\n")}
72
+ ]`;
73
+ }
74
+ if (schemaPaths.length === 1) return `import { schemaString, typeDefs } from '${schemaPaths[0]}'
75
+ export { schemaString, typeDefs }
76
+ export const schemas = [{ def: schemaString }]`;
77
+ const imports = schemaPaths.map((p, i) => `import { schemaString as schema${i} } from '${p}'`);
78
+ const schemaVars = schemaPaths.map((_, i) => `schema${i}`);
79
+ const mergeCode = `export const schemaString = [${schemaVars.join(", ")}].join('\\n\\n')
80
+ import { parse } from 'graphql'
81
+ export const typeDefs = parse(schemaString)
82
+ export const schemas = [${schemaVars.map((v) => `{ def: ${v} }`).join(", ")}]`;
83
+ return `${imports.join("\n")}\n\n${mergeCode}`;
84
+ }
85
+ const schemas = [...nitro.scanSchemas, ...nitro.options.graphql?.typedefs ?? []];
86
+ if (!schemas.length) {
87
+ if (nitro.options.dev) nitro.logger.warn("[nitro-graphql] No schemas found. Virtual module will export empty array.");
88
+ return "export const schemas = []";
89
+ }
90
+ const importStatements = schemas.map((s) => `import ${getImportId(s)} from '${s}';`);
91
+ const schemaArray = schemas.map((s) => `{ def: ${getImportId(s)} }`);
92
+ return `${importStatements.join("\n")}\n\nexport const schemas = [\n${schemaArray.join(",\n")}\n];`;
93
+ }
94
+ };
95
+ const serverResolvers = {
96
+ id: "#nitro-graphql/server-resolvers",
97
+ getCode: (nitro) => {
98
+ const ext = normalizeExtendConfig(nitro.options.graphql?.extend);
99
+ const skipLocalScan = nitro.options.graphql?.skipLocalScan === true;
100
+ if (ext && ext.resolvers.length > 0) {
101
+ const resolverPaths = ext.resolvers.map((p) => resolveExtendPath(nitro, p));
102
+ const imports$1 = resolverPaths.map((p, i) => `import { resolvers as resolvers${i} } from '${p}'`);
103
+ if (!skipLocalScan && nitro.scanResolvers.length > 0) {
104
+ const scannedCode = generateImportModule(nitro.scanResolvers, "scannedResolvers", "resolver");
105
+ const spreadAll$1 = [...resolverPaths.map((_, i) => `...resolvers${i}`), "...scannedResolvers"];
106
+ return `${imports$1.join("\n")}
107
+ ${scannedCode}
108
+
109
+ export const resolvers = [${spreadAll$1.join(", ")}]`;
110
+ }
111
+ if (resolverPaths.length === 1) return `export { resolvers } from '${resolverPaths[0]}'`;
112
+ const spreadAll = resolverPaths.map((_, i) => `...resolvers${i}`);
113
+ return `${imports$1.join("\n")}
114
+
115
+ export const resolvers = [${spreadAll.join(", ")}]`;
116
+ }
117
+ const imports = [...nitro.scanResolvers];
118
+ if (!imports.length) {
119
+ if (nitro.options.dev) nitro.logger.warn("[nitro-graphql] No resolvers found. Virtual module will export empty array.");
120
+ return "export const resolvers = []";
121
+ }
122
+ return generateImportModule(imports, "resolvers", "resolver");
123
+ }
124
+ };
125
+ const serverDirectives = {
126
+ id: "#nitro-graphql/server-directives",
127
+ getCode: (nitro) => {
128
+ const imports = nitro.scanDirectives || [];
129
+ if (!imports.length) return "export const directives = []";
130
+ return generateImportModule(imports, "directives", "directive");
131
+ }
132
+ };
133
+ const graphqlConfig = {
134
+ id: "#nitro-graphql/graphql-config",
135
+ getCode: (nitro) => {
136
+ return `import config from '${resolve(nitro.graphql.serverDir, "config.ts")}'
137
+ const importedConfig = config
138
+ export { importedConfig }
139
+ `;
140
+ }
141
+ };
142
+ const moduleConfig = {
143
+ id: "#nitro-graphql/module-config",
144
+ getCode: (nitro) => {
145
+ const config = nitro.options.graphql || {};
146
+ return `export const moduleConfig = ${JSON.stringify(config, null, 2)};`;
147
+ }
148
+ };
149
+ const debugInfo = {
150
+ id: "#nitro-graphql/debug-info",
151
+ getCode: (nitro) => {
152
+ const virtualModuleCodes = {
153
+ "server-schemas": safeGenerateModuleCode(nitro, "#nitro-graphql/server-schemas"),
154
+ "server-resolvers": safeGenerateModuleCode(nitro, "#nitro-graphql/server-resolvers"),
155
+ "server-directives": safeGenerateModuleCode(nitro, "#nitro-graphql/server-directives"),
156
+ "module-config": safeGenerateModuleCode(nitro, "#nitro-graphql/module-config"),
157
+ "graphql-config": safeGenerateModuleCode(nitro, "#nitro-graphql/graphql-config")
158
+ };
159
+ const info = {
160
+ isDev: nitro.options.dev,
161
+ framework: nitro.options.framework.name,
162
+ graphqlFramework: nitro.options.graphql?.framework,
163
+ federation: nitro.options.graphql?.federation,
164
+ scanned: {
165
+ schemas: nitro.scanSchemas?.length || 0,
166
+ schemaFiles: nitro.scanSchemas || [],
167
+ resolvers: nitro.scanResolvers?.length || 0,
168
+ resolverFiles: nitro.scanResolvers || [],
169
+ directives: nitro.scanDirectives?.length || 0,
170
+ directiveFiles: nitro.scanDirectives || [],
171
+ documents: nitro.scanDocuments?.length || 0,
172
+ documentFiles: nitro.scanDocuments || []
173
+ },
174
+ virtualModules: virtualModuleCodes
175
+ };
176
+ return `export const debugInfo = ${JSON.stringify(info, null, 2)};`;
177
+ }
178
+ };
179
+ const allModules = [
180
+ serverSchemas,
181
+ serverResolvers,
182
+ serverDirectives,
183
+ graphqlConfig,
184
+ moduleConfig,
185
+ debugInfo
186
+ ];
187
+ function registerAllVirtualModules(nitro) {
188
+ nitro.options.virtual ??= {};
189
+ for (const mod of allModules) nitro.options.virtual[mod.id] = () => mod.getCode(nitro);
190
+ }
191
+
192
+ //#endregion
193
+ export { debugInfo, graphqlConfig, moduleConfig, registerAllVirtualModules, serverDirectives, serverResolvers, serverSchemas };
@@ -0,0 +1,20 @@
1
+ //#region src/nitro/virtual/stubs.d.ts
2
+ /**
3
+ * Virtual module stubs for #nitro-graphql/*
4
+ * Used during build to prevent import resolution errors.
5
+ * At runtime, Nitro overrides these with actual virtual modules.
6
+ */
7
+ declare const schemas: Array<{
8
+ def: string;
9
+ }>;
10
+ declare const resolvers: Array<{
11
+ resolver: any;
12
+ }>;
13
+ declare const directives: Array<{
14
+ directive: any;
15
+ }>;
16
+ declare const moduleConfig: {};
17
+ declare const importedConfig: {};
18
+ declare const debugInfo: Record<string, any>;
19
+ //#endregion
20
+ export { debugInfo, directives, importedConfig, moduleConfig, resolvers, schemas };
@@ -0,0 +1,31 @@
1
+ //#region src/nitro/virtual/stubs.ts
2
+ /**
3
+ * Virtual module stubs for #nitro-graphql/*
4
+ * Used during build to prevent import resolution errors.
5
+ * At runtime, Nitro overrides these with actual virtual modules.
6
+ */
7
+ const schemas = [];
8
+ const resolvers = [];
9
+ const directives = [];
10
+ const moduleConfig = {};
11
+ const importedConfig = {};
12
+ const debugInfo = {
13
+ isDev: false,
14
+ framework: "",
15
+ graphqlFramework: "",
16
+ federation: {},
17
+ scanned: {
18
+ schemas: 0,
19
+ schemaFiles: [],
20
+ resolvers: 0,
21
+ resolverFiles: [],
22
+ directives: 0,
23
+ directiveFiles: [],
24
+ documents: 0,
25
+ documentFiles: []
26
+ },
27
+ virtualModules: {}
28
+ };
29
+
30
+ //#endregion
31
+ export { debugInfo, directives, importedConfig, moduleConfig, resolvers, schemas };
@@ -1,6 +1,6 @@
1
1
  import * as _nuxt_schema0 from "@nuxt/schema";
2
2
 
3
- //#region src/ecosystem/nuxt.d.ts
3
+ //#region src/nuxt.d.ts
4
4
  interface ModuleOptions {}
5
5
  declare const _default: _nuxt_schema0.NuxtModule<ModuleOptions, ModuleOptions, false>;
6
6
  //#endregion
package/dist/nuxt.mjs ADDED
@@ -0,0 +1,109 @@
1
+ import { getDefaultPaths, getTypesConfig, resolveFilePath } from "./nitro/paths.mjs";
2
+ import { dirname, join, relative, resolve } from "pathe";
3
+ import { existsSync, mkdirSync, writeFileSync } from "node:fs";
4
+ import { defineNuxtModule, getLayerDirectories } from "@nuxt/kit";
5
+
6
+ //#region src/nuxt.ts
7
+ var nuxt_default = defineNuxtModule({
8
+ meta: {
9
+ name: "nitro-graphql-nuxt",
10
+ configKey: "nitro-graphql-nuxt",
11
+ compatibility: { nuxt: ">=3.16.0" }
12
+ },
13
+ setup: async (_options, nuxt) => {
14
+ nuxt.hooks.hook("prepare:types", (options) => {
15
+ const mockNitro$1 = { options: {
16
+ rootDir: nuxt.options.rootDir,
17
+ buildDir: nuxt.options.buildDir,
18
+ framework: { name: "nuxt" },
19
+ graphql: nuxt.options.nitro?.graphql
20
+ } };
21
+ const placeholders$1 = getDefaultPaths(mockNitro$1);
22
+ const typesConfig$1 = getTypesConfig(mockNitro$1);
23
+ const tsconfigDir = dirname(join(nuxt.options.buildDir, "tsconfig.json"));
24
+ const relativeWithDot = (from, to) => {
25
+ const rel = relative(from, to);
26
+ return rel.startsWith(".") ? rel : `./${rel}`;
27
+ };
28
+ const clientTypesPath$1 = resolveFilePath(typesConfig$1.client, typesConfig$1.enabled, true, "{typesDir}/nitro-graphql-client.d.ts", placeholders$1);
29
+ if (clientTypesPath$1) {
30
+ const relativePath = relativeWithDot(tsconfigDir, clientTypesPath$1);
31
+ options.references.push({ path: relativePath });
32
+ options.tsConfig ??= {};
33
+ options.tsConfig.compilerOptions ??= {};
34
+ options.tsConfig.compilerOptions.paths ??= {};
35
+ options.tsConfig.compilerOptions.paths["#graphql/client"] = [relativePath];
36
+ options.tsConfig.include = options.tsConfig.include || [];
37
+ options.tsConfig.include.push(relativePath);
38
+ }
39
+ const externalServices$1 = nuxt.options.nitro?.graphql?.externalServices || [];
40
+ for (const service of externalServices$1) {
41
+ const servicePlaceholders = {
42
+ ...placeholders$1,
43
+ serviceName: service.name
44
+ };
45
+ const externalTypesPath = resolveFilePath(service.paths?.types ?? typesConfig$1.external, typesConfig$1.enabled, true, "{typesDir}/nitro-graphql-client-{serviceName}.d.ts", servicePlaceholders);
46
+ if (externalTypesPath) {
47
+ const relativePath = relativeWithDot(tsconfigDir, externalTypesPath);
48
+ options.references.push({ path: relativePath });
49
+ if (options.tsConfig.compilerOptions) options.tsConfig.compilerOptions.paths[`#graphql/client/${service.name}`] = [relativePath];
50
+ if (options.tsConfig.include) options.tsConfig.include.push(relativePath);
51
+ }
52
+ }
53
+ });
54
+ nuxt.options.alias = nuxt.options.alias || {};
55
+ const mockNitro = { options: {
56
+ rootDir: nuxt.options.rootDir,
57
+ buildDir: nuxt.options.buildDir,
58
+ framework: { name: "nuxt" },
59
+ graphql: nuxt.options.nitro?.graphql
60
+ } };
61
+ const placeholders = getDefaultPaths(mockNitro);
62
+ const typesConfig = getTypesConfig(mockNitro);
63
+ const clientTypesPath = resolveFilePath(typesConfig.client, typesConfig.enabled, true, "{typesDir}/nitro-graphql-client.d.ts", placeholders);
64
+ if (clientTypesPath) nuxt.options.alias["#graphql/client"] = clientTypesPath;
65
+ const externalServices = nuxt.options.nitro?.graphql?.externalServices || [];
66
+ for (const service of externalServices) {
67
+ const servicePlaceholders = {
68
+ ...placeholders,
69
+ serviceName: service.name
70
+ };
71
+ const externalTypesPath = resolveFilePath(service.paths?.types ?? typesConfig.external, typesConfig.enabled, true, "{typesDir}/nitro-graphql-client-{serviceName}.d.ts", servicePlaceholders);
72
+ if (externalTypesPath) nuxt.options.alias[`#graphql/client/${service.name}`] = externalTypesPath;
73
+ }
74
+ nuxt.hook("imports:dirs", (dirs) => {
75
+ const graphqlServerPath = nuxt.options.nitro?.graphql?.serverDir || resolve(nuxt.options.srcDir, "graphql");
76
+ dirs.push(graphqlServerPath);
77
+ });
78
+ nuxt.hook("nitro:config", async (nitroConfig) => {
79
+ const clientDir = join(nuxt.options.buildDir, "graphql");
80
+ const layerDirs = await getLayerDirectories(nuxt);
81
+ const layerDirectories = layerDirs.map((layer) => layer.root.replace(/\/$/, "")).filter((root) => root !== nuxt.options.rootDir);
82
+ const layerServerDirs = layerDirs.filter((layer) => layer.root !== `${nuxt.options.rootDir}/`).map((layer) => layer.server?.replace(/\/$/, "")).filter(Boolean);
83
+ const layerAppDirs = layerDirs.filter((layer) => layer.root !== `${nuxt.options.rootDir}/`).map((layer) => layer.app?.replace(/\/$/, "")).filter(Boolean);
84
+ if (!nitroConfig.graphql) nitroConfig.graphql = {};
85
+ nitroConfig.graphql.layerDirectories = layerDirectories;
86
+ nitroConfig.graphql.layerServerDirs = layerServerDirs;
87
+ nitroConfig.graphql.layerAppDirs = layerAppDirs;
88
+ if (!existsSync(resolve(nuxt.options.rootDir, "app/graphql"))) {
89
+ const defaultDir = join(clientDir, "default");
90
+ if (!existsSync(defaultDir)) mkdirSync(defaultDir, { recursive: true });
91
+ const sampleQueryFile = join(defaultDir, "queries.graphql");
92
+ if (!existsSync(sampleQueryFile)) writeFileSync(sampleQueryFile, `# Example GraphQL queries
93
+ # Add your GraphQL queries here
94
+
95
+ # query GetUser($id: ID!) {
96
+ # user(id: $id) {
97
+ # id
98
+ # name
99
+ # email
100
+ # }
101
+ # }
102
+ `, "utf-8");
103
+ }
104
+ });
105
+ }
106
+ });
107
+
108
+ //#endregion
109
+ export { nuxt_default as default };
@@ -1,4 +1,8 @@
1
- //#region src/graphql/server.d.ts
1
+ //#region src/stubs/index.d.ts
2
+ /**
3
+ * Runtime type stubs for GraphQL types
4
+ * These interfaces are replaced by generated types at build time
5
+ */
2
6
  interface StandardSchemaV1 extends Record<string, any> {}
3
7
  interface ResolversTypes extends Record<string, any> {}
4
8
  interface Resolvers extends Record<string, any> {}
@@ -0,0 +1 @@
1
+ export { };
package/package.json CHANGED
@@ -1,127 +1,137 @@
1
1
  {
2
2
  "name": "nitro-graphql",
3
3
  "type": "module",
4
- "version": "2.0.0-beta.4",
4
+ "version": "2.0.0-beta.40",
5
5
  "description": "GraphQL integration for Nitro",
6
6
  "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/productdevbook/nitro-graphql"
10
+ },
7
11
  "sideEffects": false,
8
12
  "imports": {
9
13
  "#graphql/server": {
10
- "types": "./dist/graphql/server.d.ts",
11
- "import": "./dist/graphql/server.js"
12
- }
13
- },
14
- "exports": {
15
- ".": {
16
- "types": "./dist/index.d.ts",
17
- "import": "./dist/index.js"
14
+ "types": "./dist/stubs/index.d.mts",
15
+ "import": "./dist/stubs/index.mjs"
18
16
  },
19
- "./codegen": {
20
- "types": "./dist/codegen.d.ts",
21
- "import": "./dist/codegen.js"
17
+ "#nitro-graphql/graphql-config": {
18
+ "types": "./dist/nitro/virtual/stubs.d.mts",
19
+ "import": "./dist/nitro/virtual/stubs.mjs"
22
20
  },
23
- "./watcher": {
24
- "types": "./dist/watcher.d.ts",
25
- "import": "./dist/watcher.js"
21
+ "#nitro-graphql/server-schemas": {
22
+ "types": "./dist/nitro/virtual/stubs.d.mts",
23
+ "import": "./dist/nitro/virtual/stubs.mjs"
26
24
  },
27
- "./client-watcher": {
28
- "types": "./dist/client-watcher.d.ts",
29
- "import": "./dist/client-watcher.js"
25
+ "#nitro-graphql/server-resolvers": {
26
+ "types": "./dist/nitro/virtual/stubs.d.mts",
27
+ "import": "./dist/nitro/virtual/stubs.mjs"
30
28
  },
31
- "./context": {
32
- "types": "./dist/context.d.ts",
33
- "import": "./dist/context.js"
29
+ "#nitro-graphql/server-directives": {
30
+ "types": "./dist/nitro/virtual/stubs.d.mts",
31
+ "import": "./dist/nitro/virtual/stubs.mjs"
34
32
  },
35
- "./utils": {
36
- "types": "./dist/utils/index.d.ts",
37
- "import": "./dist/utils/index.js"
33
+ "#nitro-graphql/module-config": {
34
+ "types": "./dist/nitro/virtual/stubs.d.mts",
35
+ "import": "./dist/nitro/virtual/stubs.mjs"
38
36
  },
39
- "./utils/define": {
40
- "types": "./dist/utils/define.d.ts",
41
- "import": "./dist/utils/define.js"
37
+ "#nitro-graphql/debug-info": {
38
+ "types": "./dist/nitro/virtual/stubs.d.mts",
39
+ "import": "./dist/nitro/virtual/stubs.mjs"
40
+ }
41
+ },
42
+ "exports": {
43
+ ".": {
44
+ "types": "./dist/index.d.mts",
45
+ "import": "./dist/index.mjs"
42
46
  },
43
- "./utils/apollo": {
44
- "types": "./dist/utils/apollo.d.ts",
45
- "import": "./dist/utils/apollo.js"
47
+ "./core": {
48
+ "types": "./dist/core/index.d.mts",
49
+ "import": "./dist/core/index.mjs"
46
50
  },
47
- "./internal": {
48
- "types": "./dist/internal/index.d.ts",
49
- "import": "./dist/internal/index.js"
51
+ "./cli": {
52
+ "types": "./dist/cli/index.d.mts",
53
+ "import": "./dist/cli/index.mjs"
50
54
  },
51
- "./nuxt": {
52
- "types": "./dist/ecosystem/nuxt.d.ts",
53
- "import": "./dist/ecosystem/nuxt.js"
55
+ "./define": {
56
+ "types": "./dist/define.d.mts",
57
+ "import": "./dist/define.mjs"
58
+ },
59
+ "./apollo": {
60
+ "types": "./dist/nitro/apollo.d.mts",
61
+ "import": "./dist/nitro/apollo.mjs"
54
62
  },
55
- "./vite": {
56
- "types": "./dist/vite.d.ts",
57
- "import": "./dist/vite.js"
63
+ "./nuxt": {
64
+ "types": "./dist/nuxt.d.mts",
65
+ "import": "./dist/nuxt.mjs"
58
66
  }
59
67
  },
60
- "module": "./dist/index.js",
61
- "types": "./dist/index.d.ts",
68
+ "module": "./dist/index.mjs",
69
+ "types": "./dist/index.d.mts",
70
+ "bin": {
71
+ "nitro-graphql": "./dist/cli/index.mjs"
72
+ },
62
73
  "files": [
63
74
  "dist"
64
75
  ],
65
76
  "peerDependencies": {
66
77
  "@apollo/server": "^5.0.0",
67
- "@apollo/utils.withrequired": "^3.0.0",
68
- "@as-integrations/h3": "^2.0.0",
69
78
  "graphql": "^16.11.0",
70
- "h3": "^2.0.1-rc.2",
71
79
  "nitro": "^3.0.1-alpha.0"
72
80
  },
73
81
  "peerDependenciesMeta": {
74
82
  "@apollo/server": {
75
83
  "optional": true
76
- },
77
- "@apollo/utils.withrequired": {
78
- "optional": true
79
- },
80
- "@as-integrations/h3": {
81
- "optional": true
82
84
  }
83
85
  },
84
86
  "dependencies": {
85
- "@apollo/subgraph": "^2.11.3",
87
+ "@apollo/subgraph": "^2.12.2",
88
+ "@bomb.sh/tab": "^0.0.11",
86
89
  "@graphql-codegen/core": "^5.0.0",
87
90
  "@graphql-codegen/import-types-preset": "^3.0.1",
88
- "@graphql-codegen/typescript": "^5.0.2",
91
+ "@graphql-codegen/typed-document-node": "^6.1.5",
92
+ "@graphql-codegen/typescript": "^5.0.7",
89
93
  "@graphql-codegen/typescript-generic-sdk": "^4.0.2",
90
- "@graphql-codegen/typescript-operations": "^5.0.2",
91
- "@graphql-codegen/typescript-resolvers": "^5.1.0",
92
- "@graphql-tools/graphql-file-loader": "^8.1.2",
93
- "@graphql-tools/load": "^8.1.2",
94
+ "@graphql-codegen/typescript-operations": "^5.0.7",
95
+ "@graphql-codegen/typescript-resolvers": "^5.1.5",
96
+ "@graphql-tools/graphql-file-loader": "^8.1.8",
97
+ "@graphql-tools/load": "^8.1.7",
94
98
  "@graphql-tools/load-files": "^7.0.1",
95
- "@graphql-tools/merge": "^9.1.1",
96
- "@graphql-tools/schema": "^10.0.25",
97
- "@graphql-tools/url-loader": "^9.0.0",
98
- "@graphql-tools/utils": "^10.9.1",
99
- "chokidar": "^4.0.3",
99
+ "@graphql-tools/merge": "^9.1.6",
100
+ "@graphql-tools/schema": "^10.0.30",
101
+ "@graphql-tools/url-loader": "^9.0.5",
102
+ "@graphql-tools/utils": "^10.11.0",
103
+ "chokidar": "^5.0.0",
104
+ "citty": "^0.1.6",
100
105
  "consola": "^3.4.2",
101
106
  "defu": "^6.1.4",
107
+ "giget": "^2.0.0",
102
108
  "graphql-config": "^5.1.5",
103
109
  "graphql-scalars": "^1.25.0",
104
- "knitwork": "^1.2.0",
110
+ "knitwork": "^1.3.0",
105
111
  "ohash": "^2.0.11",
106
- "oxc-parser": "^0.95.0",
112
+ "oxc-parser": "^0.106.0",
107
113
  "pathe": "^2.0.3",
108
114
  "tinyglobby": "^0.2.15"
109
115
  },
110
116
  "devDependencies": {
111
- "@antfu/eslint-config": "^6.0.0",
112
- "@nuxt/kit": "^4.1.3",
113
- "@nuxt/schema": "^4.1.3",
114
- "@types/node": "^24.7.2",
115
- "bumpp": "^10.3.1",
117
+ "@antfu/eslint-config": "^6.7.3",
118
+ "@nuxt/kit": "^4.2.2",
119
+ "@nuxt/schema": "^4.2.2",
120
+ "@types/node": "^25.0.3",
121
+ "@vitejs/devtools": "^0.0.0-alpha.16",
122
+ "@vitest/ui": "^4.0.16",
123
+ "bumpp": "^10.3.2",
116
124
  "changelogen": "^0.6.2",
117
- "crossws": "0.3.5",
118
- "eslint": "^9.37.0",
119
- "graphql": "16.11.0",
120
- "graphql-yoga": "^5.16.0",
121
- "h3": "^2.0.1-rc.2",
122
- "nitro": "^3.0.1-alpha.0",
123
- "tsdown": "^0.15.7",
124
- "typescript": "^5.9.3"
125
+ "crossws": "^0.4.1",
126
+ "eslint": "^9.39.2",
127
+ "graphql": "16.12.0",
128
+ "graphql-yoga": "5.16.2",
129
+ "nitro": "3.0.1-alpha.1",
130
+ "tsdown": "^0.18.4",
131
+ "typescript": "^5.9.3",
132
+ "vite": "8.0.0-beta.5",
133
+ "vitepress-plugin-llms": "^1.10.0",
134
+ "vitest": "^4.0.16"
125
135
  },
126
136
  "resolutions": {
127
137
  "nitro-graphql": "link:."
@@ -130,11 +140,20 @@
130
140
  "build": "tsdown",
131
141
  "dev": "tsdown --watch",
132
142
  "bumpp": "bumpp package.json",
133
- "release": "pnpm build && pnpm bumpp && pnpm publish --no-git-checks --access public",
143
+ "release": "pnpm build && pnpm bumpp",
134
144
  "playground:nitro": "cd playgrounds/nitro && pnpm install && pnpm dev",
135
145
  "playground:nuxt": "cd playgrounds/nuxt && pnpm install && pnpm dev",
136
146
  "playground:federation": "cd playgrounds/federation && pnpm install && pnpm dev",
147
+ "docs:dev": "cd .docs && pnpm install && pnpm update:metadata && pnpm dev",
148
+ "docs:build": "cd .docs && pnpm install && pnpm update:metadata && pnpm build",
149
+ "docs:preview": "cd .docs && pnpm preview",
150
+ "cli": "node ./dist/cli/index.mjs",
137
151
  "lint": "eslint .",
138
- "lint:fix": "eslint . --fix"
152
+ "lint:fix": "eslint . --fix",
153
+ "test": "vitest",
154
+ "test:ui": "vitest --ui",
155
+ "test:run": "vitest run",
156
+ "test:coverage": "vitest run --coverage",
157
+ "test:types": "tsc --noEmit"
139
158
  }
140
159
  }