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,28 @@
1
+ import { DIRECTIVE_GLOB_PATTERN } from "../constants.mjs";
2
+ import { scanWithAST } from "./ast-scanner.mjs";
3
+ import { hash } from "ohash";
4
+ //#region src/core/scanning/directives.ts
5
+ const HYPHEN_RE = /-/g;
6
+ /**
7
+ * Parse a defineDirective call and return the import info
8
+ */
9
+ function parseDirectiveCall(calleeName, exportName, filePath) {
10
+ if (calleeName !== "defineDirective") return null;
11
+ return {
12
+ name: exportName,
13
+ type: "directive",
14
+ as: `_${hash(exportName + filePath).replace(HYPHEN_RE, "").slice(0, 6)}`
15
+ };
16
+ }
17
+ /**
18
+ * Scan for directive files (.directive.ts/.js)
19
+ */
20
+ function scanDirectivesCore(ctx) {
21
+ return scanWithAST(ctx, {
22
+ pattern: DIRECTIVE_GLOB_PATTERN,
23
+ parseCall: parseDirectiveCall,
24
+ emitWarnings: false
25
+ });
26
+ }
27
+ //#endregion
28
+ export { parseDirectiveCall, scanDirectivesCore };
@@ -0,0 +1,20 @@
1
+ import { CoreExternalService } from "../types/config.mjs";
2
+ import { ScanContext, ScanResult } from "../types/scanning.mjs";
3
+
4
+ //#region src/core/scanning/documents.d.ts
5
+ /**
6
+ * Options for scanning documents
7
+ */
8
+ interface ScanDocumentsOptions {
9
+ /** External services to exclude from main scan */
10
+ externalServices?: CoreExternalService[];
11
+ /** Client directory relative path */
12
+ clientDirRelative?: string;
13
+ }
14
+ /**
15
+ * Scan for GraphQL client documents (.graphql, .gql) in client directory
16
+ * Excludes files from external service directories
17
+ */
18
+ declare function scanDocumentsCore(ctx: ScanContext, options?: ScanDocumentsOptions): Promise<ScanResult<string>>;
19
+ //#endregion
20
+ export { ScanDocumentsOptions, scanDocumentsCore };
@@ -0,0 +1,36 @@
1
+ import { GRAPHQL_GLOB_PATTERN } from "../constants.mjs";
2
+ import { scanDirectory } from "./common.mjs";
3
+ import { relative } from "pathe";
4
+ //#region src/core/scanning/documents.ts
5
+ const REGEX_SPECIAL_CHARS_RE = /[.*+?^${}()|[\]\\]/g;
6
+ /**
7
+ * Scan for GraphQL client documents (.graphql, .gql) in client directory
8
+ * Excludes files from external service directories
9
+ */
10
+ async function scanDocumentsCore(ctx, options = {}) {
11
+ const warnings = [];
12
+ const errors = [];
13
+ try {
14
+ const clientDirRelative = options.clientDirRelative || relative(ctx.rootDir, ctx.clientDir);
15
+ const allFiles = await scanDirectory(ctx, ctx.rootDir, clientDirRelative, GRAPHQL_GLOB_PATTERN);
16
+ const externalPatterns = (options.externalServices || []).flatMap((service) => service.documents || []);
17
+ return {
18
+ items: allFiles.filter((f) => !f.path.startsWith("external/")).filter((f) => {
19
+ const relativePath = f.path;
20
+ for (const pattern of externalPatterns) if (pattern.replace(new RegExp(`^${clientDirRelative.replace(REGEX_SPECIAL_CHARS_RE, "\\$&")}/`), "").split("/")[0] === relativePath.split("/")[0]) return false;
21
+ return true;
22
+ }).map((f) => f.fullPath),
23
+ warnings,
24
+ errors
25
+ };
26
+ } catch (error) {
27
+ errors.push(`Document scanning error: ${error}`);
28
+ return {
29
+ items: [],
30
+ warnings,
31
+ errors
32
+ };
33
+ }
34
+ }
35
+ //#endregion
36
+ export { scanDocumentsCore };
@@ -0,0 +1,7 @@
1
+ import { ASTScanConfig, parseSingleFile, scanWithAST } from "./ast-scanner.mjs";
2
+ import { deduplicateFiles, extractPaths, filterByExtension, scanDirectory } from "./common.mjs";
3
+ import { parseDirectiveCall, scanDirectivesCore } from "./directives.mjs";
4
+ import { ScanDocumentsOptions, scanDocumentsCore } from "./documents.mjs";
5
+ import { parseResolverCall, scanResolversCore } from "./resolvers.mjs";
6
+ import { scanGraphqlCore, scanSchemasCore } from "./schemas.mjs";
7
+ export { type ASTScanConfig, type ScanDocumentsOptions, deduplicateFiles, extractPaths, filterByExtension, parseDirectiveCall, parseResolverCall, parseSingleFile, scanDirectivesCore, scanDirectory, scanDocumentsCore, scanGraphqlCore, scanResolversCore, scanSchemasCore, scanWithAST };
@@ -0,0 +1,7 @@
1
+ import { deduplicateFiles, extractPaths, filterByExtension, scanDirectory } from "./common.mjs";
2
+ import { parseSingleFile, scanWithAST } from "./ast-scanner.mjs";
3
+ import { parseDirectiveCall, scanDirectivesCore } from "./directives.mjs";
4
+ import { scanDocumentsCore } from "./documents.mjs";
5
+ import { parseResolverCall, scanResolversCore } from "./resolvers.mjs";
6
+ import { scanGraphqlCore, scanSchemasCore } from "./schemas.mjs";
7
+ export { deduplicateFiles, extractPaths, filterByExtension, parseDirectiveCall, parseResolverCall, parseSingleFile, scanDirectivesCore, scanDirectory, scanDocumentsCore, scanGraphqlCore, scanResolversCore, scanSchemasCore, scanWithAST };
@@ -0,0 +1,14 @@
1
+ import { ResolverImport, ScanContext, ScanResult, ScannedResolver } from "../types/scanning.mjs";
2
+
3
+ //#region src/core/scanning/resolvers.d.ts
4
+ /**
5
+ * Parse a define* function call and return the import info
6
+ * Exported for use by manifest loader
7
+ */
8
+ declare function parseResolverCall(calleeName: string, exportName: string, filePath: string): ResolverImport | null;
9
+ /**
10
+ * Scan for resolver files and parse their exports
11
+ */
12
+ declare function scanResolversCore(ctx: ScanContext): Promise<ScanResult<ScannedResolver>>;
13
+ //#endregion
14
+ export { parseResolverCall, scanResolversCore };
@@ -0,0 +1,58 @@
1
+ import { DEFINE_FUNCTIONS, RESOLVER_GLOB_PATTERN } from "../constants.mjs";
2
+ import { scanWithAST } from "./ast-scanner.mjs";
3
+ import { hash } from "ohash";
4
+ //#region src/core/scanning/resolvers.ts
5
+ const HYPHEN_RE = /-/g;
6
+ /**
7
+ * Parse a define* function call and return the import info
8
+ * Exported for use by manifest loader
9
+ */
10
+ function parseResolverCall(calleeName, exportName, filePath) {
11
+ const aliasHash = `_${hash(exportName + filePath).replace(HYPHEN_RE, "").slice(0, 6)}`;
12
+ switch (calleeName) {
13
+ case "defineResolver": return {
14
+ name: exportName,
15
+ type: "resolver",
16
+ as: aliasHash
17
+ };
18
+ case "defineQuery": return {
19
+ name: exportName,
20
+ type: "query",
21
+ as: aliasHash
22
+ };
23
+ case "defineMutation": return {
24
+ name: exportName,
25
+ type: "mutation",
26
+ as: aliasHash
27
+ };
28
+ case "defineField": return {
29
+ name: exportName,
30
+ type: "type",
31
+ as: aliasHash
32
+ };
33
+ case "defineSubscription": return {
34
+ name: exportName,
35
+ type: "subscription",
36
+ as: aliasHash
37
+ };
38
+ case "defineDirective": return {
39
+ name: exportName,
40
+ type: "directive",
41
+ as: aliasHash
42
+ };
43
+ default: return null;
44
+ }
45
+ }
46
+ /**
47
+ * Scan for resolver files and parse their exports
48
+ */
49
+ function scanResolversCore(ctx) {
50
+ return scanWithAST(ctx, {
51
+ pattern: RESOLVER_GLOB_PATTERN,
52
+ parseCall: parseResolverCall,
53
+ emitWarnings: true,
54
+ validFunctions: DEFINE_FUNCTIONS
55
+ });
56
+ }
57
+ //#endregion
58
+ export { parseResolverCall, scanResolversCore };
@@ -0,0 +1,13 @@
1
+ import { ScanContext, ScanResult } from "../types/scanning.mjs";
2
+
3
+ //#region src/core/scanning/schemas.d.ts
4
+ /**
5
+ * Scan for GraphQL schema files (.graphql, .gql) in server directory
6
+ */
7
+ declare function scanSchemasCore(ctx: ScanContext): Promise<ScanResult<string>>;
8
+ /**
9
+ * Scan for GraphQL files (.graphql, .gql) in server directory
10
+ */
11
+ declare function scanGraphqlCore(ctx: ScanContext): Promise<ScanResult<string>>;
12
+ //#endregion
13
+ export { scanGraphqlCore, scanSchemasCore };
@@ -0,0 +1,50 @@
1
+ import { GRAPHQL_GLOB_PATTERN } from "../constants.mjs";
2
+ import { extractPaths, scanDirectory } from "./common.mjs";
3
+ import { relative } from "pathe";
4
+ //#region src/core/scanning/schemas.ts
5
+ /**
6
+ * Scan for GraphQL schema files (.graphql, .gql) in server directory
7
+ */
8
+ async function scanSchemasCore(ctx) {
9
+ const warnings = [];
10
+ const errors = [];
11
+ try {
12
+ const serverDirRelative = relative(ctx.rootDir, ctx.serverDir);
13
+ return {
14
+ items: extractPaths(await scanDirectory(ctx, ctx.rootDir, serverDirRelative, GRAPHQL_GLOB_PATTERN)),
15
+ warnings,
16
+ errors
17
+ };
18
+ } catch (error) {
19
+ errors.push(`Schema scanning error: ${error}`);
20
+ return {
21
+ items: [],
22
+ warnings,
23
+ errors
24
+ };
25
+ }
26
+ }
27
+ /**
28
+ * Scan for GraphQL files (.graphql, .gql) in server directory
29
+ */
30
+ async function scanGraphqlCore(ctx) {
31
+ const warnings = [];
32
+ const errors = [];
33
+ try {
34
+ const serverDirRelative = relative(ctx.rootDir, ctx.serverDir);
35
+ return {
36
+ items: extractPaths(await scanDirectory(ctx, ctx.rootDir, serverDirRelative, "**/*.{graphql,gql}")),
37
+ warnings,
38
+ errors
39
+ };
40
+ } catch (error) {
41
+ errors.push(`GraphQL scanning error: ${error}`);
42
+ return {
43
+ items: [],
44
+ warnings,
45
+ errors
46
+ };
47
+ }
48
+ }
49
+ //#endregion
50
+ export { scanGraphqlCore, scanSchemasCore };
@@ -0,0 +1,59 @@
1
+ import { DirectiveDefinition } from "../types/define.mjs";
2
+ import { GraphQLSchema, parse, subscribe, validate } from "graphql";
3
+
4
+ //#region src/core/schema/builder.d.ts
5
+ /**
6
+ * Schema definition from virtual module
7
+ */
8
+ interface SchemaDefinition {
9
+ def: string;
10
+ }
11
+ /**
12
+ * Resolver definition from virtual module
13
+ */
14
+ interface ResolverDefinition {
15
+ resolver: Record<string, unknown>;
16
+ }
17
+ /**
18
+ * Directive wrapper from virtual module
19
+ */
20
+ interface DirectiveWrapper {
21
+ directive: DirectiveDefinition;
22
+ }
23
+ /**
24
+ * Module configuration for federation
25
+ */
26
+ interface ModuleConfig {
27
+ federation?: {
28
+ enabled?: boolean;
29
+ serviceName?: string;
30
+ };
31
+ }
32
+ /**
33
+ * Options for creating a merged schema
34
+ */
35
+ interface CreateMergedSchemaOptions {
36
+ schemas: SchemaDefinition[];
37
+ resolvers: ResolverDefinition[];
38
+ directives?: DirectiveWrapper[];
39
+ moduleConfig: ModuleConfig;
40
+ }
41
+ /**
42
+ * Create a merged GraphQL schema from schemas, resolvers, and directives
43
+ * Supports Apollo Federation when enabled
44
+ */
45
+ declare function createMergedSchema(options: CreateMergedSchemaOptions): Promise<GraphQLSchema>;
46
+ /**
47
+ * Base schema with empty Query and Mutation types.
48
+ * Required for 'extend type Query' syntax to work.
49
+ * Shared between CLI and Nitro.
50
+ */
51
+ declare const BASE_SCHEMA = "type Query { _empty: String }\ntype Mutation { _empty: String }";
52
+ /**
53
+ * Build a GraphQL schema from file paths (CLI usage)
54
+ * Reads schema files, merges them, and builds an executable schema
55
+ * Includes BASE_SCHEMA for extend type support
56
+ */
57
+ declare function buildGraphQLSchema(schemaPaths: string[]): Promise<GraphQLSchema | null>;
58
+ //#endregion
59
+ export { BASE_SCHEMA, CreateMergedSchemaOptions, DirectiveWrapper, ModuleConfig, ResolverDefinition, SchemaDefinition, buildGraphQLSchema, createMergedSchema, parse, subscribe, validate };
@@ -0,0 +1,76 @@
1
+ import { loadFederationSupport, warnFederationUnavailable } from "./federation.mjs";
2
+ import { consola as consola$1 } from "consola";
3
+ import { buildSchema, parse, parse as parse$1, print, subscribe, validate } from "graphql";
4
+ import { readFileSync } from "node:fs";
5
+ import { mergeResolvers, mergeTypeDefs } from "@graphql-tools/merge";
6
+ import { makeExecutableSchema } from "@graphql-tools/schema";
7
+ //#region src/core/schema/builder.ts
8
+ /**
9
+ * Create a merged GraphQL schema from schemas, resolvers, and directives
10
+ * Supports Apollo Federation when enabled
11
+ */
12
+ async function createMergedSchema(options) {
13
+ const { schemas, resolvers, directives, moduleConfig } = options;
14
+ try {
15
+ const typeDefs = mergeTypeDefs([schemas.map((schema) => schema.def).join("\n\n")], {
16
+ throwOnConflict: true,
17
+ commentDescriptions: true,
18
+ sort: true
19
+ });
20
+ const mergedResolvers = mergeResolvers(resolvers.map((r) => r.resolver));
21
+ const federationEnabled = moduleConfig.federation?.enabled;
22
+ let schema;
23
+ if (federationEnabled) {
24
+ const buildSubgraph = await loadFederationSupport();
25
+ if (buildSubgraph) schema = buildSubgraph({
26
+ typeDefs: typeof typeDefs === "string" ? parse$1(typeDefs) : typeDefs,
27
+ resolvers: mergedResolvers
28
+ });
29
+ else {
30
+ warnFederationUnavailable();
31
+ schema = makeExecutableSchema({
32
+ typeDefs,
33
+ resolvers: mergedResolvers
34
+ });
35
+ }
36
+ } else schema = makeExecutableSchema({
37
+ typeDefs,
38
+ resolvers: mergedResolvers
39
+ });
40
+ if (directives && directives.length > 0) {
41
+ for (const { directive } of directives) if (directive.transformer) schema = directive.transformer(schema);
42
+ }
43
+ return schema;
44
+ } catch (error) {
45
+ consola$1.error("Schema merge error:", error);
46
+ throw error;
47
+ }
48
+ }
49
+ /**
50
+ * Base schema with empty Query and Mutation types.
51
+ * Required for 'extend type Query' syntax to work.
52
+ * Shared between CLI and Nitro.
53
+ */
54
+ const BASE_SCHEMA = `type Query { _empty: String }
55
+ type Mutation { _empty: String }`;
56
+ /**
57
+ * Build a GraphQL schema from file paths (CLI usage)
58
+ * Reads schema files, merges them, and builds an executable schema
59
+ * Includes BASE_SCHEMA for extend type support
60
+ */
61
+ async function buildGraphQLSchema(schemaPaths) {
62
+ if (schemaPaths.length === 0) return null;
63
+ try {
64
+ const mergedTypeDefs = mergeTypeDefs([BASE_SCHEMA, ...schemaPaths.map((path) => readFileSync(path, "utf-8"))], {
65
+ throwOnConflict: true,
66
+ commentDescriptions: true,
67
+ sort: true
68
+ });
69
+ return buildSchema(typeof mergedTypeDefs === "string" ? mergedTypeDefs : print(mergedTypeDefs));
70
+ } catch (error) {
71
+ consola$1.error("Failed to build GraphQL schema:", error);
72
+ return null;
73
+ }
74
+ }
75
+ //#endregion
76
+ export { BASE_SCHEMA, buildGraphQLSchema, createMergedSchema, parse, subscribe, validate };
@@ -0,0 +1,33 @@
1
+ import { DocumentNode, GraphQLSchema } from "graphql";
2
+
3
+ //#region src/core/schema/federation.d.ts
4
+ /**
5
+ * Module type for buildSubgraphSchema
6
+ */
7
+ interface SubgraphModule {
8
+ typeDefs: DocumentNode;
9
+ resolvers?: Record<string, unknown>;
10
+ }
11
+ /**
12
+ * Type for buildSubgraphSchema function from @apollo/subgraph
13
+ * Accepts either an array of modules or a single options object
14
+ */
15
+ type BuildSubgraphSchemaFn = (modulesOrOptions: SubgraphModule[] | SubgraphModule) => GraphQLSchema;
16
+ /**
17
+ * Dynamically load @apollo/subgraph for federation support.
18
+ * Returns the buildSubgraphSchema function if available, or false if the package is not installed.
19
+ * Result is cached for subsequent calls.
20
+ */
21
+ declare function loadFederationSupport(): Promise<BuildSubgraphSchemaFn | false>;
22
+ /**
23
+ * Log a warning when federation is enabled but @apollo/subgraph is not available.
24
+ * Uses consola logger instead of console.warn for consistent logging.
25
+ */
26
+ declare function warnFederationUnavailable(): void;
27
+ /**
28
+ * Reset the federation support cache.
29
+ * Useful for testing or when the module needs to be reloaded.
30
+ */
31
+ declare function resetFederationCache(): void;
32
+ //#endregion
33
+ export { loadFederationSupport, resetFederationCache, warnFederationUnavailable };
@@ -0,0 +1,38 @@
1
+ import { LOG_TAG } from "../constants.mjs";
2
+ import { consola as consola$1 } from "consola";
3
+ //#region src/core/schema/federation.ts
4
+ const logger = consola$1.withTag(LOG_TAG);
5
+ /**
6
+ * Cached result: function if available, false if not available, null if not checked yet
7
+ */
8
+ let buildSubgraphSchemaCache = null;
9
+ /**
10
+ * Dynamically load @apollo/subgraph for federation support.
11
+ * Returns the buildSubgraphSchema function if available, or false if the package is not installed.
12
+ * Result is cached for subsequent calls.
13
+ */
14
+ async function loadFederationSupport() {
15
+ if (buildSubgraphSchemaCache !== null) return buildSubgraphSchemaCache;
16
+ try {
17
+ buildSubgraphSchemaCache = (await import("@apollo/subgraph")).buildSubgraphSchema;
18
+ } catch {
19
+ buildSubgraphSchemaCache = false;
20
+ }
21
+ return buildSubgraphSchemaCache;
22
+ }
23
+ /**
24
+ * Log a warning when federation is enabled but @apollo/subgraph is not available.
25
+ * Uses consola logger instead of console.warn for consistent logging.
26
+ */
27
+ function warnFederationUnavailable() {
28
+ logger.warn("Federation enabled but @apollo/subgraph not available, falling back to regular schema");
29
+ }
30
+ /**
31
+ * Reset the federation support cache.
32
+ * Useful for testing or when the module needs to be reloaded.
33
+ */
34
+ function resetFederationCache() {
35
+ buildSubgraphSchemaCache = null;
36
+ }
37
+ //#endregion
38
+ export { loadFederationSupport, resetFederationCache, warnFederationUnavailable };
@@ -0,0 +1,3 @@
1
+ import { BASE_SCHEMA, CreateMergedSchemaOptions, DirectiveWrapper, ModuleConfig, ResolverDefinition, SchemaDefinition, buildGraphQLSchema, createMergedSchema, parse, subscribe, validate } from "./builder.mjs";
2
+ import { loadFederationSupport, resetFederationCache, warnFederationUnavailable } from "./federation.mjs";
3
+ export { BASE_SCHEMA, CreateMergedSchemaOptions, DirectiveWrapper, ModuleConfig, ResolverDefinition, SchemaDefinition, buildGraphQLSchema, createMergedSchema, loadFederationSupport, parse, resetFederationCache, subscribe, validate, warnFederationUnavailable };
@@ -0,0 +1,3 @@
1
+ import { loadFederationSupport, resetFederationCache, warnFederationUnavailable } from "./federation.mjs";
2
+ import { BASE_SCHEMA, buildGraphQLSchema, createMergedSchema, parse, subscribe, validate } from "./builder.mjs";
3
+ export { BASE_SCHEMA, buildGraphQLSchema, createMergedSchema, loadFederationSupport, parse, resetFederationCache, subscribe, validate, warnFederationUnavailable };
@@ -0,0 +1,4 @@
1
+ import { CoreServerInstance, CoreServerOptions, ServerFactory } from "./types.mjs";
2
+ import { APOLLO_SANDBOX_CDN, createSandboxResponse, fetchSandboxScript } from "./sandbox.mjs";
3
+ import { BASE_SCHEMA, apolloSandboxHtml, createYogaServer } from "./yoga.mjs";
4
+ export { APOLLO_SANDBOX_CDN, type CoreServerInstance, type CoreServerOptions, type ServerFactory, BASE_SCHEMA as YOGA_BASE_SCHEMA, apolloSandboxHtml, createSandboxResponse, createYogaServer, fetchSandboxScript };
@@ -0,0 +1,3 @@
1
+ import { APOLLO_SANDBOX_CDN, createSandboxResponse, fetchSandboxScript } from "./sandbox.mjs";
2
+ import { BASE_SCHEMA, apolloSandboxHtml, createYogaServer } from "./yoga.mjs";
3
+ export { APOLLO_SANDBOX_CDN, BASE_SCHEMA as YOGA_BASE_SCHEMA, apolloSandboxHtml, createSandboxResponse, createYogaServer, fetchSandboxScript };
@@ -0,0 +1,18 @@
1
+ //#region src/core/server/sandbox.d.ts
2
+ /**
3
+ * Core Sandbox Script Handler
4
+ *
5
+ * Proxies Apollo Sandbox script from CDN with caching.
6
+ * Used by both CLI and Nitro.
7
+ */
8
+ declare const APOLLO_SANDBOX_CDN = "https://embeddable-sandbox.cdn.apollographql.com/_latest/embeddable-sandbox.umd.production.min.js";
9
+ /**
10
+ * Fetch and cache the Apollo Sandbox script
11
+ */
12
+ declare function fetchSandboxScript(): Promise<string>;
13
+ /**
14
+ * Create a Response with the sandbox script
15
+ */
16
+ declare function createSandboxResponse(): Promise<Response>;
17
+ //#endregion
18
+ export { APOLLO_SANDBOX_CDN, createSandboxResponse, fetchSandboxScript };
@@ -0,0 +1,38 @@
1
+ //#region src/core/server/sandbox.ts
2
+ /**
3
+ * Core Sandbox Script Handler
4
+ *
5
+ * Proxies Apollo Sandbox script from CDN with caching.
6
+ * Used by both CLI and Nitro.
7
+ */
8
+ const APOLLO_SANDBOX_CDN = "https://embeddable-sandbox.cdn.apollographql.com/_latest/embeddable-sandbox.umd.production.min.js";
9
+ let cachedScript = null;
10
+ /**
11
+ * Fetch and cache the Apollo Sandbox script
12
+ */
13
+ async function fetchSandboxScript() {
14
+ if (cachedScript) return cachedScript;
15
+ const response = await fetch(APOLLO_SANDBOX_CDN);
16
+ if (!response.ok) throw new Error(`Failed to fetch Apollo Sandbox script: ${response.status}`);
17
+ cachedScript = await response.text();
18
+ return cachedScript;
19
+ }
20
+ /**
21
+ * Create a Response with the sandbox script
22
+ */
23
+ async function createSandboxResponse() {
24
+ try {
25
+ const script = await fetchSandboxScript();
26
+ return new Response(script, { headers: {
27
+ "content-type": "text/javascript; charset=utf-8",
28
+ "cache-control": "public, max-age=2592000, immutable"
29
+ } });
30
+ } catch (error) {
31
+ return new Response(`// Error loading Apollo Sandbox: ${error}`, {
32
+ status: 500,
33
+ headers: { "content-type": "text/javascript; charset=utf-8" }
34
+ });
35
+ }
36
+ }
37
+ //#endregion
38
+ export { APOLLO_SANDBOX_CDN, createSandboxResponse, fetchSandboxScript };
@@ -0,0 +1,54 @@
1
+ import { DirectiveWrapper, ModuleConfig, ResolverDefinition, SchemaDefinition } from "../schema/builder.mjs";
2
+ import { GraphQLSchema } from "graphql";
3
+
4
+ //#region src/core/server/types.d.ts
5
+ /**
6
+ * Security configuration for GraphQL server
7
+ */
8
+ interface CoreSecurityConfig {
9
+ /** Enable GraphQL introspection (default: true in dev, false in prod) */
10
+ introspection?: boolean;
11
+ /** Enable GraphQL playground/sandbox (default: true in dev, false in prod) */
12
+ playground?: boolean;
13
+ /** Mask error messages in responses (default: false in dev, true in prod) */
14
+ maskErrors?: boolean;
15
+ /** Disable field suggestions in error messages */
16
+ disableSuggestions?: boolean;
17
+ }
18
+ /**
19
+ * Options for creating a GraphQL server instance
20
+ */
21
+ interface CoreServerOptions {
22
+ /** Schema definitions (GraphQL SDL strings) */
23
+ schemas: SchemaDefinition[];
24
+ /** Resolver definitions */
25
+ resolvers: ResolverDefinition[];
26
+ /** Directive definitions (optional) */
27
+ directives?: DirectiveWrapper[];
28
+ /** Module configuration (federation, etc.) */
29
+ moduleConfig: ModuleConfig;
30
+ /** GraphQL endpoint path (default: /api/graphql) */
31
+ endpoint?: string;
32
+ /** Security configuration */
33
+ security?: CoreSecurityConfig;
34
+ /** User's imported GraphQL config (from defineGraphQLConfig) */
35
+ importedConfig?: Record<string, unknown>;
36
+ }
37
+ /**
38
+ * GraphQL server instance returned by server factories
39
+ */
40
+ interface CoreServerInstance {
41
+ /**
42
+ * Handle a request using the web standard fetch API
43
+ * Compatible with srvx, Bun, Deno, and Node.js
44
+ */
45
+ fetch: (request: Request, context?: Record<string, unknown>) => Promise<Response>;
46
+ /** The compiled GraphQL schema */
47
+ schema: GraphQLSchema;
48
+ }
49
+ /**
50
+ * Factory function type for creating GraphQL servers
51
+ */
52
+ type ServerFactory = (options: CoreServerOptions) => Promise<CoreServerInstance>;
53
+ //#endregion
54
+ export { CoreSecurityConfig, CoreServerInstance, CoreServerOptions, ServerFactory };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,42 @@
1
+ import { SchemaDefinition } from "../schema/builder.mjs";
2
+ import { CoreServerInstance, CoreServerOptions } from "./types.mjs";
3
+
4
+ //#region src/core/server/yoga.d.ts
5
+ /**
6
+ * Base schema definition for Yoga server
7
+ * Uses shared BASE_SCHEMA string from builder
8
+ */
9
+ declare const BASE_SCHEMA: SchemaDefinition;
10
+ /**
11
+ * Apollo Sandbox HTML template
12
+ * Shared between CLI and Nitro for consistent playground experience
13
+ */
14
+ declare const apolloSandboxHtml = "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <link rel=\"preload\" href=\"/api/graphql/sandbox.js\" as=\"script\">\n</head>\n<body style=\"margin: 0; overflow-x: hidden; overflow-y: hidden\">\n<div id=\"sandbox\" style=\"height:100vh; width:100vw;\"></div>\n<script src=\"/api/graphql/sandbox.js\"></script>\n<script>\nnew window.EmbeddedSandbox({\n target: \"#sandbox\",\n initialEndpoint: window.location.href.replace('/sandbox.js', ''),\n hideCookieToggle: false,\n initialState: {\n includeCookies: true\n }\n});\n</script>\n</body>\n</html>";
15
+ /**
16
+ * Create a GraphQL Yoga server instance
17
+ *
18
+ * This is the core server factory used by both:
19
+ * - Nitro routes (via virtual module imports)
20
+ * - CLI dev server (via file-based loading)
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * // In Nitro route
25
+ * const server = await createYogaServer({
26
+ * schemas, resolvers, directives, moduleConfig,
27
+ * security: moduleConfig.security,
28
+ * importedConfig,
29
+ * })
30
+ *
31
+ * // In CLI
32
+ * const server = await createYogaServer({
33
+ * schemas: await loadSchemas(ctx),
34
+ * resolvers: await loadResolvers(ctx),
35
+ * moduleConfig: { federation: ctx.config.federation },
36
+ * endpoint: '/graphql',
37
+ * })
38
+ * ```
39
+ */
40
+ declare function createYogaServer(options: CoreServerOptions): Promise<CoreServerInstance>;
41
+ //#endregion
42
+ export { BASE_SCHEMA, apolloSandboxHtml, createYogaServer };