nitro-graphql 2.0.0-beta.7 → 2.0.0-beta.70

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 (239) hide show
  1. package/README.md +31 -1196
  2. package/dist/cli/adapter.d.mts +13 -0
  3. package/dist/cli/adapter.mjs +69 -0
  4. package/dist/cli/commands/build.d.mts +21 -0
  5. package/dist/cli/commands/build.mjs +52 -0
  6. package/dist/cli/commands/dev.d.mts +40 -0
  7. package/dist/cli/commands/dev.mjs +76 -0
  8. package/dist/cli/commands/generate.d.mts +25 -0
  9. package/dist/cli/commands/generate.mjs +198 -0
  10. package/dist/cli/commands/index.d.mts +5 -0
  11. package/dist/cli/commands/index.mjs +6 -0
  12. package/dist/cli/commands/init.d.mts +45 -0
  13. package/dist/cli/commands/init.mjs +195 -0
  14. package/dist/cli/commands/validate.d.mts +9 -0
  15. package/dist/cli/commands/validate.mjs +67 -0
  16. package/dist/cli/completions.d.mts +6 -0
  17. package/dist/cli/completions.mjs +34 -0
  18. package/dist/cli/config.d.mts +18 -0
  19. package/dist/cli/config.mjs +20 -0
  20. package/dist/cli/index.d.mts +26 -0
  21. package/dist/cli/index.mjs +317 -0
  22. package/dist/cli/server/debug-handler.d.mts +9 -0
  23. package/dist/cli/server/debug-handler.mjs +71 -0
  24. package/dist/cli/server/dev-server.d.mts +29 -0
  25. package/dist/cli/server/dev-server.mjs +64 -0
  26. package/dist/cli/server/graphql-handler.d.mts +21 -0
  27. package/dist/cli/server/graphql-handler.mjs +45 -0
  28. package/dist/cli/server/health-handler.d.mts +12 -0
  29. package/dist/cli/server/health-handler.mjs +30 -0
  30. package/dist/cli/server/loader.d.mts +33 -0
  31. package/dist/cli/server/loader.mjs +146 -0
  32. package/dist/cli/server/sandbox-handler.d.mts +12 -0
  33. package/dist/cli/server/sandbox-handler.mjs +19 -0
  34. package/dist/cli/server/watcher.d.mts +20 -0
  35. package/dist/cli/server/watcher.mjs +66 -0
  36. package/dist/cli/server/ws-handler.d.mts +28 -0
  37. package/dist/cli/server/ws-handler.mjs +50 -0
  38. package/dist/config.d.mts +2 -0
  39. package/dist/config.mjs +3 -0
  40. package/dist/core/codegen/client.d.mts +42 -0
  41. package/dist/core/codegen/client.mjs +553 -0
  42. package/dist/core/codegen/document-loader.d.mts +9 -0
  43. package/dist/core/codegen/document-loader.mjs +18 -0
  44. package/dist/core/codegen/index.d.mts +8 -0
  45. package/dist/core/codegen/index.mjs +9 -0
  46. package/dist/core/codegen/plugin.d.mts +19 -0
  47. package/dist/core/codegen/plugin.mjs +30 -0
  48. package/dist/core/codegen/runtime.d.mts +19 -0
  49. package/dist/core/codegen/runtime.mjs +60 -0
  50. package/dist/core/codegen/schema-loader.d.mts +27 -0
  51. package/dist/core/codegen/schema-loader.mjs +128 -0
  52. package/dist/core/codegen/server.d.mts +27 -0
  53. package/dist/core/codegen/server.mjs +144 -0
  54. package/dist/core/codegen/validation.d.mts +17 -0
  55. package/dist/core/codegen/validation.mjs +35 -0
  56. package/dist/core/config.d.mts +45 -0
  57. package/dist/core/config.mjs +78 -0
  58. package/dist/core/constants.d.mts +188 -0
  59. package/dist/core/constants.mjs +210 -0
  60. package/dist/core/debug/index.d.mts +2 -0
  61. package/dist/core/debug/index.mjs +3 -0
  62. package/dist/core/debug/template.d.mts +52 -0
  63. package/dist/core/debug/template.mjs +383 -0
  64. package/dist/core/extend/index.d.mts +2 -0
  65. package/dist/core/extend/index.mjs +3 -0
  66. package/dist/core/extend/loader.d.mts +40 -0
  67. package/dist/core/extend/loader.mjs +198 -0
  68. package/dist/core/index.d.mts +37 -0
  69. package/dist/core/index.mjs +29 -0
  70. package/dist/core/manifest.d.mts +56 -0
  71. package/dist/core/manifest.mjs +102 -0
  72. package/dist/core/pubsub/index.d.mts +109 -0
  73. package/dist/core/pubsub/index.mjs +148 -0
  74. package/dist/core/scanning/ast-scanner.d.mts +27 -0
  75. package/dist/core/scanning/ast-scanner.mjs +116 -0
  76. package/dist/core/scanning/common.d.mts +25 -0
  77. package/dist/core/scanning/common.mjs +59 -0
  78. package/dist/core/scanning/directives.d.mts +13 -0
  79. package/dist/core/scanning/directives.mjs +29 -0
  80. package/dist/core/scanning/documents.d.mts +20 -0
  81. package/dist/core/scanning/documents.mjs +37 -0
  82. package/dist/core/scanning/index.d.mts +7 -0
  83. package/dist/core/scanning/index.mjs +8 -0
  84. package/dist/core/scanning/resolvers.d.mts +14 -0
  85. package/dist/core/scanning/resolvers.mjs +59 -0
  86. package/dist/core/scanning/schemas.d.mts +13 -0
  87. package/dist/core/scanning/schemas.mjs +52 -0
  88. package/dist/core/schema/builder.d.mts +59 -0
  89. package/dist/core/schema/builder.mjs +78 -0
  90. package/dist/core/schema/federation.d.mts +33 -0
  91. package/dist/core/schema/federation.mjs +40 -0
  92. package/dist/core/schema/index.d.mts +3 -0
  93. package/dist/core/schema/index.mjs +4 -0
  94. package/dist/core/server/index.d.mts +4 -0
  95. package/dist/core/server/index.mjs +4 -0
  96. package/dist/core/server/sandbox.d.mts +18 -0
  97. package/dist/core/server/sandbox.mjs +39 -0
  98. package/dist/core/server/types.d.mts +54 -0
  99. package/dist/core/server/yoga.d.mts +42 -0
  100. package/dist/core/server/yoga.mjs +89 -0
  101. package/dist/core/types/adapter.d.mts +57 -0
  102. package/dist/core/types/codegen.d.mts +136 -0
  103. package/dist/core/types/codegen.mjs +1 -0
  104. package/dist/core/types/config.d.mts +188 -0
  105. package/dist/core/types/config.mjs +1 -0
  106. package/dist/{utils/define.d.ts → core/types/define.d.mts} +2 -30
  107. package/dist/core/types/define.mjs +1 -0
  108. package/dist/core/types/index.d.mts +5 -0
  109. package/dist/core/types/index.mjs +1 -0
  110. package/dist/core/types/scanning.d.mts +64 -0
  111. package/dist/core/types/scanning.mjs +1 -0
  112. package/dist/{utils/directive-parser.d.ts → core/utils/directive-parser.d.mts} +18 -4
  113. package/dist/{utils/directive-parser.js → core/utils/directive-parser.mjs} +28 -34
  114. package/dist/core/utils/errors.d.mts +77 -0
  115. package/dist/core/utils/errors.mjs +93 -0
  116. package/dist/core/utils/file-io.d.mts +24 -0
  117. package/dist/core/utils/file-io.mjs +47 -0
  118. package/dist/core/utils/imports.d.mts +15 -0
  119. package/dist/core/utils/imports.mjs +25 -0
  120. package/dist/core/utils/index.d.mts +7 -0
  121. package/dist/core/utils/index.mjs +8 -0
  122. package/dist/core/utils/logger.d.mts +18 -0
  123. package/dist/core/utils/logger.mjs +38 -0
  124. package/dist/core/utils/ofetch-templates.d.mts +30 -0
  125. package/dist/core/utils/ofetch-templates.mjs +135 -0
  126. package/dist/core/utils/runtime.d.mts +74 -0
  127. package/dist/core/utils/runtime.mjs +111 -0
  128. package/dist/core/utils/subscribe-templates.d.mts +8 -0
  129. package/dist/core/utils/subscribe-templates.mjs +59 -0
  130. package/dist/core/validation/external-services.d.mts +11 -0
  131. package/dist/core/validation/external-services.mjs +33 -0
  132. package/dist/core/validation/index.d.mts +2 -0
  133. package/dist/core/validation/index.mjs +3 -0
  134. package/dist/core/watcher/index.d.mts +107 -0
  135. package/dist/core/watcher/index.mjs +141 -0
  136. package/dist/define.d.mts +294 -0
  137. package/dist/define.mjs +325 -0
  138. package/dist/index.d.mts +6 -0
  139. package/dist/index.mjs +6 -0
  140. package/dist/nitro/adapter.d.mts +29 -0
  141. package/dist/nitro/adapter.mjs +93 -0
  142. package/dist/{utils/apollo.d.ts → nitro/apollo.d.mts} +3 -3
  143. package/dist/nitro/apollo.mjs +59 -0
  144. package/dist/nitro/codegen.d.mts +18 -0
  145. package/dist/nitro/codegen.mjs +173 -0
  146. package/dist/nitro/config.d.mts +50 -0
  147. package/dist/nitro/config.mjs +57 -0
  148. package/dist/nitro/index.d.mts +45 -0
  149. package/dist/nitro/index.mjs +65 -0
  150. package/dist/{utils/path-resolver.d.ts → nitro/paths.d.mts} +8 -25
  151. package/dist/{utils/path-resolver.js → nitro/paths.mjs} +14 -49
  152. package/dist/nitro/rollup.d.mts +6 -0
  153. package/dist/nitro/rollup.mjs +53 -0
  154. package/dist/nitro/routes/apollo-sandbox-script.d.mts +6 -0
  155. package/dist/nitro/routes/apollo-sandbox-script.mjs +14 -0
  156. package/dist/nitro/routes/apollo-server-ws.d.mts +15 -0
  157. package/dist/nitro/routes/apollo-server-ws.mjs +53 -0
  158. package/dist/nitro/routes/apollo-server.d.mts +6 -0
  159. package/dist/nitro/routes/apollo-server.mjs +71 -0
  160. package/dist/{routes/debug.d.ts → nitro/routes/debug.d.mts} +12 -19
  161. package/dist/nitro/routes/debug.mjs +102 -0
  162. package/dist/nitro/routes/graphql-yoga-ws.d.mts +12 -0
  163. package/dist/nitro/routes/graphql-yoga-ws.mjs +53 -0
  164. package/dist/nitro/routes/graphql-yoga.d.mts +12 -0
  165. package/dist/nitro/routes/graphql-yoga.mjs +41 -0
  166. package/dist/nitro/routes/health.d.mts +10 -0
  167. package/dist/{routes/health.js → nitro/routes/health.mjs} +4 -3
  168. package/dist/nitro/setup/extend-loader.d.mts +16 -0
  169. package/dist/nitro/setup/extend-loader.mjs +82 -0
  170. package/dist/nitro/setup/file-watcher.d.mts +18 -0
  171. package/dist/nitro/setup/file-watcher.mjs +63 -0
  172. package/dist/nitro/setup/logging.d.mts +16 -0
  173. package/dist/nitro/setup/logging.mjs +66 -0
  174. package/dist/nitro/setup/rollup-integration.d.mts +24 -0
  175. package/dist/nitro/setup/rollup-integration.mjs +63 -0
  176. package/dist/nitro/setup/routes.d.mts +13 -0
  177. package/dist/nitro/setup/routes.mjs +71 -0
  178. package/dist/nitro/setup/scanner.d.mts +59 -0
  179. package/dist/nitro/setup/scanner.mjs +120 -0
  180. package/dist/nitro/setup/ts-config.d.mts +10 -0
  181. package/dist/nitro/setup/ts-config.mjs +69 -0
  182. package/dist/nitro/setup.d.mts +11 -0
  183. package/dist/nitro/setup.mjs +191 -0
  184. package/dist/nitro/types.d.mts +549 -0
  185. package/dist/nitro/types.mjs +1 -0
  186. package/dist/nitro/virtual/generators.d.mts +38 -0
  187. package/dist/nitro/virtual/generators.mjs +192 -0
  188. package/dist/nitro/virtual/stubs.d.mts +21 -0
  189. package/dist/nitro/virtual/stubs.mjs +32 -0
  190. package/dist/{ecosystem/nuxt.d.ts → nuxt.d.mts} +1 -1
  191. package/dist/nuxt.mjs +112 -0
  192. package/dist/{graphql/server.d.ts → stubs/index.d.mts} +5 -1
  193. package/dist/stubs/index.mjs +1 -0
  194. package/dist/subscribe/index.d.mts +78 -0
  195. package/dist/subscribe/index.mjs +206 -0
  196. package/native/index.d.ts +20 -0
  197. package/native/index.js +585 -0
  198. package/package.json +201 -111
  199. package/dist/ecosystem/nuxt.js +0 -67
  200. package/dist/graphql/index.d.ts +0 -5
  201. package/dist/index.d.ts +0 -8
  202. package/dist/index.js +0 -318
  203. package/dist/rollup.js +0 -277
  204. package/dist/routes/apollo-server.d.ts +0 -6
  205. package/dist/routes/apollo-server.js +0 -89
  206. package/dist/routes/debug.js +0 -449
  207. package/dist/routes/graphql-yoga.d.ts +0 -6
  208. package/dist/routes/graphql-yoga.js +0 -91
  209. package/dist/routes/health.d.ts +0 -10
  210. package/dist/types/index.d.ts +0 -246
  211. package/dist/types/standard-schema.d.ts +0 -59
  212. package/dist/utils/apollo.js +0 -61
  213. package/dist/utils/client-codegen.d.ts +0 -38
  214. package/dist/utils/client-codegen.js +0 -290
  215. package/dist/utils/define.js +0 -57
  216. package/dist/utils/file-generator.d.ts +0 -37
  217. package/dist/utils/file-generator.js +0 -72
  218. package/dist/utils/index.d.ts +0 -39
  219. package/dist/utils/index.js +0 -278
  220. package/dist/utils/server-codegen.d.ts +0 -7
  221. package/dist/utils/server-codegen.js +0 -136
  222. package/dist/utils/type-generation.d.ts +0 -7
  223. package/dist/utils/type-generation.js +0 -360
  224. package/dist/virtual/debug-info.d.ts +0 -9
  225. package/dist/virtual/debug-info.js +0 -26
  226. package/dist/virtual/graphql-config.d.ts +0 -9
  227. package/dist/virtual/graphql-config.js +0 -10
  228. package/dist/virtual/module-config.d.ts +0 -9
  229. package/dist/virtual/module-config.js +0 -10
  230. package/dist/virtual/server-directives.d.ts +0 -11
  231. package/dist/virtual/server-directives.js +0 -10
  232. package/dist/virtual/server-resolvers.d.ts +0 -11
  233. package/dist/virtual/server-resolvers.js +0 -10
  234. package/dist/virtual/server-schemas.d.ts +0 -11
  235. package/dist/virtual/server-schemas.js +0 -10
  236. package/dist/vite.d.ts +0 -25
  237. package/dist/vite.js +0 -40
  238. /package/dist/{graphql/index.js → core/server/types.mjs} +0 -0
  239. /package/dist/{graphql/server.js → core/types/adapter.mjs} +0 -0
