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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/README.md +441 -27
  2. package/dist/cli/commands/generate.d.mts +26 -0
  3. package/dist/cli/commands/generate.mjs +196 -0
  4. package/dist/cli/commands/index.d.mts +4 -0
  5. package/dist/cli/commands/index.mjs +5 -0
  6. package/dist/cli/commands/init.d.mts +46 -0
  7. package/dist/cli/commands/init.mjs +195 -0
  8. package/dist/cli/commands/validate.d.mts +10 -0
  9. package/dist/cli/commands/validate.mjs +69 -0
  10. package/dist/cli/completions.d.mts +7 -0
  11. package/dist/cli/completions.mjs +34 -0
  12. package/dist/cli/config.d.mts +75 -0
  13. package/dist/cli/config.mjs +20 -0
  14. package/dist/cli/index.d.mts +24 -0
  15. package/dist/cli/index.mjs +253 -0
  16. package/dist/core/codegen/client.d.mts +23 -0
  17. package/dist/core/codegen/client.mjs +150 -0
  18. package/dist/core/codegen/document-loader.d.mts +10 -0
  19. package/dist/core/codegen/document-loader.mjs +18 -0
  20. package/dist/core/codegen/index.d.mts +8 -0
  21. package/dist/core/codegen/index.mjs +9 -0
  22. package/dist/core/codegen/plugin.d.mts +20 -0
  23. package/dist/core/codegen/plugin.mjs +30 -0
  24. package/dist/core/codegen/runtime.d.mts +20 -0
  25. package/dist/core/codegen/runtime.mjs +60 -0
  26. package/dist/core/codegen/schema-loader.d.mts +28 -0
  27. package/dist/core/codegen/schema-loader.mjs +128 -0
  28. package/dist/core/codegen/server.d.mts +28 -0
  29. package/dist/core/codegen/server.mjs +143 -0
  30. package/dist/core/codegen/validation.d.mts +13 -0
  31. package/dist/core/codegen/validation.mjs +96 -0
  32. package/dist/core/config.d.mts +50 -0
  33. package/dist/core/config.mjs +82 -0
  34. package/dist/core/constants.d.mts +188 -0
  35. package/dist/core/constants.mjs +210 -0
  36. package/dist/core/index.d.mts +32 -0
  37. package/dist/core/index.mjs +26 -0
  38. package/dist/core/scanning/ast-scanner.d.mts +23 -0
  39. package/dist/core/scanning/ast-scanner.mjs +103 -0
  40. package/dist/core/scanning/common.d.mts +37 -0
  41. package/dist/core/scanning/common.mjs +60 -0
  42. package/dist/core/scanning/directives.d.mts +10 -0
  43. package/dist/core/scanning/directives.mjs +29 -0
  44. package/dist/core/scanning/documents.d.mts +21 -0
  45. package/dist/core/scanning/documents.mjs +43 -0
  46. package/dist/core/scanning/index.d.mts +7 -0
  47. package/dist/core/scanning/index.mjs +8 -0
  48. package/dist/core/scanning/resolvers.d.mts +10 -0
  49. package/dist/core/scanning/resolvers.mjs +58 -0
  50. package/dist/core/scanning/schemas.d.mts +14 -0
  51. package/dist/core/scanning/schemas.mjs +64 -0
  52. package/dist/core/schema/builder.d.mts +53 -0
  53. package/dist/core/schema/builder.mjs +70 -0
  54. package/dist/core/schema/federation.d.mts +34 -0
  55. package/dist/core/schema/federation.mjs +40 -0
  56. package/dist/core/schema/index.d.mts +3 -0
  57. package/dist/core/schema/index.mjs +4 -0
  58. package/dist/core/types/adapter.d.mts +58 -0
  59. package/dist/core/types/codegen.d.mts +133 -0
  60. package/dist/core/types/config.d.mts +212 -0
  61. package/dist/core/types/config.mjs +1 -0
  62. package/dist/{utils/define.d.ts → core/types/define.d.mts} +3 -30
  63. package/dist/core/types/define.mjs +1 -0
  64. package/dist/core/types/index.d.mts +5 -0
  65. package/dist/core/types/index.mjs +1 -0
  66. package/dist/core/types/scanning.d.mts +69 -0
  67. package/dist/core/types/scanning.mjs +1 -0
  68. package/dist/{utils/directive-parser.d.ts → core/utils/directive-parser.d.mts} +21 -4
  69. package/dist/{utils/directive-parser.js → core/utils/directive-parser.mjs} +25 -34
  70. package/dist/core/utils/errors.d.mts +77 -0
  71. package/dist/core/utils/errors.mjs +93 -0
  72. package/dist/core/utils/file-io.d.mts +24 -0
  73. package/dist/core/utils/file-io.mjs +47 -0
  74. package/dist/core/utils/imports.d.mts +15 -0
  75. package/dist/core/utils/imports.mjs +25 -0
  76. package/dist/core/utils/index.d.mts +7 -0
  77. package/dist/core/utils/index.mjs +8 -0
  78. package/dist/core/utils/logger.d.mts +19 -0
  79. package/dist/core/utils/logger.mjs +38 -0
  80. package/dist/core/utils/ofetch-templates.d.mts +30 -0
  81. package/dist/core/utils/ofetch-templates.mjs +135 -0
  82. package/dist/core/validation/external-services.d.mts +11 -0
  83. package/dist/core/validation/external-services.mjs +34 -0
  84. package/dist/core/validation/index.d.mts +2 -0
  85. package/dist/core/validation/index.mjs +3 -0
  86. package/dist/define.d.mts +294 -0
  87. package/dist/define.mjs +323 -0
  88. package/dist/index.d.mts +6 -0
  89. package/dist/index.mjs +6 -0
  90. package/dist/nitro/adapter.d.mts +30 -0
  91. package/dist/nitro/adapter.mjs +97 -0
  92. package/dist/{utils/apollo.d.ts → nitro/apollo.d.mts} +3 -3
  93. package/dist/nitro/apollo.mjs +59 -0
  94. package/dist/nitro/codegen.d.mts +19 -0
  95. package/dist/nitro/codegen.mjs +141 -0
  96. package/dist/nitro/config.d.mts +52 -0
  97. package/dist/nitro/config.mjs +58 -0
  98. package/dist/nitro/index.d.mts +46 -0
  99. package/dist/nitro/index.mjs +65 -0
  100. package/dist/nitro/paths.d.mts +54 -0
  101. package/dist/nitro/paths.mjs +93 -0
  102. package/dist/nitro/rollup.d.mts +6 -0
  103. package/dist/nitro/rollup.mjs +95 -0
  104. package/dist/nitro/routes/apollo-server.d.mts +6 -0
  105. package/dist/nitro/routes/apollo-server.mjs +71 -0
  106. package/dist/nitro/routes/debug-template.d.mts +15 -0
  107. package/dist/nitro/routes/debug-template.mjs +385 -0
  108. package/dist/nitro/routes/debug.d.mts +55 -0
  109. package/dist/nitro/routes/debug.mjs +102 -0
  110. package/dist/nitro/routes/graphql-yoga.d.mts +6 -0
  111. package/dist/nitro/routes/graphql-yoga.mjs +62 -0
  112. package/dist/nitro/routes/health.d.mts +10 -0
  113. package/dist/{routes/health.js → nitro/routes/health.mjs} +4 -3
  114. package/dist/nitro/setup/file-watcher.d.mts +16 -0
  115. package/dist/nitro/setup/file-watcher.mjs +80 -0
  116. package/dist/nitro/setup/logging.d.mts +17 -0
  117. package/dist/nitro/setup/logging.mjs +66 -0
  118. package/dist/nitro/setup/rollup-integration.d.mts +16 -0
  119. package/dist/nitro/setup/rollup-integration.mjs +90 -0
  120. package/dist/nitro/setup/routes.d.mts +10 -0
  121. package/dist/nitro/setup/routes.mjs +35 -0
  122. package/dist/nitro/setup/ts-config.d.mts +11 -0
  123. package/dist/nitro/setup/ts-config.mjs +69 -0
  124. package/dist/nitro/setup.d.mts +12 -0
  125. package/dist/nitro/setup.mjs +231 -0
  126. package/dist/nitro/types.d.mts +378 -0
  127. package/dist/nitro/types.mjs +1 -0
  128. package/dist/nitro/virtual/generators.d.mts +31 -0
  129. package/dist/nitro/virtual/generators.mjs +193 -0
  130. package/dist/nitro/virtual/stubs.d.mts +20 -0
  131. package/dist/nitro/virtual/stubs.mjs +31 -0
  132. package/dist/{ecosystem/nuxt.d.ts → nuxt.d.mts} +1 -1
  133. package/dist/nuxt.mjs +109 -0
  134. package/dist/{graphql/server.d.ts → stubs/index.d.mts} +5 -1
  135. package/dist/stubs/index.mjs +1 -0
  136. package/package.json +97 -78
  137. package/dist/ecosystem/nuxt.js +0 -67
  138. package/dist/graphql/index.d.ts +0 -5
  139. package/dist/index.d.ts +0 -8
  140. package/dist/index.js +0 -264
  141. package/dist/rollup.js +0 -119
  142. package/dist/routes/apollo-server.d.ts +0 -6
  143. package/dist/routes/apollo-server.js +0 -89
  144. package/dist/routes/graphql-yoga.d.ts +0 -6
  145. package/dist/routes/graphql-yoga.js +0 -91
  146. package/dist/routes/health.d.ts +0 -6
  147. package/dist/types/index.d.ts +0 -128
  148. package/dist/types/standard-schema.d.ts +0 -59
  149. package/dist/utils/apollo.js +0 -61
  150. package/dist/utils/client-codegen.d.ts +0 -38
  151. package/dist/utils/client-codegen.js +0 -290
  152. package/dist/utils/define.js +0 -57
  153. package/dist/utils/index.d.ts +0 -39
  154. package/dist/utils/index.js +0 -250
  155. package/dist/utils/server-codegen.d.ts +0 -7
  156. package/dist/utils/server-codegen.js +0 -136
  157. package/dist/utils/type-generation.d.ts +0 -7
  158. package/dist/utils/type-generation.js +0 -287
  159. package/dist/vite.d.ts +0 -25
  160. package/dist/vite.js +0 -40
  161. /package/dist/{graphql/index.js → core/types/adapter.mjs} +0 -0
  162. /package/dist/{graphql/server.js → core/types/codegen.mjs} +0 -0
