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

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 (242) hide show
  1. package/README.md +31 -1196
  2. package/dist/cli/adapter.d.mts +13 -0
  3. package/dist/cli/adapter.mjs +67 -0
  4. package/dist/cli/commands/build.d.mts +21 -0
  5. package/dist/cli/commands/build.mjs +50 -0
  6. package/dist/cli/commands/dev.d.mts +40 -0
  7. package/dist/cli/commands/dev.mjs +74 -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 +5 -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 +65 -0
  16. package/dist/cli/completions.d.mts +6 -0
  17. package/dist/cli/completions.mjs +32 -0
  18. package/dist/cli/config.d.mts +18 -0
  19. package/dist/cli/config.mjs +19 -0
  20. package/dist/cli/index.d.mts +26 -0
  21. package/dist/cli/index.mjs +315 -0
  22. package/dist/cli/server/debug-handler.d.mts +9 -0
  23. package/dist/cli/server/debug-handler.mjs +68 -0
  24. package/dist/cli/server/dev-server.d.mts +29 -0
  25. package/dist/cli/server/dev-server.mjs +62 -0
  26. package/dist/cli/server/graphql-handler.d.mts +21 -0
  27. package/dist/cli/server/graphql-handler.mjs +43 -0
  28. package/dist/cli/server/health-handler.d.mts +12 -0
  29. package/dist/cli/server/health-handler.mjs +29 -0
  30. package/dist/cli/server/loader.d.mts +33 -0
  31. package/dist/cli/server/loader.mjs +144 -0
  32. package/dist/cli/server/sandbox-handler.d.mts +12 -0
  33. package/dist/cli/server/sandbox-handler.mjs +17 -0
  34. package/dist/cli/server/watcher.d.mts +20 -0
  35. package/dist/cli/server/watcher.mjs +64 -0
  36. package/dist/cli/server/ws-handler.d.mts +28 -0
  37. package/dist/cli/server/ws-handler.mjs +48 -0
  38. package/dist/config.d.mts +2 -0
  39. package/dist/config.mjs +2 -0
  40. package/dist/core/codegen/client.d.mts +42 -0
  41. package/dist/core/codegen/client.mjs +551 -0
  42. package/dist/core/codegen/document-loader.d.mts +9 -0
  43. package/dist/core/codegen/document-loader.mjs +16 -0
  44. package/dist/core/codegen/index.d.mts +8 -0
  45. package/dist/core/codegen/index.mjs +8 -0
  46. package/dist/core/codegen/plugin.d.mts +19 -0
  47. package/dist/core/codegen/plugin.mjs +29 -0
  48. package/dist/core/codegen/runtime.d.mts +17 -0
  49. package/dist/core/codegen/runtime.mjs +61 -0
  50. package/dist/core/codegen/schema-loader.d.mts +27 -0
  51. package/dist/core/codegen/schema-loader.mjs +126 -0
  52. package/dist/core/codegen/server.d.mts +27 -0
  53. package/dist/core/codegen/server.mjs +142 -0
  54. package/dist/core/codegen/validation.d.mts +17 -0
  55. package/dist/core/codegen/validation.mjs +33 -0
  56. package/dist/core/config.d.mts +45 -0
  57. package/dist/core/config.mjs +76 -0
  58. package/dist/core/constants.d.mts +188 -0
  59. package/dist/core/constants.mjs +208 -0
  60. package/dist/core/debug/index.d.mts +2 -0
  61. package/dist/core/debug/index.mjs +2 -0
  62. package/dist/core/debug/template.d.mts +52 -0
  63. package/dist/core/debug/template.mjs +384 -0
  64. package/dist/core/extend/index.d.mts +2 -0
  65. package/dist/core/extend/index.mjs +2 -0
  66. package/dist/core/extend/loader.d.mts +40 -0
  67. package/dist/core/extend/loader.mjs +196 -0
  68. package/dist/core/index.d.mts +33 -0
  69. package/dist/core/index.mjs +28 -0
  70. package/dist/core/manifest.d.mts +56 -0
  71. package/dist/core/manifest.mjs +100 -0
  72. package/dist/core/pubsub/index.d.mts +109 -0
  73. package/dist/core/pubsub/index.mjs +146 -0
  74. package/dist/core/scanning/ast-scanner.d.mts +27 -0
  75. package/dist/core/scanning/ast-scanner.mjs +114 -0
  76. package/dist/core/scanning/common.d.mts +25 -0
  77. package/dist/core/scanning/common.mjs +57 -0
  78. package/dist/core/scanning/directives.d.mts +13 -0
  79. package/dist/core/scanning/directives.mjs +28 -0
  80. package/dist/core/scanning/documents.d.mts +20 -0
  81. package/dist/core/scanning/documents.mjs +36 -0
  82. package/dist/core/scanning/index.d.mts +7 -0
  83. package/dist/core/scanning/index.mjs +7 -0
  84. package/dist/core/scanning/resolvers.d.mts +14 -0
  85. package/dist/core/scanning/resolvers.mjs +58 -0
  86. package/dist/core/scanning/schemas.d.mts +13 -0
  87. package/dist/core/scanning/schemas.mjs +50 -0
  88. package/dist/core/schema/builder.d.mts +59 -0
  89. package/dist/core/schema/builder.mjs +76 -0
  90. package/dist/core/schema/federation.d.mts +33 -0
  91. package/dist/core/schema/federation.mjs +38 -0
  92. package/dist/core/schema/index.d.mts +3 -0
  93. package/dist/core/schema/index.mjs +3 -0
  94. package/dist/core/server/index.d.mts +4 -0
  95. package/dist/core/server/index.mjs +3 -0
  96. package/dist/core/server/sandbox.d.mts +18 -0
  97. package/dist/core/server/sandbox.mjs +38 -0
  98. package/dist/core/server/types.d.mts +54 -0
  99. package/dist/core/server/types.mjs +1 -0
  100. package/dist/core/server/yoga.d.mts +42 -0
  101. package/dist/core/server/yoga.mjs +87 -0
  102. package/dist/core/types/adapter.d.mts +55 -0
  103. package/dist/core/types/adapter.mjs +1 -0
  104. package/dist/core/types/codegen.d.mts +136 -0
  105. package/dist/core/types/codegen.mjs +1 -0
  106. package/dist/core/types/config.d.mts +188 -0
  107. package/dist/core/types/config.mjs +1 -0
  108. package/dist/{utils/define.d.ts → core/types/define.d.mts} +2 -30
  109. package/dist/core/types/define.mjs +1 -0
  110. package/dist/core/types/index.d.mts +5 -0
  111. package/dist/core/types/index.mjs +1 -0
  112. package/dist/core/types/scanning.d.mts +64 -0
  113. package/dist/core/types/scanning.mjs +1 -0
  114. package/dist/{utils/directive-parser.d.ts → core/utils/directive-parser.d.mts} +18 -4
  115. package/dist/{utils/directive-parser.js → core/utils/directive-parser.mjs} +29 -36
  116. package/dist/core/utils/errors.d.mts +77 -0
  117. package/dist/core/utils/errors.mjs +91 -0
  118. package/dist/core/utils/file-io.d.mts +24 -0
  119. package/dist/core/utils/file-io.mjs +45 -0
  120. package/dist/core/utils/imports.d.mts +15 -0
  121. package/dist/core/utils/imports.mjs +24 -0
  122. package/dist/core/utils/index.d.mts +7 -0
  123. package/dist/core/utils/index.mjs +7 -0
  124. package/dist/core/utils/logger.d.mts +18 -0
  125. package/dist/core/utils/logger.mjs +36 -0
  126. package/dist/core/utils/ofetch-templates.d.mts +30 -0
  127. package/dist/core/utils/ofetch-templates.mjs +134 -0
  128. package/dist/core/utils/runtime.d.mts +74 -0
  129. package/dist/core/utils/runtime.mjs +109 -0
  130. package/dist/core/utils/subscribe-templates.d.mts +8 -0
  131. package/dist/core/utils/subscribe-templates.mjs +58 -0
  132. package/dist/core/validation/external-services.d.mts +11 -0
  133. package/dist/core/validation/external-services.mjs +33 -0
  134. package/dist/core/validation/index.d.mts +2 -0
  135. package/dist/core/validation/index.mjs +2 -0
  136. package/dist/core/watcher/index.d.mts +107 -0
  137. package/dist/core/watcher/index.mjs +140 -0
  138. package/dist/define.d.mts +294 -0
  139. package/dist/define.mjs +323 -0
  140. package/dist/index.d.mts +6 -0
  141. package/dist/index.mjs +5 -0
  142. package/dist/nitro/adapter.d.mts +28 -0
  143. package/dist/nitro/adapter.mjs +90 -0
  144. package/dist/{utils/apollo.d.ts → nitro/apollo.d.mts} +3 -3
  145. package/dist/nitro/apollo.mjs +57 -0
  146. package/dist/nitro/codegen.d.mts +18 -0
  147. package/dist/nitro/codegen.mjs +171 -0
  148. package/dist/nitro/config.d.mts +50 -0
  149. package/dist/nitro/config.mjs +55 -0
  150. package/dist/nitro/index.d.mts +45 -0
  151. package/dist/nitro/index.mjs +63 -0
  152. package/dist/{utils/path-resolver.d.ts → nitro/paths.d.mts} +8 -25
  153. package/dist/nitro/paths.mjs +97 -0
  154. package/dist/nitro/rollup.d.mts +6 -0
  155. package/dist/nitro/rollup.mjs +52 -0
  156. package/dist/nitro/routes/apollo-sandbox-script.d.mts +6 -0
  157. package/dist/nitro/routes/apollo-sandbox-script.mjs +12 -0
  158. package/dist/nitro/routes/apollo-server-ws.d.mts +15 -0
  159. package/dist/nitro/routes/apollo-server-ws.mjs +50 -0
  160. package/dist/nitro/routes/apollo-server.d.mts +6 -0
  161. package/dist/nitro/routes/apollo-server.mjs +69 -0
  162. package/dist/{routes/debug.d.ts → nitro/routes/debug.d.mts} +12 -19
  163. package/dist/nitro/routes/debug.mjs +98 -0
  164. package/dist/nitro/routes/graphql-yoga-ws.d.mts +12 -0
  165. package/dist/nitro/routes/graphql-yoga-ws.mjs +50 -0
  166. package/dist/nitro/routes/graphql-yoga.d.mts +12 -0
  167. package/dist/nitro/routes/graphql-yoga.mjs +39 -0
  168. package/dist/nitro/routes/health.d.mts +10 -0
  169. package/dist/{routes/health.js → nitro/routes/health.mjs} +5 -6
  170. package/dist/nitro/setup/extend-loader.d.mts +16 -0
  171. package/dist/nitro/setup/extend-loader.mjs +80 -0
  172. package/dist/nitro/setup/file-watcher.d.mts +18 -0
  173. package/dist/nitro/setup/file-watcher.mjs +62 -0
  174. package/dist/nitro/setup/logging.d.mts +16 -0
  175. package/dist/nitro/setup/logging.mjs +64 -0
  176. package/dist/nitro/setup/rollup-integration.d.mts +24 -0
  177. package/dist/nitro/setup/rollup-integration.mjs +64 -0
  178. package/dist/nitro/setup/routes.d.mts +13 -0
  179. package/dist/nitro/setup/routes.mjs +69 -0
  180. package/dist/nitro/setup/scanner.d.mts +59 -0
  181. package/dist/nitro/setup/scanner.mjs +118 -0
  182. package/dist/nitro/setup/ts-config.d.mts +10 -0
  183. package/dist/nitro/setup/ts-config.mjs +67 -0
  184. package/dist/nitro/setup.d.mts +11 -0
  185. package/dist/nitro/setup.mjs +189 -0
  186. package/dist/nitro/types.d.mts +549 -0
  187. package/dist/nitro/types.mjs +1 -0
  188. package/dist/nitro/virtual/generators.d.mts +38 -0
  189. package/dist/nitro/virtual/generators.mjs +190 -0
  190. package/dist/nitro/virtual/stubs.d.mts +21 -0
  191. package/dist/nitro/virtual/stubs.mjs +31 -0
  192. package/dist/{ecosystem/nuxt.d.ts → nuxt.d.mts} +1 -1
  193. package/dist/nuxt.mjs +111 -0
  194. package/dist/{graphql/server.d.ts → stubs/index.d.mts} +5 -1
  195. package/dist/stubs/index.mjs +1 -0
  196. package/dist/subscribe/index.d.mts +78 -0
  197. package/dist/subscribe/index.mjs +205 -0
  198. package/native/index.d.ts +20 -0
  199. package/native/index.js +585 -0
  200. package/package.json +202 -112
  201. package/dist/ecosystem/nuxt.js +0 -67
  202. package/dist/graphql/index.d.ts +0 -5
  203. package/dist/graphql/index.js +0 -1
  204. package/dist/graphql/server.js +0 -1
  205. package/dist/index.d.ts +0 -8
  206. package/dist/index.js +0 -318
  207. package/dist/rollup.js +0 -277
  208. package/dist/routes/apollo-server.d.ts +0 -6
  209. package/dist/routes/apollo-server.js +0 -89
  210. package/dist/routes/debug.js +0 -449
  211. package/dist/routes/graphql-yoga.d.ts +0 -6
  212. package/dist/routes/graphql-yoga.js +0 -91
  213. package/dist/routes/health.d.ts +0 -10
  214. package/dist/types/index.d.ts +0 -246
  215. package/dist/types/standard-schema.d.ts +0 -59
  216. package/dist/utils/apollo.js +0 -61
  217. package/dist/utils/client-codegen.d.ts +0 -38
  218. package/dist/utils/client-codegen.js +0 -290
  219. package/dist/utils/define.js +0 -57
  220. package/dist/utils/file-generator.d.ts +0 -37
  221. package/dist/utils/file-generator.js +0 -72
  222. package/dist/utils/index.d.ts +0 -39
  223. package/dist/utils/index.js +0 -278
  224. package/dist/utils/path-resolver.js +0 -127
  225. package/dist/utils/server-codegen.d.ts +0 -7
  226. package/dist/utils/server-codegen.js +0 -136
  227. package/dist/utils/type-generation.d.ts +0 -7
  228. package/dist/utils/type-generation.js +0 -360
  229. package/dist/virtual/debug-info.d.ts +0 -9
  230. package/dist/virtual/debug-info.js +0 -26
  231. package/dist/virtual/graphql-config.d.ts +0 -9
  232. package/dist/virtual/graphql-config.js +0 -10
  233. package/dist/virtual/module-config.d.ts +0 -9
  234. package/dist/virtual/module-config.js +0 -10
  235. package/dist/virtual/server-directives.d.ts +0 -11
  236. package/dist/virtual/server-directives.js +0 -10
  237. package/dist/virtual/server-resolvers.d.ts +0 -11
  238. package/dist/virtual/server-resolvers.js +0 -10
  239. package/dist/virtual/server-schemas.d.ts +0 -11
  240. package/dist/virtual/server-schemas.js +0 -10
  241. package/dist/vite.d.ts +0 -25
  242. package/dist/vite.js +0 -40