package/dist/index.js DELETED
@@ -1,318 +0,0 @@
1
- import { generateDirectiveSchemas } from "./utils/directive-parser.js";
2
- import { generateLayerIgnorePatterns, getLayerAppDirectories, getLayerServerDirectories, relativeWithDot, scanDirectives, scanDocs, scanResolvers, scanSchemas, validateExternalServices } from "./utils/index.js";
3
- import { writeFileIfNotExists } from "./utils/file-generator.js";
4
- import { getDefaultPaths, getScaffoldConfig, resolveFilePath, shouldGenerateScaffold } from "./utils/path-resolver.js";
5
- import { clientTypeGeneration, serverTypeGeneration } from "./utils/type-generation.js";
6
- import { rollupConfig } from "./rollup.js";
7
- import { existsSync, mkdirSync } from "node:fs";
8
- import { fileURLToPath } from "node:url";
9
- import { watch } from "chokidar";
10
- import consola from "consola";
11
- import defu from "defu";
12
- import { dirname, join, relative, resolve } from "pathe";
13
-
14
- //#region src/index.ts
15
- var src_default = defineNitroModule({
16
- name: "nitro-graphql",
17
- async setup(nitro) {
18
- if (!nitro.options.graphql?.framework) consola.warn("No GraphQL framework specified. Please set graphql.framework to \"graphql-yoga\" or \"apollo-server\".");
19
- if (nitro.options.graphql?.externalServices?.length) {
20
- const validationErrors = validateExternalServices(nitro.options.graphql.externalServices);
21
- if (validationErrors.length > 0) {
22
- consola.error("External services configuration errors:");
23
- for (const error of validationErrors) consola.error(` - ${error}`);
24
- throw new Error("Invalid external services configuration");
25
- }
26
- consola.info(`Configured ${nitro.options.graphql.externalServices.length} external GraphQL services`);
27
- }
28
- nitro.graphql ||= {
29
- buildDir: "",
30
- watchDirs: [],
31
- clientDir: "",
32
- serverDir: resolve(nitro.options.rootDir, "server", "graphql"),
33
- dir: {
34
- build: relative(nitro.options.rootDir, nitro.options.buildDir),
35
- client: "graphql",
36
- server: "server"
37
- }
38
- };
39
- nitro.hooks.hook("rollup:before", (_, rollupConfig$1) => {
40
- rollupConfig$1.external = rollupConfig$1.external || [];
41
- const codegenExternals = ["oxc-parser", "@oxc-parser"];
42
- if (Array.isArray(rollupConfig$1.external)) rollupConfig$1.external.push(...codegenExternals);
43
- else if (typeof rollupConfig$1.external === "function") {
44
- const originalExternal = rollupConfig$1.external;
45
- rollupConfig$1.external = (id, parent, isResolved) => {
46
- if (codegenExternals.some((external) => id.includes(external))) return true;
47
- return originalExternal(id, parent, isResolved);
48
- };
49
- }
50
- });
51
- nitro.options.runtimeConfig.graphql = defu(nitro.options.runtimeConfig.graphql || {}, {
52
- endpoint: {
53
- graphql: "/api/graphql",
54
- healthCheck: "/api/graphql/health"
55
- },
56
- playground: true
57
- });
58
- if (nitro.options.graphql?.federation?.enabled) consola.info(`Apollo Federation enabled for service: ${nitro.options.graphql.federation.serviceName || "unnamed"}`);
59
- const graphqlBuildDir = resolve(nitro.options.buildDir, "graphql");
60
- nitro.graphql.buildDir = graphqlBuildDir;
61
- const watchDirs = [];
62
- switch (nitro.options.framework.name) {
63
- case "nuxt": {
64
- if (!nitro.graphql.clientDir) {
65
- nitro.graphql.clientDir = resolve(nitro.options.rootDir, "app", "graphql");
66
- nitro.graphql.dir.client = "app/graphql";
67
- }
68
- if (!nitro.options.graphql?.serverDir) nitro.graphql.serverDir = resolve(nitro.options.rootDir, "server", "graphql");
69
- watchDirs.push(nitro.graphql.clientDir);
70
- const layerServerDirs = getLayerServerDirectories(nitro);
71
- const layerAppDirs = getLayerAppDirectories(nitro);
72
- for (const layerServerDir of layerServerDirs) watchDirs.push(join(layerServerDir, "graphql"));
73
- for (const layerAppDir of layerAppDirs) watchDirs.push(join(layerAppDir, "graphql"));
74
- break;
75
- }
76
- case "nitro":
77
- if (!nitro.options.graphql?.serverDir) nitro.graphql.serverDir = resolve(nitro.options.rootDir, "server", "graphql");
78
- nitro.graphql.clientDir = resolve(nitro.options.rootDir, "graphql");
79
- nitro.graphql.dir.client = "graphql";
80
- watchDirs.push(nitro.graphql.clientDir);
81
- watchDirs.push(nitro.graphql.serverDir);
82
- break;
83
- default:
84
- }
85
- if (nitro.options.graphql?.externalServices?.length) {
86
- for (const service of nitro.options.graphql.externalServices) if (service.documents?.length) for (const pattern of service.documents) {
87
- if (!pattern) continue;
88
- const baseDir = pattern.split("**")[0]?.replace(/\/$/, "") || ".";
89
- const resolvedDir = resolve(nitro.options.rootDir, baseDir);
90
- if (!watchDirs.includes(resolvedDir)) watchDirs.push(resolvedDir);
91
- }
92
- }
93
- const watcher = watch(watchDirs, {
94
- persistent: true,
95
- ignoreInitial: true,
96
- ignored: [...nitro.options.ignore, ...generateLayerIgnorePatterns(nitro)]
97
- }).on("all", async (_, path) => {
98
- if (path.endsWith(".graphql") || path.endsWith(".gql")) if (path.includes(nitro.graphql.serverDir) || path.includes("server/graphql") || path.includes("server\\graphql")) {
99
- await serverTypeGeneration(nitro);
100
- await clientTypeGeneration(nitro);
101
- await nitro.hooks.callHook("dev:reload");
102
- } else await clientTypeGeneration(nitro);
103
- });
104
- nitro.hooks.hook("close", () => {
105
- watcher.close();
106
- });
107
- const tsconfigDir = dirname(resolve(nitro.options.buildDir, nitro.options.typescript.tsconfigPath));
108
- const typesDir = resolve(nitro.options.buildDir, "types");
109
- nitro.scanSchemas = await scanSchemas(nitro);
110
- nitro.scanDocuments = await scanDocs(nitro);
111
- nitro.scanResolvers = await scanResolvers(nitro);
112
- const directives = await scanDirectives(nitro);
113
- nitro.scanDirectives = directives;
114
- await generateDirectiveSchemas(nitro, directives);
115
- nitro.hooks.hook("dev:start", async () => {
116
- const schemas = await scanSchemas(nitro);
117
- nitro.scanSchemas = schemas;
118
- const resolvers = await scanResolvers(nitro);
119
- nitro.scanResolvers = resolvers;
120
- const directives$1 = await scanDirectives(nitro);
121
- nitro.scanDirectives = directives$1;
122
- await generateDirectiveSchemas(nitro, directives$1);
123
- const docs = await scanDocs(nitro);
124
- nitro.scanDocuments = docs;
125
- if (nitro.options.dev) {
126
- consola.box({
127
- title: "Nitro GraphQL",
128
- message: [
129
- `Framework: ${nitro.options.graphql?.framework || "Not configured"}`,
130
- `Schemas: ${schemas.length}`,
131
- `Resolvers: ${resolvers.length}`,
132
- `Directives: ${directives$1.length}`,
133
- `Documents: ${docs.length}`,
134
- "",
135
- "Debug Dashboard: /_nitro/graphql/debug"
136
- ].join("\n"),
137
- style: {
138
- borderColor: "cyan",
139
- borderStyle: "rounded"
140
- }
141
- });
142
- if (resolvers.length > 0) {
143
- const totalExports = resolvers.reduce((sum, r) => sum + r.imports.length, 0);
144
- const typeCount = {
145
- query: 0,
146
- mutation: 0,
147
- resolver: 0,
148
- type: 0,
149
- subscription: 0,
150
- directive: 0
151
- };
152
- for (const resolver of resolvers) for (const imp of resolver.imports) if (imp.type in typeCount) typeCount[imp.type]++;
153
- const breakdown = [];
154
- if (typeCount.query > 0) breakdown.push(`${typeCount.query} query`);
155
- if (typeCount.mutation > 0) breakdown.push(`${typeCount.mutation} mutation`);
156
- if (typeCount.resolver > 0) breakdown.push(`${typeCount.resolver} resolver`);
157
- if (typeCount.type > 0) breakdown.push(`${typeCount.type} type`);
158
- if (typeCount.subscription > 0) breakdown.push(`${typeCount.subscription} subscription`);
159
- if (typeCount.directive > 0) breakdown.push(`${typeCount.directive} directive`);
160
- if (breakdown.length > 0) consola.success(`[nitro-graphql] ${totalExports} resolver export(s): ${breakdown.join(", ")}`);
161
- } else consola.warn("[nitro-graphql] No resolvers found. Check /_nitro/graphql/debug for details.");
162
- }
163
- });
164
- await rollupConfig(nitro);
165
- await serverTypeGeneration(nitro);
166
- await clientTypeGeneration(nitro);
167
- nitro.hooks.hook("close", async () => {
168
- await serverTypeGeneration(nitro);
169
- await clientTypeGeneration(nitro);
170
- });
171
- const runtime = fileURLToPath(new URL("routes", import.meta.url));
172
- const methods = [
173
- "GET",
174
- "POST",
175
- "OPTIONS"
176
- ];
177
- if (nitro.options.graphql?.framework === "graphql-yoga") for (const method of methods) nitro.options.handlers.push({
178
- route: nitro.options.runtimeConfig.graphql?.endpoint?.graphql || "/api/graphql",
179
- handler: join(runtime, "graphql-yoga"),
180
- method
181
- });
182
- if (nitro.options.graphql?.framework === "apollo-server") for (const method of methods) nitro.options.handlers.push({
183
- route: nitro.options.runtimeConfig.graphql?.endpoint?.graphql || "/api/graphql",
184
- handler: join(runtime, "apollo-server"),
185
- method
186
- });
187
- nitro.options.handlers.push({
188
- route: nitro.options.runtimeConfig.graphql?.endpoint?.healthCheck || "/api/graphql/health",
189
- handler: join(runtime, "health"),
190
- method: "GET"
191
- });
192
- if (nitro.options.dev) {
193
- nitro.options.handlers.push({
194
- route: "/_nitro/graphql/debug",
195
- handler: join(runtime, "debug"),
196
- method: "get"
197
- });
198
- consola.info("[nitro-graphql] Debug dashboard available at: /_nitro/graphql/debug");
199
- }
200
- if (nitro.options.imports) {
201
- nitro.options.imports.presets ??= [];
202
- nitro.options.imports.presets.push({
203
- from: fileURLToPath(new URL("utils/define", import.meta.url)),
204
- imports: [
205
- "defineResolver",
206
- "defineMutation",
207
- "defineQuery",
208
- "defineSubscription",
209
- "defineType",
210
- "defineGraphQLConfig",
211
- "defineSchema",
212
- "defineDirective"
213
- ]
214
- });
215
- }
216
- nitro.hooks.hook("rollup:before", (_, rollupConfig$1) => {
217
- const manualChunks = rollupConfig$1.output?.manualChunks;
218
- const chunkFiles = rollupConfig$1.output?.chunkFileNames;
219
- if (!rollupConfig$1.output.inlineDynamicImports) rollupConfig$1.output.manualChunks = (id, meta) => {
220
- if (id.endsWith(".graphql") || id.endsWith(".gql")) return "schemas";
221
- if (id.endsWith(".resolver.ts")) return "resolvers";
222
- if (typeof manualChunks === "function") return manualChunks(id, meta);
223
- };
224
- rollupConfig$1.output.chunkFileNames = (chunkInfo) => {
225
- if (chunkInfo.moduleIds && chunkInfo.moduleIds.some((id) => id.endsWith(".graphql") || id.endsWith(".resolver.ts") || id.endsWith(".gql"))) return `chunks/graphql/[name].mjs`;
226
- if (typeof chunkFiles === "function") return chunkFiles(chunkInfo);
227
- return `chunks/_/[name].mjs`;
228
- };
229
- });
230
- nitro.options.typescript.strict = true;
231
- nitro.hooks.hook("types:extend", (types) => {
232
- types.tsConfig ||= {};
233
- types.tsConfig.compilerOptions ??= {};
234
- types.tsConfig.compilerOptions.paths ??= {};
235
- types.tsConfig.compilerOptions.paths["#graphql/server"] = [relativeWithDot(tsconfigDir, join(typesDir, "nitro-graphql-server.d.ts"))];
236
- types.tsConfig.compilerOptions.paths["#graphql/client"] = [relativeWithDot(tsconfigDir, join(typesDir, "nitro-graphql-client.d.ts"))];
237
- types.tsConfig.compilerOptions.paths["#graphql/schema"] = [relativeWithDot(tsconfigDir, join(nitro.graphql.serverDir, "schema.ts"))];
238
- if (nitro.options.graphql?.externalServices?.length) for (const service of nitro.options.graphql.externalServices) types.tsConfig.compilerOptions.paths[`#graphql/client/${service.name}`] = [relativeWithDot(tsconfigDir, join(typesDir, `nitro-graphql-client-${service.name}.d.ts`))];
239
- types.tsConfig.include = types.tsConfig.include || [];
240
- types.tsConfig.include.push(relativeWithDot(tsconfigDir, join(typesDir, "nitro-graphql-server.d.ts")), relativeWithDot(tsconfigDir, join(typesDir, "nitro-graphql-client.d.ts")), relativeWithDot(tsconfigDir, join(typesDir, "graphql.d.ts")));
241
- if (nitro.options.graphql?.externalServices?.length) for (const service of nitro.options.graphql.externalServices) types.tsConfig.include.push(relativeWithDot(tsconfigDir, join(typesDir, `nitro-graphql-client-${service.name}.d.ts`)));
242
- });
243
- if (nitro.options.framework?.name === "nuxt" && nitro.options.graphql?.externalServices?.length) nitro.hooks.hook("build:before", () => {
244
- const nuxtOptions = nitro._nuxt?.options;
245
- if (nuxtOptions) nuxtOptions.nitroGraphqlExternalServices = nitro.options.graphql?.externalServices || [];
246
- });
247
- if (shouldGenerateScaffold(nitro)) {
248
- const placeholders = getDefaultPaths(nitro);
249
- const scaffoldConfig = getScaffoldConfig(nitro);
250
- const graphqlConfigPath = resolveFilePath(scaffoldConfig.graphqlConfig, scaffoldConfig.enabled, true, "graphql.config.ts", placeholders);
251
- if (graphqlConfigPath) writeFileIfNotExists(graphqlConfigPath, `
252
- import type { IGraphQLConfig } from 'graphql-config'
253
-
254
- export default <IGraphQLConfig> {
255
- projects: {
256
- default: {
257
- schema: [
258
- '${relativeWithDot(nitro.options.rootDir, resolve(nitro.graphql.buildDir, "schema.graphql"))}',
259
- ],
260
- documents: [
261
- '${relativeWithDot(nitro.options.rootDir, resolve(nitro.graphql.clientDir, "**/*.{graphql,js,ts,jsx,tsx}"))}',
262
- ],
263
- },
264
- },
265
- }`, "graphql.config.ts");
266
- const serverSchemaPath = resolveFilePath(scaffoldConfig.serverSchema, scaffoldConfig.enabled, true, "{serverGraphql}/schema.ts", placeholders);
267
- const serverConfigPath = resolveFilePath(scaffoldConfig.serverConfig, scaffoldConfig.enabled, true, "{serverGraphql}/config.ts", placeholders);
268
- const serverContextPath = resolveFilePath(scaffoldConfig.serverContext, scaffoldConfig.enabled, true, "{serverGraphql}/context.ts", placeholders);
269
- if (serverSchemaPath || serverConfigPath || serverContextPath) {
270
- if (!existsSync(nitro.graphql.serverDir)) mkdirSync(nitro.graphql.serverDir, { recursive: true });
271
- }
272
- if (serverSchemaPath) writeFileIfNotExists(serverSchemaPath, `export default defineSchema({
273
-
274
- })
275
- `, "server schema.ts");
276
- if (serverConfigPath) writeFileIfNotExists(serverConfigPath, `// Example GraphQL config file please change it to your needs
277
- // import * as tables from '../drizzle/schema/index'
278
- // import { useDatabase } from '../utils/useDb'
279
- import { defineGraphQLConfig } from 'nitro-graphql/utils/define'
280
-
281
- export default defineGraphQLConfig({
282
- // graphql-yoga example config
283
- // context: () => {
284
- // return {
285
- // context: {
286
- // useDatabase,
287
- // tables,
288
- // },
289
- // }
290
- // },
291
- })
292
- `, "server config.ts");
293
- if (serverContextPath) writeFileIfNotExists(serverContextPath, `// Example context definition - please change it to your needs
294
- // import type { Database } from '../utils/useDb'
295
-
296
- declare module 'h3' {
297
- interface H3EventContext {
298
- // Add your custom context properties here
299
- // useDatabase: () => Database
300
- // tables: typeof import('../drizzle/schema')
301
- // auth?: {
302
- // user?: {
303
- // id: string
304
- // role: 'admin' | 'user'
305
- // }
306
- // }
307
- }
308
- }`, "server context.ts");
309
- if (existsSync(join(nitro.graphql.serverDir, "context.d.ts"))) {
310
- consola.warn("nitro-graphql: Found context.d.ts file. Please rename it to context.ts for the new structure.");
311
- consola.info("The context file should now be context.ts instead of context.d.ts");
312
- }
313
- } else consola.info("[nitro-graphql] Scaffold file generation is disabled (library mode)");
314
- }
315
- });
316
-
317
- //#endregion
318
- export { src_default as default };
package/dist/rollup.js DELETED
@@ -1,277 +0,0 @@
1
- import { getImportId, scanGraphql } from "./utils/index.js";
2
- import { clientTypeGeneration, serverTypeGeneration } from "./utils/type-generation.js";
3
- import { fileURLToPath } from "node:url";
4
- import { resolve } from "pathe";
5
- import { readFile } from "node:fs/promises";
6
- import { parse } from "graphql";
7
- import { genImport } from "knitwork";
8
-
9
- //#region src/rollup.ts
10
- async function rollupConfig(app) {
11
- virtualSchemas(app);
12
- virtualResolvers(app);
13
- virtualDirectives(app);
14
- getGraphQLConfig(app);
15
- virtualModuleConfig(app);
16
- virtualDebugInfo(app);
17
- app.hooks.hook("rollup:before", (nitro, rollupConfig$1) => {
18
- rollupConfig$1.plugins = rollupConfig$1.plugins || [];
19
- const { include = /\.(?:graphql|gql)$/i, exclude, validate = false } = app.options.graphql?.loader || {};
20
- if (Array.isArray(rollupConfig$1.plugins)) {
21
- rollupConfig$1.plugins.push({
22
- name: "nitro-graphql:virtual",
23
- resolveId: {
24
- order: "pre",
25
- async handler(id, parent, options) {
26
- if (id.startsWith("#nitro-graphql/")) return `\0virtual:${id}`;
27
- if (parent?.startsWith("\0virtual:#nitro-graphql")) {
28
- const runtimeDir = fileURLToPath(new URL("routes", import.meta.url));
29
- const internalRes = await this.resolve(id, runtimeDir, {
30
- skipSelf: true,
31
- ...options
32
- });
33
- if (internalRes) return internalRes;
34
- }
35
- }
36
- },
37
- load: {
38
- order: "pre",
39
- handler(id) {
40
- if (id.startsWith("\0virtual:#nitro-graphql/")) {
41
- const moduleName = id.slice(9);
42
- const generator = app.options.virtual?.[moduleName];
43
- if (typeof generator === "function") try {
44
- return generator();
45
- } catch (error) {
46
- const message = error instanceof Error ? error.message : String(error);
47
- this.error(`Failed to generate virtual module ${moduleName}: ${message}`);
48
- }
49
- else this.error(`No generator function found for virtual module ${moduleName}`);
50
- }
51
- }
52
- }
53
- });
54
- rollupConfig$1.plugins.push({
55
- name: "nitro-graphql",
56
- resolveId: {
57
- order: "pre",
58
- handler(id) {
59
- if (/\.(?:graphql|gql)$/i.test(id)) return null;
60
- }
61
- },
62
- load: {
63
- order: "pre",
64
- async handler(id) {
65
- if (exclude?.test?.(id)) return null;
66
- if (!include.test(id)) return null;
67
- try {
68
- const content = await readFile(id, "utf-8");
69
- if (validate) parse(content);
70
- return `export default ${JSON.stringify(content)}`;
71
- } catch (error) {
72
- if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") return null;
73
- const message = error instanceof Error ? error.message : String(error);
74
- this.error(`Failed to read GraphQL file ${id}: ${message}`);
75
- }
76
- }
77
- }
78
- });
79
- if (app.options.dev) rollupConfig$1.plugins.push({
80
- name: "nitro-graphql-watcher",
81
- buildStart: {
82
- order: "pre",
83
- async handler() {
84
- const graphqlFiles = await scanGraphql(nitro);
85
- for (const file of graphqlFiles) this.addWatchFile(file);
86
- }
87
- }
88
- });
89
- }
90
- });
91
- app.hooks.hook("dev:reload", async () => {
92
- await serverTypeGeneration(app);
93
- await clientTypeGeneration(app);
94
- });
95
- }
96
- function virtualSchemas(app) {
97
- const getSchemas = () => [...app.scanSchemas, ...app.options.graphql?.typedefs ?? []];
98
- app.options.virtual ??= {};
99
- app.options.virtual["#nitro-graphql/server-schemas"] = () => {
100
- try {
101
- const imports = getSchemas();
102
- if (imports.length === 0) {
103
- if (app.options.dev) app.logger.warn("[nitro-graphql] No schemas found. Virtual module will export empty array.");
104
- return "export const schemas = []";
105
- }
106
- const importStatements = imports.map((handler) => `import ${getImportId(handler)} from '${handler}';`);
107
- const schemaArray = imports.map((h) => `{ def: ${getImportId(h)} }`);
108
- return `
109
- ${importStatements.join("\n")}
110
-
111
- export const schemas = [
112
- ${schemaArray.join(",\n")}
113
- ];
114
- `;
115
- } catch (error) {
116
- app.logger.error("[nitro-graphql] Failed to generate virtual schema module:", error);
117
- return "export const schemas = []";
118
- }
119
- };
120
- }
121
- function virtualResolvers(app) {
122
- const getResolvers = () => [...app.scanResolvers];
123
- app.options.virtual ??= {};
124
- app.options.virtual["#nitro-graphql/server-resolvers"] = () => {
125
- try {
126
- const imports = getResolvers();
127
- if (imports.length === 0) {
128
- if (app.options.dev) app.logger.warn("[nitro-graphql] No resolvers found. Virtual module will export empty array.");
129
- return "export const resolvers = []";
130
- }
131
- const importsContent = [];
132
- const invalidImports = [];
133
- for (const { specifier, imports: importList, options } of imports) try {
134
- if (!importList || importList.length === 0) {
135
- invalidImports.push(`${specifier}: No exports found`);
136
- continue;
137
- }
138
- const importCode = genImport(specifier, importList, options);
139
- importsContent.push(importCode);
140
- } catch (error) {
141
- const message = error instanceof Error ? error.message : String(error);
142
- invalidImports.push(`${specifier}: ${message}`);
143
- if (app.options.dev) app.logger.error(`[nitro-graphql] Failed to generate import for ${specifier}:`, error);
144
- }
145
- if (invalidImports.length > 0 && app.options.dev) {
146
- app.logger.warn("[nitro-graphql] Some resolver imports could not be generated:");
147
- for (const msg of invalidImports) app.logger.warn(` - ${msg}`);
148
- }
149
- const data = imports.map(({ imports: importList }) => importList.map((i) => `{ resolver: ${i.as} }`).join(",\n")).filter(Boolean).join(",\n");
150
- return [
151
- ...importsContent,
152
- "",
153
- "export const resolvers = [",
154
- data,
155
- "]",
156
- ""
157
- ].join("\n");
158
- } catch (error) {
159
- app.logger.error("[nitro-graphql] Failed to generate virtual resolver module:", error);
160
- return "export const resolvers = []";
161
- }
162
- };
163
- }
164
- function virtualDirectives(app) {
165
- const getDirectives = () => app.scanDirectives || [];
166
- app.options.virtual ??= {};
167
- app.options.virtual["#nitro-graphql/server-directives"] = () => {
168
- try {
169
- const imports = getDirectives();
170
- if (imports.length === 0) return "export const directives = []";
171
- const importsContent = [];
172
- const invalidImports = [];
173
- for (const { specifier, imports: importList, options } of imports) try {
174
- if (!importList || importList.length === 0) {
175
- invalidImports.push(`${specifier}: No exports found`);
176
- continue;
177
- }
178
- const importCode = genImport(specifier, importList, options);
179
- importsContent.push(importCode);
180
- } catch (error) {
181
- const message = error instanceof Error ? error.message : String(error);
182
- invalidImports.push(`${specifier}: ${message}`);
183
- if (app.options.dev) app.logger.error(`[nitro-graphql] Failed to generate import for directive ${specifier}:`, error);
184
- }
185
- if (invalidImports.length > 0 && app.options.dev) {
186
- app.logger.warn("[nitro-graphql] Some directive imports could not be generated:");
187
- for (const msg of invalidImports) app.logger.warn(` - ${msg}`);
188
- }
189
- const data = imports.map(({ imports: importList }) => importList.map((i) => `{ directive: ${i.as} }`).join(",\n")).filter(Boolean).join(",\n");
190
- return [
191
- ...importsContent,
192
- "",
193
- "export const directives = [",
194
- data,
195
- "]",
196
- ""
197
- ].join("\n");
198
- } catch (error) {
199
- app.logger.error("[nitro-graphql] Failed to generate virtual directive module:", error);
200
- return "export const directives = []";
201
- }
202
- };
203
- }
204
- function getGraphQLConfig(app) {
205
- const configPath = resolve(app.graphql.serverDir, "config.ts");
206
- app.options.virtual ??= {};
207
- app.options.virtual["#nitro-graphql/graphql-config"] = () => {
208
- return `import config from '${configPath}'
209
- const importedConfig = config
210
- export { importedConfig }
211
- `;
212
- };
213
- }
214
- function virtualModuleConfig(app) {
215
- app.options.virtual ??= {};
216
- app.options.virtual["#nitro-graphql/module-config"] = () => {
217
- const moduleConfig = app.options.graphql || {};
218
- return `export const moduleConfig = ${JSON.stringify(moduleConfig, null, 2)};`;
219
- };
220
- }
221
- function virtualDebugInfo(app) {
222
- app.options.virtual ??= {};
223
- app.options.virtual["#nitro-graphql/debug-info"] = () => {
224
- const virtualModuleCodes = {};
225
- try {
226
- const schemasGenerator = app.options.virtual["#nitro-graphql/server-schemas"];
227
- if (schemasGenerator && typeof schemasGenerator === "function") virtualModuleCodes["server-schemas"] = schemasGenerator();
228
- } catch (error) {
229
- virtualModuleCodes["server-schemas"] = `// Error generating: ${error instanceof Error ? error.message : String(error)}`;
230
- }
231
- try {
232
- const resolversGenerator = app.options.virtual["#nitro-graphql/server-resolvers"];
233
- if (resolversGenerator && typeof resolversGenerator === "function") virtualModuleCodes["server-resolvers"] = resolversGenerator();
234
- } catch (error) {
235
- virtualModuleCodes["server-resolvers"] = `// Error generating: ${error instanceof Error ? error.message : String(error)}`;
236
- }
237
- try {
238
- const directivesGenerator = app.options.virtual["#nitro-graphql/server-directives"];
239
- if (directivesGenerator && typeof directivesGenerator === "function") virtualModuleCodes["server-directives"] = directivesGenerator();
240
- } catch (error) {
241
- virtualModuleCodes["server-directives"] = `// Error generating: ${error instanceof Error ? error.message : String(error)}`;
242
- }
243
- try {
244
- const moduleConfigGenerator = app.options.virtual["#nitro-graphql/module-config"];
245
- if (moduleConfigGenerator && typeof moduleConfigGenerator === "function") virtualModuleCodes["module-config"] = moduleConfigGenerator();
246
- } catch (error) {
247
- virtualModuleCodes["module-config"] = `// Error generating: ${error instanceof Error ? error.message : String(error)}`;
248
- }
249
- try {
250
- const graphqlConfigGenerator = app.options.virtual["#nitro-graphql/graphql-config"];
251
- if (graphqlConfigGenerator && typeof graphqlConfigGenerator === "function") virtualModuleCodes["graphql-config"] = graphqlConfigGenerator();
252
- } catch (error) {
253
- virtualModuleCodes["graphql-config"] = `// Error generating: ${error instanceof Error ? error.message : String(error)}`;
254
- }
255
- const debugInfo = {
256
- isDev: app.options.dev,
257
- framework: app.options.framework.name,
258
- graphqlFramework: app.options.graphql?.framework,
259
- federation: app.options.graphql?.federation,
260
- scanned: {
261
- schemas: app.scanSchemas?.length || 0,
262
- schemaFiles: app.scanSchemas || [],
263
- resolvers: app.scanResolvers?.length || 0,
264
- resolverFiles: app.scanResolvers || [],
265
- directives: app.scanDirectives?.length || 0,
266
- directiveFiles: app.scanDirectives || [],
267
- documents: app.scanDocuments?.length || 0,
268
- documentFiles: app.scanDocuments || []
269
- },
270
- virtualModules: virtualModuleCodes
271
- };
272
- return `export const debugInfo = ${JSON.stringify(debugInfo, null, 2)};`;
273
- };
274
- }
275
-
276
- //#endregion
277
- export { rollupConfig };
@@ -1,6 +0,0 @@
1
- import * as h30 from "h3";
2
-
3
- //#region src/routes/apollo-server.d.ts
4
- declare const _default: h30.EventHandlerWithFetch<h30.EventHandlerRequest, Promise<any>>;
5
- //#endregion
6
- export { _default as default };