@@ -1,67 +0,0 @@
1
- import { existsSync, mkdirSync, writeFileSync } from "node:fs";
2
- import { join, resolve } from "pathe";
3
- import { defineNuxtModule, getLayerDirectories } from "@nuxt/kit";
4
-
5
- //#region src/ecosystem/nuxt.ts
6
- var nuxt_default = defineNuxtModule({
7
- meta: {
8
- name: "nitro-graphql-nuxt",
9
- configKey: "nitro-graphql-nuxt",
10
- compatibility: { nuxt: ">=3.16.0" }
11
- },
12
- setup: async (_options, nuxt) => {
13
- nuxt.hooks.hook("prepare:types", (options) => {
14
- options.references.push({ path: "types/nitro-graphql-client.d.ts" });
15
- options.tsConfig ??= {};
16
- options.tsConfig.compilerOptions ??= {};
17
- options.tsConfig.compilerOptions.paths ??= {};
18
- options.tsConfig.compilerOptions.paths["#graphql/client"] = ["./types/nitro-graphql-client.d.ts"];
19
- const externalServices$1 = nuxt.options.nitro?.graphql?.externalServices || [];
20
- for (const service of externalServices$1) {
21
- options.references.push({ path: `types/nitro-graphql-client-${service.name}.d.ts` });
22
- options.tsConfig.compilerOptions.paths[`#graphql/client/${service.name}`] = [`./types/nitro-graphql-client-${service.name}.d.ts`];
23
- }
24
- options.tsConfig.include = options.tsConfig.include || [];
25
- options.tsConfig.include.push("./types/nitro-graphql-client.d.ts");
26
- for (const service of externalServices$1) options.tsConfig.include.push(`./types/nitro-graphql-client-${service.name}.d.ts`);
27
- });
28
- nuxt.options.alias = nuxt.options.alias || {};
29
- nuxt.options.alias["#graphql/client"] = join(nuxt.options.buildDir, "types/nitro-graphql-client.d.ts");
30
- const externalServices = nuxt.options.nitro?.graphql?.externalServices || [];
31
- for (const service of externalServices) nuxt.options.alias[`#graphql/client/${service.name}`] = join(nuxt.options.buildDir, `types/nitro-graphql-client-${service.name}.d.ts`);
32
- nuxt.hook("imports:dirs", (dirs) => {
33
- const graphqlServerPath = nuxt.options.nitro?.graphql?.serverDir || resolve(nuxt.options.srcDir, "graphql");
34
- dirs.push(graphqlServerPath);
35
- });
36
- nuxt.hook("nitro:config", async (nitroConfig) => {
37
- const clientDir = join(nuxt.options.buildDir, "graphql");
38
- const layerDirs = await getLayerDirectories(nuxt);
39
- const layerDirectories = layerDirs.map((layer) => layer.root.replace(/\/$/, "")).filter((root) => root !== nuxt.options.rootDir);
40
- const layerServerDirs = layerDirs.filter((layer) => layer.root !== `${nuxt.options.rootDir}/`).map((layer) => layer.server?.replace(/\/$/, "")).filter(Boolean);
41
- const layerAppDirs = layerDirs.filter((layer) => layer.root !== `${nuxt.options.rootDir}/`).map((layer) => layer.app?.replace(/\/$/, "")).filter(Boolean);
42
- if (!nitroConfig.graphql) nitroConfig.graphql = {};
43
- nitroConfig.graphql.layerDirectories = layerDirectories;
44
- nitroConfig.graphql.layerServerDirs = layerServerDirs;
45
- nitroConfig.graphql.layerAppDirs = layerAppDirs;
46
- if (!existsSync(resolve(nuxt.options.rootDir, "app/graphql"))) {
47
- const defaultDir = join(clientDir, "default");
48
- if (!existsSync(defaultDir)) mkdirSync(defaultDir, { recursive: true });
49
- const sampleQueryFile = join(defaultDir, "queries.graphql");
50
- if (!existsSync(sampleQueryFile)) writeFileSync(sampleQueryFile, `# Example GraphQL queries
51
- # Add your GraphQL queries here
52
-
53
- # query GetUser($id: ID!) {
54
- # user(id: $id) {
55
- # id
56
- # name
57
- # email
58
- # }
59
- # }
60
- `, "utf-8");
61
- }
62
- });
63
- }
64
- });
65
-
66
- //#endregion
67
- export { nuxt_default as default };
@@ -1,5 +0,0 @@
1
- //#region src/graphql/index.d.ts
2
- interface StandardSchemaV1 extends Record<string, any> {}
3
- interface ResolversTypes extends Record<string, any> {}
4
- //#endregion
5
- export { ResolversTypes, StandardSchemaV1 };
package/dist/index.d.ts DELETED
@@ -1,8 +0,0 @@
1
- import { StandardSchemaV1 } from "./types/standard-schema.js";
2
- import { CodegenClientConfig, CodegenServerConfig, ExternalGraphQLService, FederationConfig, GenImport, GenericSdkConfig, NitroGraphQLOptions } from "./types/index.js";
3
- import * as nitro_types0 from "nitro/types";
4
-
5
- //#region src/index.d.ts
6
- declare const _default: nitro_types0.NitroModule;
7
- //#endregion
8
- export { CodegenClientConfig, CodegenServerConfig, ExternalGraphQLService, FederationConfig, GenImport, GenericSdkConfig, NitroGraphQLOptions, StandardSchemaV1, _default as default };
package/dist/index.js DELETED
@@ -1,264 +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 { clientTypeGeneration, serverTypeGeneration } from "./utils/type-generation.js";
4
- import { rollupConfig } from "./rollup.js";
5
- import { existsSync, mkdirSync, writeFileSync } from "node:fs";
6
- import { fileURLToPath } from "node:url";
7
- import { watch } from "chokidar";
8
- import consola from "consola";
9
- import defu from "defu";
10
- import { dirname, join, relative, resolve } from "pathe";
11
-
12
- //#region src/index.ts
13
- var src_default = defineNitroModule({
14
- name: "nitro-graphql",
15
- async setup(nitro) {
16
- if (!nitro.options.graphql?.framework) consola.warn("No GraphQL framework specified. Please set graphql.framework to \"graphql-yoga\" or \"apollo-server\".");
17
- if (nitro.options.graphql?.externalServices?.length) {
18
- const validationErrors = validateExternalServices(nitro.options.graphql.externalServices);
19
- if (validationErrors.length > 0) {
20
- consola.error("External services configuration errors:");
21
- for (const error of validationErrors) consola.error(` - ${error}`);
22
- throw new Error("Invalid external services configuration");
23
- }
24
- consola.info(`Configured ${nitro.options.graphql.externalServices.length} external GraphQL services`);
25
- }
26
- nitro.graphql ||= {
27
- buildDir: "",
28
- watchDirs: [],
29
- clientDir: "",
30
- serverDir: resolve(nitro.options.rootDir, "server", "graphql"),
31
- dir: {
32
- build: relative(nitro.options.rootDir, nitro.options.buildDir),
33
- client: "graphql",
34
- server: "server"
35
- }
36
- };
37
- nitro.hooks.hook("rollup:before", (_, rollupConfig$1) => {
38
- rollupConfig$1.external = rollupConfig$1.external || [];
39
- const codegenExternals = ["oxc-parser", "@oxc-parser"];
40
- if (Array.isArray(rollupConfig$1.external)) rollupConfig$1.external.push(...codegenExternals);
41
- else if (typeof rollupConfig$1.external === "function") {
42
- const originalExternal = rollupConfig$1.external;
43
- rollupConfig$1.external = (id, parent, isResolved) => {
44
- if (codegenExternals.some((external) => id.includes(external))) return true;
45
- return originalExternal(id, parent, isResolved);
46
- };
47
- }
48
- });
49
- nitro.options.runtimeConfig.graphql = defu(nitro.options.runtimeConfig.graphql || {}, {
50
- endpoint: {
51
- graphql: "/api/graphql",
52
- healthCheck: "/api/graphql/health"
53
- },
54
- playground: true
55
- });
56
- if (nitro.options.graphql?.federation?.enabled) consola.info(`Apollo Federation enabled for service: ${nitro.options.graphql.federation.serviceName || "unnamed"}`);
57
- const graphqlBuildDir = resolve(nitro.options.buildDir, "graphql");
58
- nitro.graphql.buildDir = graphqlBuildDir;
59
- const watchDirs = [];
60
- switch (nitro.options.framework.name) {
61
- case "nuxt": {
62
- if (!nitro.graphql.clientDir) {
63
- nitro.graphql.clientDir = resolve(nitro.options.rootDir, "app", "graphql");
64
- nitro.graphql.dir.client = "app/graphql";
65
- }
66
- if (!nitro.options.graphql?.serverDir) nitro.graphql.serverDir = resolve(nitro.options.rootDir, "server", "graphql");
67
- watchDirs.push(nitro.graphql.clientDir);
68
- const layerServerDirs = getLayerServerDirectories(nitro);
69
- const layerAppDirs = getLayerAppDirectories(nitro);
70
- for (const layerServerDir of layerServerDirs) watchDirs.push(join(layerServerDir, "graphql"));
71
- for (const layerAppDir of layerAppDirs) watchDirs.push(join(layerAppDir, "graphql"));
72
- break;
73
- }
74
- case "nitro":
75
- if (!nitro.options.graphql?.serverDir) nitro.graphql.serverDir = resolve(nitro.options.rootDir, "server", "graphql");
76
- nitro.graphql.clientDir = resolve(nitro.options.rootDir, "graphql");
77
- nitro.graphql.dir.client = "graphql";
78
- watchDirs.push(nitro.graphql.clientDir);
79
- watchDirs.push(nitro.graphql.serverDir);
80
- break;
81
- default:
82
- }
83
- if (nitro.options.graphql?.externalServices?.length) {
84
- for (const service of nitro.options.graphql.externalServices) if (service.documents?.length) for (const pattern of service.documents) {
85
- if (!pattern) continue;
86
- const baseDir = pattern.split("**")[0]?.replace(/\/$/, "") || ".";
87
- const resolvedDir = resolve(nitro.options.rootDir, baseDir);
88
- if (!watchDirs.includes(resolvedDir)) watchDirs.push(resolvedDir);
89
- }
90
- }
91
- const watcher = watch(watchDirs, {
92
- persistent: true,
93
- ignoreInitial: true,
94
- ignored: [...nitro.options.ignore, ...generateLayerIgnorePatterns(nitro)]
95
- }).on("all", async (_, path) => {
96
- if (path.endsWith(".graphql") || path.endsWith(".gql")) if (path.includes(nitro.graphql.serverDir) || path.includes("server/graphql") || path.includes("server\\graphql")) {
97
- await serverTypeGeneration(nitro);
98
- await clientTypeGeneration(nitro);
99
- await nitro.hooks.callHook("dev:reload");
100
- } else await clientTypeGeneration(nitro);
101
- });
102
- nitro.hooks.hook("close", () => {
103
- watcher.close();
104
- });
105
- const tsconfigDir = dirname(resolve(nitro.options.buildDir, nitro.options.typescript.tsconfigPath));
106
- const typesDir = resolve(nitro.options.buildDir, "types");
107
- nitro.scanSchemas = await scanSchemas(nitro);
108
- nitro.scanDocuments = await scanDocs(nitro);
109
- nitro.scanResolvers = await scanResolvers(nitro);
110
- const directives = await scanDirectives(nitro);
111
- nitro.scanDirectives = directives;
112
- await generateDirectiveSchemas(nitro, directives);
113
- nitro.hooks.hook("dev:start", async () => {
114
- nitro.scanSchemas = await scanSchemas(nitro);
115
- nitro.scanResolvers = await scanResolvers(nitro);
116
- const directives$1 = await scanDirectives(nitro);
117
- nitro.scanDirectives = directives$1;
118
- await generateDirectiveSchemas(nitro, directives$1);
119
- nitro.scanDocuments = await scanDocs(nitro);
120
- });
121
- await rollupConfig(nitro);
122
- await serverTypeGeneration(nitro);
123
- await clientTypeGeneration(nitro);
124
- nitro.hooks.hook("close", async () => {
125
- await serverTypeGeneration(nitro);
126
- await clientTypeGeneration(nitro);
127
- });
128
- const runtime = fileURLToPath(new URL("routes", import.meta.url));
129
- const methods = [
130
- "GET",
131
- "POST",
132
- "OPTIONS"
133
- ];
134
- if (nitro.options.graphql?.framework === "graphql-yoga") for (const method of methods) nitro.options.handlers.push({
135
- route: nitro.options.runtimeConfig.graphql?.endpoint?.graphql || "/api/graphql",
136
- handler: join(runtime, "graphql-yoga"),
137
- method
138
- });
139
- if (nitro.options.graphql?.framework === "apollo-server") for (const method of methods) nitro.options.handlers.push({
140
- route: nitro.options.runtimeConfig.graphql?.endpoint?.graphql || "/api/graphql",
141
- handler: join(runtime, "apollo-server"),
142
- method
143
- });
144
- nitro.options.handlers.push({
145
- route: nitro.options.runtimeConfig.graphql?.endpoint?.healthCheck || "/api/graphql/health",
146
- handler: join(runtime, "health"),
147
- method: "GET"
148
- });
149
- if (nitro.options.imports) {
150
- nitro.options.imports.presets ??= [];
151
- nitro.options.imports.presets.push({
152
- from: fileURLToPath(new URL("utils/define", import.meta.url)),
153
- imports: [
154
- "defineResolver",
155
- "defineMutation",
156
- "defineQuery",
157
- "defineSubscription",
158
- "defineType",
159
- "defineGraphQLConfig",
160
- "defineSchema",
161
- "defineDirective"
162
- ]
163
- });
164
- }
165
- nitro.hooks.hook("rollup:before", (_, rollupConfig$1) => {
166
- const manualChunks = rollupConfig$1.output?.manualChunks;
167
- const chunkFiles = rollupConfig$1.output?.chunkFileNames;
168
- if (!rollupConfig$1.output.inlineDynamicImports) rollupConfig$1.output.manualChunks = (id, meta) => {
169
- if (id.endsWith(".graphql") || id.endsWith(".gql")) return "schemas";
170
- if (id.endsWith(".resolver.ts")) return "resolvers";
171
- if (typeof manualChunks === "function") return manualChunks(id, meta);
172
- };
173
- rollupConfig$1.output.chunkFileNames = (chunkInfo) => {
174
- if (chunkInfo.moduleIds && chunkInfo.moduleIds.some((id) => id.endsWith(".graphql") || id.endsWith(".resolver.ts") || id.endsWith(".gql"))) return `chunks/graphql/[name].mjs`;
175
- if (typeof chunkFiles === "function") return chunkFiles(chunkInfo);
176
- return `chunks/_/[name].mjs`;
177
- };
178
- });
179
- nitro.options.typescript.strict = true;
180
- nitro.hooks.hook("types:extend", (types) => {
181
- types.tsConfig ||= {};
182
- types.tsConfig.compilerOptions ??= {};
183
- types.tsConfig.compilerOptions.paths ??= {};
184
- types.tsConfig.compilerOptions.paths["#graphql/server"] = [relativeWithDot(tsconfigDir, join(typesDir, "nitro-graphql-server.d.ts"))];
185
- types.tsConfig.compilerOptions.paths["#graphql/client"] = [relativeWithDot(tsconfigDir, join(typesDir, "nitro-graphql-client.d.ts"))];
186
- types.tsConfig.compilerOptions.paths["#graphql/schema"] = [relativeWithDot(tsconfigDir, join(nitro.graphql.serverDir, "schema.ts"))];
187
- 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`))];
188
- types.tsConfig.include = types.tsConfig.include || [];
189
- 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")));
190
- 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`)));
191
- });
192
- if (nitro.options.framework?.name === "nuxt" && nitro.options.graphql?.externalServices?.length) nitro.hooks.hook("build:before", () => {
193
- const nuxtOptions = nitro._nuxt?.options;
194
- if (nuxtOptions) nuxtOptions.nitroGraphqlExternalServices = nitro.options.graphql?.externalServices || [];
195
- });
196
- if (!existsSync(join(nitro.options.rootDir, "graphql.config.ts"))) {
197
- const schemaPath = relativeWithDot(nitro.options.rootDir, resolve(nitro.graphql.buildDir, "schema.graphql"));
198
- const documentsPath = relativeWithDot(nitro.options.rootDir, resolve(nitro.graphql.clientDir, "**/*.{graphql,js,ts,jsx,tsx}"));
199
- writeFileSync(join(nitro.options.rootDir, "graphql.config.ts"), `
200
- import type { IGraphQLConfig } from 'graphql-config'
201
-
202
- export default <IGraphQLConfig> {
203
- projects: {
204
- default: {
205
- schema: [
206
- '${schemaPath}',
207
- ],
208
- documents: [
209
- '${documentsPath}',
210
- ],
211
- },
212
- },
213
- }`, "utf-8");
214
- }
215
- if (!existsSync(nitro.graphql.serverDir)) mkdirSync(nitro.graphql.serverDir, { recursive: true });
216
- if (!existsSync(join(nitro.graphql.serverDir, "schema.ts"))) writeFileSync(join(nitro.graphql.serverDir, "schema.ts"), `
217
- import { defineSchema } from 'nitro-graphql/utils/define'
218
-
219
- export default defineSchema({
220
-
221
- })
222
- `, "utf-8");
223
- if (!existsSync(join(nitro.graphql.serverDir, "config.ts"))) writeFileSync(join(nitro.graphql.serverDir, "config.ts"), `// Example GraphQL config file please change it to your needs
224
- // import * as tables from '../drizzle/schema/index'
225
- // import { useDatabase } from '../utils/useDb'
226
- import { defineGraphQLConfig } from 'nitro-graphql/utils/define'
227
-
228
- export default defineGraphQLConfig({
229
- // graphql-yoga example config
230
- // context: () => {
231
- // return {
232
- // context: {
233
- // useDatabase,
234
- // tables,
235
- // },
236
- // }
237
- // },
238
- })
239
- `, "utf-8");
240
- if (!existsSync(join(nitro.graphql.serverDir, "context.ts"))) writeFileSync(join(nitro.graphql.serverDir, "context.ts"), `// Example context definition - please change it to your needs
241
- // import type { Database } from '../utils/useDb'
242
-
243
- declare module 'h3' {
244
- interface H3EventContext {
245
- // Add your custom context properties here
246
- // useDatabase: () => Database
247
- // tables: typeof import('../drizzle/schema')
248
- // auth?: {
249
- // user?: {
250
- // id: string
251
- // role: 'admin' | 'user'
252
- // }
253
- // }
254
- }
255
- }`, "utf-8");
256
- if (existsSync(join(nitro.graphql.serverDir, "context.d.ts"))) {
257
- consola.warn("nitro-graphql: Found context.d.ts file. Please rename it to context.ts for the new structure.");
258
- consola.info("The context file should now be context.ts instead of context.d.ts");
259
- }
260
- }
261
- });
262
-
263
- //#endregion
264
- export { src_default as default };
package/dist/rollup.js DELETED
@@ -1,119 +0,0 @@
1
- import { getImportId, scanGraphql } from "./utils/index.js";
2
- import { clientTypeGeneration, serverTypeGeneration } from "./utils/type-generation.js";
3
- import { resolve } from "pathe";
4
- import { readFile } from "node:fs/promises";
5
- import { parse } from "graphql";
6
- import { genImport } from "knitwork";
7
-
8
- //#region src/rollup.ts
9
- async function rollupConfig(app) {
10
- virtualSchemas(app);
11
- virtualResolvers(app);
12
- virtualDirectives(app);
13
- getGraphQLConfig(app);
14
- virtualModuleConfig(app);
15
- app.hooks.hook("rollup:before", (nitro, rollupConfig$1) => {
16
- rollupConfig$1.plugins = rollupConfig$1.plugins || [];
17
- const { include = /\.(graphql|gql)$/i, exclude, validate = false } = app.options.graphql?.loader || {};
18
- if (Array.isArray(rollupConfig$1.plugins)) {
19
- rollupConfig$1.plugins.push({
20
- name: "nitro-graphql",
21
- enforce: "pre",
22
- resolveId(id) {
23
- if (/\.(graphql|gql)$/i.test(id)) return null;
24
- },
25
- async load(id) {
26
- if (exclude?.test?.(id)) return null;
27
- if (!include.test(id)) return null;
28
- try {
29
- const content = await readFile(id, "utf-8");
30
- if (validate) parse(content);
31
- return `export default ${JSON.stringify(content)}`;
32
- } catch (error) {
33
- if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") return null;
34
- const message = error instanceof Error ? error.message : String(error);
35
- this.error(`Failed to read GraphQL file ${id}: ${message}`);
36
- }
37
- }
38
- });
39
- rollupConfig$1.plugins.push({
40
- name: "nitro-graphql-watcher",
41
- enforce: "pre",
42
- async buildStart() {
43
- const graphqlFiles = await scanGraphql(nitro);
44
- for (const file of graphqlFiles) this.addWatchFile(file);
45
- }
46
- });
47
- }
48
- });
49
- app.hooks.hook("dev:reload", async () => {
50
- await serverTypeGeneration(app);
51
- await clientTypeGeneration(app);
52
- });
53
- }
54
- function virtualSchemas(app) {
55
- const getSchemas = () => [...app.scanSchemas, ...app.options.graphql?.typedefs ?? []];
56
- app.options.virtual ??= {};
57
- app.options.virtual["#nitro-internal-virtual/server-schemas"] = () => {
58
- const imports = getSchemas();
59
- return `
60
- ${imports.map((handler) => `import ${getImportId(handler)} from '${handler}';`).join("\n")}
61
-
62
- export const schemas = [
63
- ${imports.map((h) => `{ def: ${getImportId(h)} }`).join(",\n")}
64
- ];
65
- `;
66
- };
67
- }
68
- function virtualResolvers(app) {
69
- const getResolvers = () => [...app.scanResolvers];
70
- app.options.virtual ??= {};
71
- app.options.virtual["#nitro-internal-virtual/server-resolvers"] = () => {
72
- const imports = getResolvers();
73
- const importsContent = imports.map(({ specifier, imports: imports$1, options }) => genImport(specifier, imports$1, options));
74
- const data = imports.map(({ imports: imports$1 }) => imports$1.map((i) => `{ resolver: ${i.as} }`).join(",\n")).filter(Boolean).join(",\n");
75
- return [
76
- ...importsContent,
77
- "export const resolvers = [",
78
- data,
79
- "]",
80
- ""
81
- ].join("\n");
82
- };
83
- }
84
- function virtualDirectives(app) {
85
- const getDirectives = () => app.scanDirectives || [];
86
- app.options.virtual ??= {};
87
- app.options.virtual["#nitro-internal-virtual/server-directives"] = () => {
88
- const imports = getDirectives();
89
- const importsContent = imports.map(({ specifier, imports: imports$1, options }) => genImport(specifier, imports$1, options));
90
- const data = imports.map(({ imports: imports$1 }) => imports$1.map((i) => `{ directive: ${i.as} }`).join(",\n")).filter(Boolean).join(",\n");
91
- return [
92
- ...importsContent,
93
- "export const directives = [",
94
- data,
95
- "]",
96
- ""
97
- ].join("\n");
98
- };
99
- }
100
- function getGraphQLConfig(app) {
101
- const configPath = resolve(app.graphql.serverDir, "config.ts");
102
- app.options.virtual ??= {};
103
- app.options.virtual["#nitro-internal-virtual/graphql-config"] = () => {
104
- return `import config from '${configPath}'
105
- const importedConfig = config
106
- export { importedConfig }
107
- `;
108
- };
109
- }
110
- function virtualModuleConfig(app) {
111
- app.options.virtual ??= {};
112
- app.options.virtual["#nitro-internal-virtual/module-config"] = () => {
113
- const moduleConfig = app.options.graphql || {};
114
- return `export const moduleConfig = ${JSON.stringify(moduleConfig, null, 2)};`;
115
- };
116
- }
117
-
118
- //#endregion
119
- export { rollupConfig };
@@ -1,6 +0,0 @@
1
- import * as h33 from "h3";
2
-
3
- //#region src/routes/apollo-server.d.ts
4
- declare const _default: h33.EventHandler<h33.EventHandlerRequest, unknown>;
5
- //#endregion
6
- export { _default as default };
@@ -1,89 +0,0 @@
1
- import { consola as consola$1 } from "consola";
2
- import defu from "defu";
3
- import { parse } from "graphql";
4
- import { mergeResolvers, mergeTypeDefs } from "@graphql-tools/merge";
5
- import { importedConfig } from "#nitro-internal-virtual/graphql-config";
6
- import { moduleConfig } from "#nitro-internal-virtual/module-config";
7
- import { directives } from "#nitro-internal-virtual/server-directives";
8
- import { resolvers } from "#nitro-internal-virtual/server-resolvers";
9
- import { schemas } from "#nitro-internal-virtual/server-schemas";
10
- import { ApolloServer } from "@apollo/server";
11
- import { ApolloServerPluginLandingPageLocalDefault } from "@apollo/server/plugin/landingPage/default";
12
- import { makeExecutableSchema } from "@graphql-tools/schema";
13
- import { defineEventHandler } from "h3";
14
- import { startServerAndCreateH3Handler } from "nitro-graphql/utils/apollo";
15
-
16
- //#region src/routes/apollo-server.ts
17
- let buildSubgraphSchema = null;
18
- async function loadFederationSupport() {
19
- if (buildSubgraphSchema !== null) return buildSubgraphSchema;
20
- try {
21
- buildSubgraphSchema = (await import("@apollo/subgraph")).buildSubgraphSchema;
22
- } catch {
23
- buildSubgraphSchema = false;
24
- }
25
- return buildSubgraphSchema;
26
- }
27
- async function createMergedSchema() {
28
- try {
29
- const typeDefs = mergeTypeDefs([schemas.map((schema$1) => schema$1.def).join("\n\n")], {
30
- throwOnConflict: true,
31
- commentDescriptions: true,
32
- sort: true
33
- });
34
- const mergedResolvers = mergeResolvers(resolvers.map((r) => r.resolver));
35
- const federationEnabled = moduleConfig.federation?.enabled;
36
- let schema;
37
- if (federationEnabled) {
38
- const buildSubgraph = await loadFederationSupport();
39
- if (buildSubgraph) schema = buildSubgraph({
40
- typeDefs: typeof typeDefs === "string" ? parse(typeDefs) : typeDefs,
41
- resolvers: mergedResolvers
42
- });
43
- else {
44
- console.warn("Federation enabled but @apollo/subgraph not available, falling back to regular schema");
45
- schema = makeExecutableSchema({
46
- typeDefs,
47
- resolvers: mergedResolvers
48
- });
49
- }
50
- } else schema = makeExecutableSchema({
51
- typeDefs,
52
- resolvers: mergedResolvers
53
- });
54
- if (directives && directives.length > 0) {
55
- for (const { directive } of directives) if (directive.transformer) schema = directive.transformer(schema);
56
- }
57
- return schema;
58
- } catch (error) {
59
- consola$1.error("Schema merge error:", error);
60
- throw error;
61
- }
62
- }
63
- let apolloServer = null;
64
- let serverStarted = false;
65
- async function createApolloServer() {
66
- if (!apolloServer) {
67
- apolloServer = new ApolloServer(defu({
68
- schema: await createMergedSchema(),
69
- introspection: true,
70
- plugins: [ApolloServerPluginLandingPageLocalDefault({ embed: true })]
71
- }, importedConfig));
72
- if (!serverStarted) {
73
- await apolloServer.start();
74
- serverStarted = true;
75
- }
76
- }
77
- return apolloServer;
78
- }
79
- let serverPromise = null;
80
- var apollo_server_default = defineEventHandler(async (event) => {
81
- if (!serverPromise) serverPromise = createApolloServer();
82
- return startServerAndCreateH3Handler(await serverPromise, {
83
- context: async () => ({ event }),
84
- serverAlreadyStarted: true
85
- })(event);
86
- });
87
-
88
- //#endregion
89
- export { apollo_server_default as default };
@@ -1,6 +0,0 @@
1
- import * as h30 from "h3";
2
-
3
- //#region src/routes/graphql-yoga.d.ts
4
- declare const _default: h30.EventHandler<h30.EventHandlerRequest, unknown>;
5
- //#endregion
6
- export { _default as default };
@@ -1,91 +0,0 @@
1
- import { consola as consola$1 } from "consola";
2
- import defu from "defu";
3
- import { parse } from "graphql";
4
- import { mergeResolvers, mergeTypeDefs } from "@graphql-tools/merge";
5
- import { importedConfig } from "#nitro-internal-virtual/graphql-config";
6
- import { moduleConfig } from "#nitro-internal-virtual/module-config";
7
- import { directives } from "#nitro-internal-virtual/server-directives";
8
- import { resolvers } from "#nitro-internal-virtual/server-resolvers";
9
- import { schemas } from "#nitro-internal-virtual/server-schemas";
10
- import { makeExecutableSchema } from "@graphql-tools/schema";
11
- import { defineEventHandler } from "h3";
12
- import { createYoga } from "graphql-yoga";
13
-
14
- //#region src/routes/graphql-yoga.ts
15
- let buildSubgraphSchema = null;
16
- async function loadFederationSupport() {
17
- if (buildSubgraphSchema !== null) return buildSubgraphSchema;
18
- try {
19
- buildSubgraphSchema = (await import("@apollo/subgraph")).buildSubgraphSchema;
20
- } catch {
21
- buildSubgraphSchema = false;
22
- }
23
- return buildSubgraphSchema;
24
- }
25
- const apolloSandboxHtml = `<!DOCTYPE html>
26
- <html lang="en">
27
- <body style="margin: 0; overflow-x: hidden; overflow-y: hidden">
28
- <div id="sandbox" style="height:100vh; width:100vw;"></div>
29
- <script src="https://embeddable-sandbox.cdn.apollographql.com/02e2da0fccbe0240ef03d2396d6c98559bab5b06/embeddable-sandbox.umd.production.min.js"><\/script>
30
- <script>
31
- new window.EmbeddedSandbox({
32
- target: "#sandbox",
33
- initialEndpoint: window.location.href,
34
- hideCookieToggle: false,
35
- initialState: {
36
- includeCookies: true
37
- }
38
- });
39
- <\/script>
40
- </body>
41
- </html>`;
42
- async function createMergedSchema() {
43
- try {
44
- const typeDefs = mergeTypeDefs([schemas.map((schema$1) => schema$1.def).join("\n\n")], {
45
- throwOnConflict: true,
46
- commentDescriptions: true,
47
- sort: true
48
- });
49
- const mergedResolvers = mergeResolvers(resolvers.map((r) => r.resolver));
50
- const federationEnabled = moduleConfig.federation?.enabled;
51
- let schema;
52
- if (federationEnabled) {
53
- const buildSubgraph = await loadFederationSupport();
54
- if (buildSubgraph) schema = buildSubgraph({
55
- typeDefs: typeof typeDefs === "string" ? parse(typeDefs) : typeDefs,
56
- resolvers: mergedResolvers
57
- });
58
- else {
59
- console.warn("Federation enabled but @apollo/subgraph not available, falling back to regular schema");
60
- schema = makeExecutableSchema({
61
- typeDefs,
62
- resolvers: mergedResolvers
63
- });
64
- }
65
- } else schema = makeExecutableSchema({
66
- typeDefs,
67
- resolvers: mergedResolvers
68
- });
69
- if (directives && directives.length > 0) {
70
- for (const { directive } of directives) if (directive.transformer) schema = directive.transformer(schema);
71
- }
72
- return schema;
73
- } catch (error) {
74
- consola$1.error("Schema merge error:", error);
75
- throw error;
76
- }
77
- }
78
- let yoga;
79
- var graphql_yoga_default = defineEventHandler(async (event) => {
80
- if (!yoga) yoga = createYoga(defu({
81
- schema: await createMergedSchema(),
82
- graphqlEndpoint: "/api/graphql",
83
- landingPage: false,
84
- renderGraphiQL: () => apolloSandboxHtml
85
- }, importedConfig));
86
- const response = await yoga.handleRequest(event.req, event);
87
- return new Response(response.body, response);
88
- });
89
-
90
- //#endregion
91
- export { graphql_yoga_default as default };
@@ -1,6 +0,0 @@
1
- import * as h31 from "h3";
2
-
3
- //#region src/routes/health.d.ts
4
- declare const _default: h31.EventHandler<h31.EventHandlerRequest, unknown>;
5
- //#endregion
6
- export { _default as default };