@@ -0,0 +1,17 @@
1
+ import { ScannedResolver } from "../types/scanning.mjs";
2
+ //#region src/core/codegen/runtime.d.ts
3
+ /**
4
+ * Generate resolver module code
5
+ * Outputs Nitro-compatible format with { resolver: ... } wrapper
6
+ */
7
+ declare function generateResolverModule(resolvers: ScannedResolver[], baseDir: string): string;
8
+ /**
9
+ * Generate schema module code
10
+ */
11
+ declare function generateSchemaModule(schemaString: string): string;
12
+ /**
13
+ * Generate runtime index module
14
+ */
15
+ declare function generateRuntimeIndex(): string;
16
+ //#endregion
17
+ export { generateResolverModule, generateRuntimeIndex, generateSchemaModule };
@@ -0,0 +1,61 @@
1
+ import { relative } from "pathe";
2
+ //#region src/core/codegen/runtime.ts
3
+ const TS_EXTENSION_RE = /\.ts$/;
4
+ const BACKTICK_RE = /`/g;
5
+ const DOLLAR_SIGN_RE = /\$/g;
6
+ /**
7
+ * Generate resolver module code
8
+ * Outputs Nitro-compatible format with { resolver: ... } wrapper
9
+ */
10
+ function generateResolverModule(resolvers, baseDir) {
11
+ if (!resolvers.length) return `// Auto-generated by nitro-graphql - no resolvers found
12
+ export const resolvers = []
13
+ `;
14
+ const imports = [];
15
+ const resolverEntries = [];
16
+ const reexports = [];
17
+ for (const resolver of resolvers) {
18
+ const relativePath = relative(baseDir, resolver.specifier).replace(TS_EXTENSION_RE, "");
19
+ const exportNames = resolver.imports.map((i) => i.name);
20
+ if (exportNames.length > 0) {
21
+ imports.push(`import { ${exportNames.join(", ")} } from '${relativePath}'`);
22
+ for (const name of exportNames) resolverEntries.push(` { resolver: ${name} }`);
23
+ reexports.push(`export { ${exportNames.join(", ")} } from '${relativePath}'`);
24
+ }
25
+ }
26
+ return `// Auto-generated by nitro-graphql - do not edit
27
+ ${imports.join("\n")}
28
+
29
+ export const resolvers = [
30
+ ${resolverEntries.join(",\n")},
31
+ ]
32
+
33
+ // Re-exports for tree-shaking
34
+ ${reexports.join("\n")}
35
+ `;
36
+ }
37
+ /**
38
+ * Generate schema module code
39
+ */
40
+ function generateSchemaModule(schemaString) {
41
+ return `// Auto-generated by nitro-graphql - do not edit
42
+ export const schemaString = \`
43
+ ${schemaString.replace(BACKTICK_RE, "\\`").replace(DOLLAR_SIGN_RE, "\\$")}
44
+ \`
45
+
46
+ // Pre-parsed for convenience
47
+ import { parse } from 'graphql'
48
+ export const typeDefs = parse(schemaString)
49
+ `;
50
+ }
51
+ /**
52
+ * Generate runtime index module
53
+ */
54
+ function generateRuntimeIndex() {
55
+ return `// Auto-generated by nitro-graphql - do not edit
56
+ export { resolvers } from './resolvers'
57
+ export { schemaString, typeDefs } from './schema'
58
+ `;
59
+ }
60
+ //#endregion
61
+ export { generateResolverModule, generateRuntimeIndex, generateSchemaModule };
@@ -0,0 +1,27 @@
1
+ import { ExternalServiceCodegenConfig } from "../types/codegen.mjs";
2
+ import { GraphQLSchema } from "graphql";
3
+ import { LoadSchemaOptions, UnnormalizedTypeDefPointer } from "@graphql-tools/load";
4
+
5
+ //#region src/core/codegen/schema-loader.d.ts
6
+ /**
7
+ * Type definition pointer for GraphQL schemas
8
+ */
9
+ type GraphQLTypeDefPointer = UnnormalizedTypeDefPointer | UnnormalizedTypeDefPointer[];
10
+ /**
11
+ * Options for loading GraphQL schemas
12
+ */
13
+ type GraphQLLoadSchemaOptions = Partial<LoadSchemaOptions>;
14
+ /**
15
+ * Load GraphQL schema synchronously
16
+ */
17
+ declare function graphQLLoadSchemaSync(schemaPointers: GraphQLTypeDefPointer, data?: GraphQLLoadSchemaOptions): GraphQLSchema | undefined;
18
+ /**
19
+ * Load schema from external GraphQL service
20
+ */
21
+ declare function loadExternalSchema(service: ExternalServiceCodegenConfig, buildDir?: string): Promise<GraphQLSchema | undefined>;
22
+ /**
23
+ * Download and save schema from external service
24
+ */
25
+ declare function downloadAndSaveSchema(service: ExternalServiceCodegenConfig, buildDir: string): Promise<string | undefined>;
26
+ //#endregion
27
+ export { GraphQLLoadSchemaOptions, GraphQLTypeDefPointer, downloadAndSaveSchema, graphQLLoadSchemaSync, loadExternalSchema };
@@ -0,0 +1,126 @@
1
+ import { writeFileIfChanged } from "../utils/file-io.mjs";
2
+ import { resolve } from "pathe";
3
+ import { printSchemaWithDirectives } from "@graphql-tools/utils";
4
+ import { GraphQLFileLoader } from "@graphql-tools/graphql-file-loader";
5
+ import { loadSchemaSync } from "@graphql-tools/load";
6
+ import { createHash } from "node:crypto";
7
+ import { existsSync, readFileSync, statSync } from "node:fs";
8
+ import { UrlLoader } from "@graphql-tools/url-loader";
9
+ //#region src/core/codegen/schema-loader.ts
10
+ /**
11
+ * Check if a path is a URL
12
+ */
13
+ function isUrl(path) {
14
+ return path.startsWith("http://") || path.startsWith("https://");
15
+ }
16
+ /**
17
+ * Load GraphQL schema synchronously
18
+ */
19
+ function graphQLLoadSchemaSync(schemaPointers, data = {}) {
20
+ const filteredPointers = [...Array.isArray(schemaPointers) ? schemaPointers : [schemaPointers], "!**/vfs/**"];
21
+ try {
22
+ return loadSchemaSync(filteredPointers, {
23
+ ...data,
24
+ loaders: [
25
+ new GraphQLFileLoader(),
26
+ new UrlLoader(),
27
+ ...data.loaders || []
28
+ ]
29
+ });
30
+ } catch (e) {
31
+ if ((e.message || "").includes("Unable to find any GraphQL type definitions for the following pointers:")) return;
32
+ throw e;
33
+ }
34
+ }
35
+ /**
36
+ * Load schema from external GraphQL service
37
+ */
38
+ async function loadExternalSchema(service, buildDir) {
39
+ try {
40
+ const headers = typeof service.headers === "function" ? service.headers() : service.headers || {};
41
+ const schemaSource = service.schema ?? service.endpoint;
42
+ const schemas = Array.isArray(schemaSource) ? schemaSource : [schemaSource];
43
+ if (service.downloadSchema && buildDir) {
44
+ const defaultPath = resolve(buildDir, "graphql", "schemas", `${service.name}.graphql`);
45
+ const schemaFilePath = service.downloadPath ? resolve(service.downloadPath) : defaultPath;
46
+ if (existsSync(schemaFilePath)) try {
47
+ return loadSchemaSync([schemaFilePath], { loaders: [new GraphQLFileLoader()] });
48
+ } catch {}
49
+ }
50
+ const hasUrls = schemas.some((schema) => isUrl(schema));
51
+ const hasLocalFiles = schemas.some((schema) => !isUrl(schema));
52
+ const loaders = [];
53
+ if (hasLocalFiles) loaders.push(new GraphQLFileLoader());
54
+ if (hasUrls) loaders.push(new UrlLoader());
55
+ if (loaders.length === 0) throw new Error("No appropriate loaders found for schema sources");
56
+ return loadSchemaSync(schemas, {
57
+ loaders,
58
+ ...Object.keys(headers).length > 0 && { headers }
59
+ });
60
+ } catch {
61
+ return;
62
+ }
63
+ }
64
+ /**
65
+ * Download and save schema from external service
66
+ */
67
+ async function downloadAndSaveSchema(service, buildDir) {
68
+ const downloadMode = service.downloadSchema;
69
+ if (!downloadMode || downloadMode === "manual") return;
70
+ const defaultPath = resolve(buildDir, "graphql", "schemas", `${service.name}.graphql`);
71
+ const schemaFilePath = service.downloadPath ? resolve(service.downloadPath) : defaultPath;
72
+ try {
73
+ const headers = typeof service.headers === "function" ? service.headers() : service.headers || {};
74
+ const schemaSource = service.schema ?? service.endpoint;
75
+ const schemas = Array.isArray(schemaSource) ? schemaSource : [schemaSource];
76
+ const hasUrlSchemas = schemas.some((schema) => isUrl(schema));
77
+ const hasLocalSchemas = schemas.some((schema) => !isUrl(schema));
78
+ let shouldDownload = false;
79
+ const fileExists = existsSync(schemaFilePath);
80
+ if (downloadMode === "always") {
81
+ shouldDownload = true;
82
+ if (fileExists && hasUrlSchemas) try {
83
+ const remoteSchemaString = printSchemaWithDirectives(loadSchemaSync(schemas.filter(isUrl), {
84
+ loaders: [new UrlLoader()],
85
+ ...Object.keys(headers).length > 0 && { headers }
86
+ }));
87
+ const remoteHash = createHash("md5").update(remoteSchemaString).digest("hex");
88
+ const localSchemaString = readFileSync(schemaFilePath, "utf-8");
89
+ if (remoteHash === createHash("md5").update(localSchemaString).digest("hex")) shouldDownload = false;
90
+ } catch {
91
+ shouldDownload = true;
92
+ }
93
+ else if (fileExists && hasLocalSchemas) {
94
+ const localFiles = schemas.filter((schema) => !isUrl(schema));
95
+ let sourceIsNewer = false;
96
+ for (const localFile of localFiles) if (existsSync(localFile)) {
97
+ const sourceStats = statSync(localFile);
98
+ const cachedStats = statSync(schemaFilePath);
99
+ if (sourceStats.mtime > cachedStats.mtime) {
100
+ sourceIsNewer = true;
101
+ break;
102
+ }
103
+ }
104
+ if (!sourceIsNewer) shouldDownload = false;
105
+ }
106
+ } else if (downloadMode === true || downloadMode === "once") shouldDownload = !fileExists;
107
+ if (shouldDownload) {
108
+ let schema;
109
+ if (hasUrlSchemas && hasLocalSchemas) schema = loadSchemaSync(schemas, {
110
+ loaders: [new GraphQLFileLoader(), new UrlLoader()],
111
+ ...Object.keys(headers).length > 0 && { headers }
112
+ });
113
+ else if (hasUrlSchemas) schema = loadSchemaSync(schemas, {
114
+ loaders: [new UrlLoader()],
115
+ ...Object.keys(headers).length > 0 && { headers }
116
+ });
117
+ else schema = loadSchemaSync(schemas, { loaders: [new GraphQLFileLoader()] });
118
+ writeFileIfChanged(schemaFilePath, printSchemaWithDirectives(schema));
119
+ }
120
+ return schemaFilePath;
121
+ } catch {
122
+ return;
123
+ }
124
+ }
125
+ //#endregion
126
+ export { downloadAndSaveSchema, graphQLLoadSchemaSync, loadExternalSchema };
@@ -0,0 +1,27 @@
1
+ import { ServerCodegenConfig, ServerCodegenInput, ServerCodegenResult } from "../types/codegen.mjs";
2
+ import { GraphQLSchema } from "graphql";
3
+
4
+ //#region src/core/codegen/server.d.ts
5
+ /**
6
+ * Default server codegen configuration
7
+ */
8
+ declare const DEFAULT_SERVER_CODEGEN_CONFIG: ServerCodegenConfig;
9
+ /**
10
+ * Generate server-side GraphQL types
11
+ * Pure function that generates TypeScript types from a GraphQL schema
12
+ */
13
+ declare function generateServerTypesCore(input: ServerCodegenInput): Promise<ServerCodegenResult>;
14
+ /**
15
+ * Generate types from schema (simplified version for direct use)
16
+ * @deprecated Use generateServerTypesCore instead
17
+ */
18
+ declare function generateTypes(framework: string, schema: GraphQLSchema, config?: {
19
+ codegen?: {
20
+ server?: ServerCodegenConfig;
21
+ };
22
+ federation?: {
23
+ enabled?: boolean;
24
+ };
25
+ }, outputPath?: string): Promise<string>;
26
+ //#endregion
27
+ export { DEFAULT_SERVER_CODEGEN_CONFIG, generateServerTypesCore, generateTypes };
@@ -0,0 +1,142 @@
1
+ import { DEFAULT_GRAPHQL_SCALARS } from "../constants.mjs";
2
+ import { pluginContent } from "./plugin.mjs";
3
+ import { defu as defu$1 } from "defu";
4
+ import { codegen } from "@graphql-codegen/core";
5
+ import * as typescriptPlugin from "@graphql-codegen/typescript";
6
+ import { printSchemaWithDirectives } from "@graphql-tools/utils";
7
+ import { parse } from "graphql";
8
+ import * as typescriptResolversPlugin from "@graphql-codegen/typescript-resolvers";
9
+ //#region src/core/codegen/server.ts
10
+ /**
11
+ * Default server codegen configuration
12
+ */
13
+ const DEFAULT_SERVER_CODEGEN_CONFIG = {
14
+ scalars: DEFAULT_GRAPHQL_SCALARS,
15
+ defaultScalarType: "unknown",
16
+ defaultMapper: `ResolverReturnType<{T}>`,
17
+ contextType: "nitro/h3#H3Event",
18
+ maybeValue: "T | null | undefined",
19
+ inputMaybeValue: "T | undefined",
20
+ declarationKind: "interface",
21
+ enumsAsTypes: true
22
+ };
23
+ /**
24
+ * Generate server-side GraphQL types
25
+ * Pure function that generates TypeScript types from a GraphQL schema
26
+ */
27
+ async function generateServerTypesCore(input) {
28
+ const { framework, schema, schemaString: inputSchemaString, config = {}, federationEnabled = false, outputPath } = input;
29
+ const mergedConfig = defu$1({
30
+ ...DEFAULT_SERVER_CODEGEN_CONFIG,
31
+ ...federationEnabled && { federation: true }
32
+ }, config);
33
+ const schemaString = inputSchemaString || (schema ? printSchemaWithDirectives(schema) : null);
34
+ if (!schemaString) throw new Error("[generateServerTypesCore] No schema or schemaString provided");
35
+ return {
36
+ types: await codegen({
37
+ filename: outputPath || "types.generated.ts",
38
+ schema: parse(schemaString),
39
+ documents: [],
40
+ config: mergedConfig,
41
+ plugins: [
42
+ { imports: {} },
43
+ { pluginContent: {} },
44
+ { typescript: {} },
45
+ { typescriptResolvers: {} }
46
+ ],
47
+ pluginMap: {
48
+ pluginContent: { plugin: pluginContent },
49
+ imports: { plugin: () => {
50
+ return {
51
+ prepend: [
52
+ `import schemas from '#nitro-graphql/validation-schemas'`,
53
+ `import type { StandardSchemaV1 } from 'nitro-graphql/types'`,
54
+ generateServerTypeHelpers(framework),
55
+ ""
56
+ ],
57
+ content: ""
58
+ };
59
+ } },
60
+ typescript: typescriptPlugin,
61
+ typescriptResolvers: typescriptResolversPlugin
62
+ }
63
+ }),
64
+ schemaString
65
+ };
66
+ }
67
+ /**
68
+ * Generate server type helper code
69
+ */
70
+ function generateServerTypeHelpers(framework) {
71
+ return `
72
+ export interface NPMConfig {
73
+ framework: '${framework || "graphql-yoga"}';
74
+ }
75
+
76
+ export type SchemaType = Partial<Record<Partial<keyof ResolversTypes>, StandardSchemaV1>>
77
+
78
+ // Check if schemas is empty object, return never if so
79
+ type SafeSchemaKeys<T> = T extends Record<PropertyKey, never>
80
+ ? never
81
+ : keyof T extends string | number | symbol
82
+ ? keyof T extends never
83
+ ? never
84
+ : keyof T
85
+ : never;
86
+
87
+
88
+ type SchemaKeys = SafeSchemaKeys<typeof schemas>;
89
+
90
+ type InferInput<T> = T extends StandardSchemaV1 ? StandardSchemaV1.InferInput<T> : unknown;
91
+ type InferOutput<T> = T extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<T> : unknown;
92
+
93
+ type InferInputFromSchema<T extends SchemaKeys> = InferInput<(typeof schemas)[T]>;
94
+ type InferOutputFromSchema<T extends SchemaKeys> = InferOutput<(typeof schemas)[T]>;
95
+
96
+ type Primitive =
97
+ | null
98
+ | undefined
99
+ | string
100
+ | number
101
+ | boolean
102
+ | symbol
103
+ | bigint;
104
+
105
+ type BuiltIns = Primitive | void | Date | RegExp;
106
+
107
+
108
+ type ResolverReturnType<T> = T extends BuiltIns
109
+ ? T
110
+ : T extends (...args: any[]) => unknown
111
+ ? T | undefined
112
+ : T extends object
113
+ ? T extends Array<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
114
+ ? ItemType[] extends T // Test for arrays (non-tuples) specifically
115
+ ? Array<ResolverReturnType<ItemType>>
116
+ : ResolverReturnTypeObject<T> // Tuples behave properly
117
+ : ResolverReturnTypeObject<T>
118
+ : unknown;
119
+
120
+ type ResolverReturnTypeObject<T extends object> =
121
+ T extends { __typename?: infer TTypename }
122
+ ? TTypename extends SchemaKeys
123
+ ? InferOutputFromSchema<TTypename>
124
+ : { [K in keyof T]: ResolverReturnType<T[K]> }
125
+ : { [K in keyof T]: ResolverReturnType<T[K]> };
126
+ `;
127
+ }
128
+ /**
129
+ * Generate types from schema (simplified version for direct use)
130
+ * @deprecated Use generateServerTypesCore instead
131
+ */
132
+ async function generateTypes(framework, schema, config = {}, outputPath) {
133
+ return (await generateServerTypesCore({
134
+ framework,
135
+ schema,
136
+ config: config.codegen?.server,
137
+ federationEnabled: config.federation?.enabled,
138
+ outputPath
139
+ })).types;
140
+ }
141
+ //#endregion
142
+ export { DEFAULT_SERVER_CODEGEN_CONFIG, generateServerTypesCore, generateTypes };
@@ -0,0 +1,17 @@
1
+ //#region src/core/codegen/validation.d.ts
2
+ /**
3
+ * GraphQL schema validation utilities
4
+ * Uses native Rust validator (apollo-compiler) for fast validation
5
+ */
6
+ /**
7
+ * Validate GraphQL schemas using native Rust validator (apollo-compiler)
8
+ * @returns true if validation passes, false if errors found
9
+ */
10
+ declare function validateNoDuplicateTypes(schemas: string[], schemaStrings: string[]): boolean;
11
+ /**
12
+ * Validate GraphQL schema files directly
13
+ * @returns true if validation passes, false if errors found
14
+ */
15
+ declare function validateSchemaFiles(filePaths: string[]): boolean;
16
+ //#endregion
17
+ export { validateNoDuplicateTypes, validateSchemaFiles };
@@ -0,0 +1,33 @@
1
+ import consola from "consola";
2
+ import { validateSchemaStringWithPaths, validateSchemas } from "nitro-graphql/native";
3
+ //#region src/core/codegen/validation.ts
4
+ /**
5
+ * GraphQL schema validation utilities
6
+ * Uses native Rust validator (apollo-compiler) for fast validation
7
+ */
8
+ /**
9
+ * Validate GraphQL schemas using native Rust validator (apollo-compiler)
10
+ * @returns true if validation passes, false if errors found
11
+ */
12
+ function validateNoDuplicateTypes(schemas, schemaStrings) {
13
+ const result = validateSchemaStringWithPaths(schemaStrings, schemas);
14
+ if (!result.valid) {
15
+ for (const error of result.errors) consola.error(error);
16
+ return false;
17
+ }
18
+ return true;
19
+ }
20
+ /**
21
+ * Validate GraphQL schema files directly
22
+ * @returns true if validation passes, false if errors found
23
+ */
24
+ function validateSchemaFiles(filePaths) {
25
+ const result = validateSchemas(filePaths);
26
+ if (!result.valid) {
27
+ for (const error of result.errors) consola.error(error);
28
+ return false;
29
+ }
30
+ return true;
31
+ }
32
+ //#endregion
33
+ export { validateNoDuplicateTypes, validateSchemaFiles };
@@ -0,0 +1,45 @@
1
+ import { CoreConfig, CoreContext, CoreGraphQLOptions, CoreLogger } from "./types/config.mjs";
2
+ import { ScanContext } from "./types/scanning.mjs";
3
+
4
+ //#region src/core/config.d.ts
5
+ /**
6
+ * Options for creating a CoreConfig
7
+ */
8
+ interface CreateCoreConfigOptions {
9
+ /** Root directory of the project */
10
+ rootDir: string;
11
+ /** Build directory (optional, defaults based on framework) */
12
+ buildDir?: string;
13
+ /** Server GraphQL directory (optional) */
14
+ serverDir?: string;
15
+ /** Client GraphQL directory (optional) */
16
+ clientDir?: string;
17
+ /** Whether running in Nuxt context */
18
+ isNuxt?: boolean;
19
+ /** Whether running in development mode */
20
+ isDev?: boolean;
21
+ /** GraphQL options */
22
+ graphqlOptions?: CoreGraphQLOptions;
23
+ /** Custom logger */
24
+ logger?: CoreLogger;
25
+ /** Patterns to ignore */
26
+ ignorePatterns?: string[];
27
+ }
28
+ /**
29
+ * Create a CoreConfig with sensible defaults
30
+ */
31
+ declare function createCoreConfig(options: CreateCoreConfigOptions): CoreConfig;
32
+ /**
33
+ * Create a CoreContext from CoreConfig
34
+ */
35
+ declare function createCoreContext(config: CoreConfig): CoreContext;
36
+ /**
37
+ * Create a ScanContext from CoreConfig
38
+ */
39
+ declare function createScanContext(config: CoreConfig): ScanContext;
40
+ /**
41
+ * Merge GraphQL options with defaults
42
+ */
43
+ declare function mergeGraphQLOptions(options: Partial<CoreGraphQLOptions>, defaults?: Partial<CoreGraphQLOptions>): CoreGraphQLOptions;
44
+ //#endregion
45
+ export { CreateCoreConfigOptions, createCoreConfig, createCoreContext, createScanContext, mergeGraphQLOptions };
@@ -0,0 +1,76 @@
1
+ import "./constants.mjs";
2
+ import { createLogger } from "./utils/logger.mjs";
3
+ import { relative, resolve } from "pathe";
4
+ //#region src/core/config.ts
5
+ /**
6
+ * Create a CoreConfig with sensible defaults
7
+ */
8
+ function createCoreConfig(options) {
9
+ const { rootDir, isNuxt = false, isDev = process.env.NODE_ENV !== "production", graphqlOptions = {}, logger = createLogger(), ignorePatterns = [] } = options;
10
+ const framework = graphqlOptions.framework || "graphql-yoga";
11
+ const buildDir = options.buildDir || resolve(rootDir, isNuxt ? ".nuxt" : ".nitro");
12
+ return {
13
+ rootDir,
14
+ buildDir,
15
+ serverDir: options.serverDir || resolve(rootDir, "server/graphql"),
16
+ clientDir: options.clientDir || resolve(rootDir, isNuxt ? "app/graphql" : "graphql"),
17
+ typesDir: resolve(buildDir, "types"),
18
+ framework,
19
+ isNuxt,
20
+ isDev,
21
+ graphqlOptions,
22
+ logger,
23
+ ignorePatterns
24
+ };
25
+ }
26
+ /**
27
+ * Create a CoreContext from CoreConfig
28
+ */
29
+ function createCoreContext(config) {
30
+ return {
31
+ config,
32
+ graphqlBuildDir: resolve(config.buildDir, "graphql"),
33
+ watchDirs: [],
34
+ dir: {
35
+ build: relative(config.rootDir, config.buildDir),
36
+ client: relative(config.rootDir, config.clientDir),
37
+ server: relative(config.rootDir, config.serverDir)
38
+ }
39
+ };
40
+ }
41
+ /**
42
+ * Create a ScanContext from CoreConfig
43
+ */
44
+ function createScanContext(config) {
45
+ return {
46
+ rootDir: config.rootDir,
47
+ serverDir: config.serverDir,
48
+ clientDir: config.clientDir,
49
+ ignorePatterns: config.ignorePatterns,
50
+ isDev: config.isDev,
51
+ logger: config.logger
52
+ };
53
+ }
54
+ /**
55
+ * Merge GraphQL options with defaults
56
+ */
57
+ function mergeGraphQLOptions(options, defaults = {}) {
58
+ return {
59
+ ...defaults,
60
+ ...options,
61
+ codegen: {
62
+ ...defaults.codegen,
63
+ ...options.codegen
64
+ },
65
+ security: {
66
+ ...defaults.security,
67
+ ...options.security
68
+ },
69
+ paths: {
70
+ ...defaults.paths,
71
+ ...options.paths
72
+ }
73
+ };
74
+ }
75
+ //#endregion
76
+ export { createCoreConfig, createCoreContext, createScanContext, mergeGraphQLOptions };