nitro-graphql 2.0.0-beta.1 → 2.0.0-beta.11

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.
@@ -0,0 +1,127 @@
1
+ import { resolve } from "pathe";
2
+
3
+ //#region src/utils/path-resolver.ts
4
+ /**
5
+ * Replace placeholders in a path string
6
+ * Supports: {serviceName}, {buildDir}, {rootDir}, {framework}, {typesDir}, {serverGraphql}, {clientGraphql}
7
+ */
8
+ function replacePlaceholders(path, placeholders) {
9
+ return path.replace(/\{serviceName\}/g, placeholders.serviceName || "default").replace(/\{buildDir\}/g, placeholders.buildDir).replace(/\{rootDir\}/g, placeholders.rootDir).replace(/\{framework\}/g, placeholders.framework).replace(/\{typesDir\}/g, placeholders.typesDir).replace(/\{serverGraphql\}/g, placeholders.serverGraphql).replace(/\{clientGraphql\}/g, placeholders.clientGraphql);
10
+ }
11
+ /**
12
+ * Get default paths based on framework and user configuration
13
+ */
14
+ function getDefaultPaths(nitro) {
15
+ const isNuxt = nitro.options.framework?.name === "nuxt";
16
+ const rootDir = nitro.options.rootDir;
17
+ const buildDir = nitro.options.buildDir;
18
+ const pathsConfig = nitro.options.graphql?.paths || {};
19
+ const defaultServerGraphql = pathsConfig.serverGraphql || resolve(rootDir, "server", "graphql");
20
+ const defaultClientGraphql = pathsConfig.clientGraphql || resolve(rootDir, isNuxt ? "app/graphql" : "graphql");
21
+ const defaultBuildDir = pathsConfig.buildDir || buildDir;
22
+ const defaultTypesDir = pathsConfig.typesDir || resolve(defaultBuildDir, "types");
23
+ return {
24
+ serviceName: "default",
25
+ buildDir: defaultBuildDir,
26
+ rootDir,
27
+ framework: isNuxt ? "nuxt" : "nitro",
28
+ typesDir: defaultTypesDir,
29
+ serverGraphql: defaultServerGraphql,
30
+ clientGraphql: defaultClientGraphql
31
+ };
32
+ }
33
+ /**
34
+ * Check if a file should be generated based on config
35
+ * Returns: true if should generate, false if should skip
36
+ */
37
+ function shouldGenerateFile(config, categoryEnabled, topLevelEnabled) {
38
+ if (config === false) return false;
39
+ if (config === true || typeof config === "string") return true;
40
+ if (categoryEnabled === false) return false;
41
+ if (categoryEnabled === true) return true;
42
+ return topLevelEnabled;
43
+ }
44
+ /**
45
+ * Resolve the file path based on configuration
46
+ * Returns: resolved absolute path or null if file should not be generated
47
+ */
48
+ function resolveFilePath(config, categoryEnabled, topLevelEnabled, defaultPath, placeholders) {
49
+ if (!shouldGenerateFile(config, categoryEnabled, topLevelEnabled)) return null;
50
+ if (typeof config === "string") {
51
+ const customPath = replacePlaceholders(config, placeholders);
52
+ return resolve(placeholders.rootDir, customPath);
53
+ }
54
+ const resolvedDefault = replacePlaceholders(defaultPath, placeholders);
55
+ return resolve(placeholders.rootDir, resolvedDefault);
56
+ }
57
+ /**
58
+ * Check if scaffold files should be generated (category-level check)
59
+ */
60
+ function shouldGenerateScaffold(nitro) {
61
+ const scaffoldConfig = nitro.options.graphql?.scaffold;
62
+ if (scaffoldConfig === false) return false;
63
+ if (scaffoldConfig && scaffoldConfig.enabled === false) return false;
64
+ return true;
65
+ }
66
+ /**
67
+ * Get scaffold configuration (handles false case)
68
+ */
69
+ function getScaffoldConfig(nitro) {
70
+ const scaffoldConfig = nitro.options.graphql?.scaffold;
71
+ if (scaffoldConfig === false) return { enabled: false };
72
+ return scaffoldConfig || {};
73
+ }
74
+ /**
75
+ * Check if client utilities should be generated (category-level check)
76
+ */
77
+ function shouldGenerateClientUtils(nitro) {
78
+ const clientUtilsConfig = nitro.options.graphql?.clientUtils;
79
+ if (clientUtilsConfig === false) return false;
80
+ if (clientUtilsConfig && clientUtilsConfig.enabled === false) return false;
81
+ return nitro.options.framework?.name === "nuxt";
82
+ }
83
+ /**
84
+ * Get client utilities configuration (handles false case)
85
+ */
86
+ function getClientUtilsConfig(nitro) {
87
+ const clientUtilsConfig = nitro.options.graphql?.clientUtils;
88
+ if (clientUtilsConfig === false) return { enabled: false };
89
+ return clientUtilsConfig || {};
90
+ }
91
+ /**
92
+ * Check if SDK files should be generated (category-level check)
93
+ */
94
+ function shouldGenerateSDK(nitro) {
95
+ const sdkConfig = nitro.options.graphql?.sdk;
96
+ if (sdkConfig === false) return false;
97
+ if (sdkConfig && sdkConfig.enabled === false) return false;
98
+ return true;
99
+ }
100
+ /**
101
+ * Get SDK configuration (handles false case)
102
+ */
103
+ function getSdkConfig(nitro) {
104
+ const sdkConfig = nitro.options.graphql?.sdk;
105
+ if (sdkConfig === false) return { enabled: false };
106
+ return sdkConfig || {};
107
+ }
108
+ /**
109
+ * Check if type files should be generated (category-level check)
110
+ */
111
+ function shouldGenerateTypes(nitro) {
112
+ const typesConfig = nitro.options.graphql?.types;
113
+ if (typesConfig === false) return false;
114
+ if (typesConfig && typesConfig.enabled === false) return false;
115
+ return true;
116
+ }
117
+ /**
118
+ * Get types configuration (handles false case)
119
+ */
120
+ function getTypesConfig(nitro) {
121
+ const typesConfig = nitro.options.graphql?.types;
122
+ if (typesConfig === false) return { enabled: false };
123
+ return typesConfig || {};
124
+ }
125
+
126
+ //#endregion
127
+ export { getClientUtilsConfig, getDefaultPaths, getScaffoldConfig, getSdkConfig, getTypesConfig, replacePlaceholders, resolveFilePath, shouldGenerateClientUtils, shouldGenerateFile, shouldGenerateSDK, shouldGenerateScaffold, shouldGenerateTypes };
@@ -1,4 +1,6 @@
1
1
  import { downloadAndSaveSchema, generateClientTypes, generateExternalClientTypes, loadExternalSchema, loadGraphQLDocuments } from "./client-codegen.js";
2
+ import { writeFileIfNotExists } from "./file-generator.js";
3
+ import { getClientUtilsConfig, getDefaultPaths, getSdkConfig, getTypesConfig, resolveFilePath, shouldGenerateClientUtils, shouldGenerateTypes } from "./path-resolver.js";
2
4
  import { generateTypes } from "./server-codegen.js";
3
5
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
4
6
  import consola from "consola";
@@ -10,12 +12,16 @@ import { mergeTypeDefs } from "@graphql-tools/merge";
10
12
  import { printSchemaWithDirectives } from "@graphql-tools/utils";
11
13
 
12
14
  //#region src/utils/type-generation.ts
13
- function generateGraphQLIndexFile(clientDir, externalServices = []) {
14
- const indexPath = resolve(clientDir, "index.ts");
15
+ function generateGraphQLIndexFile(nitro, clientDir, externalServices = []) {
16
+ if (!shouldGenerateClientUtils(nitro)) return;
17
+ const placeholders = getDefaultPaths(nitro);
18
+ const clientUtilsConfig = getClientUtilsConfig(nitro);
19
+ const indexPath = resolveFilePath(clientUtilsConfig.index, clientUtilsConfig.enabled, true, "{clientGraphql}/index.ts", placeholders);
20
+ if (!indexPath) return;
15
21
  if (!existsSync(indexPath)) {
16
22
  let indexContent = `// This file is auto-generated once by nitro-graphql for quick start
17
23
  // You can modify this file according to your needs
18
- //
24
+ //
19
25
  // Export your main GraphQL service (auto-generated)
20
26
  export * from './default/ofetch'
21
27
 
@@ -24,14 +30,22 @@ export * from './default/ofetch'
24
30
  // export * from './yourServiceName/ofetch'
25
31
  `;
26
32
  for (const service of externalServices) indexContent += `export * from './${service.name}/ofetch'\n`;
27
- writeFileSync(indexPath, indexContent, "utf-8");
33
+ writeFileIfNotExists(indexPath, indexContent, "client index.ts");
28
34
  }
29
35
  }
30
- function generateNuxtOfetchClient(clientDir, serviceName = "default") {
31
- const serviceDir = resolve(clientDir, serviceName);
32
- const ofetchPath = resolve(serviceDir, "ofetch.ts");
36
+ function generateNuxtOfetchClient(nitro, clientDir, serviceName = "default") {
37
+ if (!shouldGenerateClientUtils(nitro)) return;
38
+ const placeholders = {
39
+ ...getDefaultPaths(nitro),
40
+ serviceName
41
+ };
42
+ const clientUtilsConfig = getClientUtilsConfig(nitro);
43
+ const ofetchPath = resolveFilePath(clientUtilsConfig.ofetch, clientUtilsConfig.enabled, true, "{clientGraphql}/{serviceName}/ofetch.ts", placeholders);
44
+ if (!ofetchPath) return;
45
+ const serviceDir = dirname(ofetchPath);
33
46
  if (!existsSync(serviceDir)) mkdirSync(serviceDir, { recursive: true });
34
- if (!existsSync(ofetchPath)) writeFileSync(ofetchPath, `// This file is auto-generated once by nitro-graphql for quick start
47
+ if (existsSync(ofetchPath)) return;
48
+ writeFileIfNotExists(ofetchPath, `// This file is auto-generated once by nitro-graphql for quick start
35
49
  // You can modify this file according to your needs
36
50
  import type { Requester } from './sdk'
37
51
  import { getSdk } from './sdk'
@@ -53,15 +67,23 @@ export function createGraphQLClient(endpoint: string): Requester {
53
67
  }
54
68
  }
55
69
 
56
- export const $sdk = getSdk(createGraphQLClient('/api/graphql'))`, "utf-8");
70
+ export const $sdk = getSdk(createGraphQLClient('/api/graphql'))`, `${serviceName} ofetch.ts`);
57
71
  }
58
- function generateExternalOfetchClient(clientDir, serviceName, endpoint) {
59
- const serviceDir = resolve(clientDir, serviceName);
60
- const ofetchPath = resolve(serviceDir, "ofetch.ts");
72
+ function generateExternalOfetchClient(nitro, service, endpoint) {
73
+ if (!shouldGenerateClientUtils(nitro)) return;
74
+ const serviceName = service.name;
75
+ const placeholders = {
76
+ ...getDefaultPaths(nitro),
77
+ serviceName
78
+ };
79
+ const clientUtilsConfig = getClientUtilsConfig(nitro);
80
+ const ofetchPath = resolveFilePath(service.paths?.ofetch ?? clientUtilsConfig.ofetch, clientUtilsConfig.enabled, true, "{clientGraphql}/{serviceName}/ofetch.ts", placeholders);
81
+ if (!ofetchPath) return;
82
+ const serviceDir = dirname(ofetchPath);
61
83
  if (!existsSync(serviceDir)) mkdirSync(serviceDir, { recursive: true });
62
84
  if (!existsSync(ofetchPath)) {
63
85
  const capitalizedServiceName = serviceName.charAt(0).toUpperCase() + serviceName.slice(1);
64
- writeFileSync(ofetchPath, `// This file is auto-generated once by nitro-graphql for quick start
86
+ writeFileIfNotExists(ofetchPath, `// This file is auto-generated once by nitro-graphql for quick start
65
87
  // You can modify this file according to your needs
66
88
  import type { Sdk, Requester } from './sdk'
67
89
  import { getSdk } from './sdk'
@@ -83,7 +105,7 @@ export function create${capitalizedServiceName}GraphQLClient(endpoint: string =
83
105
  }
84
106
  }
85
107
 
86
- export const $${serviceName}Sdk: Sdk = getSdk(create${capitalizedServiceName}GraphQLClient())`, "utf-8");
108
+ export const $${serviceName}Sdk: Sdk = getSdk(create${capitalizedServiceName}GraphQLClient())`, `${serviceName} external ofetch.ts`);
87
109
  }
88
110
  }
89
111
  /**
@@ -178,6 +200,10 @@ function validateNoDuplicateTypes(schemas, schemaStrings) {
178
200
  }
179
201
  async function serverTypeGeneration(app) {
180
202
  try {
203
+ if (!shouldGenerateTypes(app)) {
204
+ consola.debug("[nitro-graphql] Server type generation is disabled");
205
+ return;
206
+ }
181
207
  const schemas = app.scanSchemas || [];
182
208
  if (!schemas.length) {
183
209
  consola.info("No GraphQL definitions found for server type generation.");
@@ -197,9 +223,14 @@ async function serverTypeGeneration(app) {
197
223
  const schemaPath = resolve(app.graphql.buildDir, "schema.graphql");
198
224
  mkdirSync(dirname(schemaPath), { recursive: true });
199
225
  writeFileSync(schemaPath, printSchema, "utf-8");
200
- const serverTypesPath = resolve(app.options.buildDir, "types", "nitro-graphql-server.d.ts");
201
- mkdirSync(dirname(serverTypesPath), { recursive: true });
202
- writeFileSync(serverTypesPath, data, "utf-8");
226
+ const placeholders = getDefaultPaths(app);
227
+ const typesConfig = getTypesConfig(app);
228
+ const serverTypesPath = resolveFilePath(typesConfig.server, typesConfig.enabled, true, "{typesDir}/nitro-graphql-server.d.ts", placeholders);
229
+ if (serverTypesPath) {
230
+ mkdirSync(dirname(serverTypesPath), { recursive: true });
231
+ writeFileSync(serverTypesPath, data, "utf-8");
232
+ consola.success(`[nitro-graphql] Generated server types at: ${serverTypesPath}`);
233
+ }
203
234
  } catch (error) {
204
235
  consola.error("Server schema generation error:", error);
205
236
  }
@@ -252,17 +283,25 @@ async function generateMainClientTypes(nitro) {
252
283
  const graphqlString = readFileSync(schemaFilePath, "utf-8");
253
284
  const types = await generateClientTypes(nitro.options.graphql?.federation?.enabled === true ? buildSubgraphSchema([{ typeDefs: parse(graphqlString) }]) : buildSchema(graphqlString), loadDocs, nitro.options.graphql?.codegen?.client ?? {}, nitro.options.graphql?.codegen?.clientSDK ?? {});
254
285
  if (types === false) return;
255
- const clientTypesPath = resolve(nitro.options.buildDir, "types", "nitro-graphql-client.d.ts");
256
- const defaultServiceDir = resolve(nitro.graphql.clientDir, "default");
257
- const sdkTypesPath = resolve(defaultServiceDir, "sdk.ts");
258
- mkdirSync(dirname(clientTypesPath), { recursive: true });
259
- writeFileSync(clientTypesPath, types.types, "utf-8");
260
- mkdirSync(defaultServiceDir, { recursive: true });
261
- writeFileSync(sdkTypesPath, types.sdk, "utf-8");
286
+ const placeholders = getDefaultPaths(nitro);
287
+ const typesConfig = getTypesConfig(nitro);
288
+ const sdkConfig = getSdkConfig(nitro);
289
+ const clientTypesPath = resolveFilePath(typesConfig.client, typesConfig.enabled, true, "{typesDir}/nitro-graphql-client.d.ts", placeholders);
290
+ if (clientTypesPath) {
291
+ mkdirSync(dirname(clientTypesPath), { recursive: true });
292
+ writeFileSync(clientTypesPath, types.types, "utf-8");
293
+ consola.success(`[nitro-graphql] Generated client types at: ${clientTypesPath}`);
294
+ }
295
+ const sdkPath = resolveFilePath(sdkConfig.main, sdkConfig.enabled, true, "{clientGraphql}/default/sdk.ts", placeholders);
296
+ if (sdkPath) {
297
+ mkdirSync(dirname(sdkPath), { recursive: true });
298
+ writeFileSync(sdkPath, types.sdk, "utf-8");
299
+ consola.success(`[nitro-graphql] Generated SDK at: ${sdkPath}`);
300
+ }
262
301
  if (nitro.options.framework?.name === "nuxt") {
263
- generateNuxtOfetchClient(nitro.graphql.clientDir, "default");
302
+ generateNuxtOfetchClient(nitro, nitro.graphql.clientDir, "default");
264
303
  const externalServices = nitro.options.graphql?.externalServices || [];
265
- generateGraphQLIndexFile(nitro.graphql.clientDir, externalServices);
304
+ generateGraphQLIndexFile(nitro, nitro.graphql.clientDir, externalServices);
266
305
  }
267
306
  }
268
307
  async function generateExternalServicesTypes(nitro) {
@@ -292,14 +331,25 @@ async function generateExternalServicesTypes(nitro) {
292
331
  consola.warn(`[graphql:${service.name}] Type generation failed`);
293
332
  continue;
294
333
  }
295
- const serviceTypesPath = resolve(nitro.options.buildDir, "types", `nitro-graphql-client-${service.name}.d.ts`);
296
- const serviceDir = resolve(nitro.graphql.clientDir, service.name);
297
- const serviceSdkPath = resolve(serviceDir, "sdk.ts");
298
- mkdirSync(dirname(serviceTypesPath), { recursive: true });
299
- writeFileSync(serviceTypesPath, types.types, "utf-8");
300
- mkdirSync(serviceDir, { recursive: true });
301
- writeFileSync(serviceSdkPath, types.sdk, "utf-8");
302
- if (nitro.options.framework?.name === "nuxt") generateExternalOfetchClient(nitro.graphql.clientDir, service.name, service.endpoint);
334
+ const placeholders = {
335
+ ...getDefaultPaths(nitro),
336
+ serviceName: service.name
337
+ };
338
+ const typesConfig = getTypesConfig(nitro);
339
+ const sdkConfig = getSdkConfig(nitro);
340
+ const serviceTypesPath = resolveFilePath(service.paths?.types ?? typesConfig.external, typesConfig.enabled, true, "{typesDir}/nitro-graphql-client-{serviceName}.d.ts", placeholders);
341
+ if (serviceTypesPath) {
342
+ mkdirSync(dirname(serviceTypesPath), { recursive: true });
343
+ writeFileSync(serviceTypesPath, types.types, "utf-8");
344
+ consola.success(`[graphql:${service.name}] Generated types at: ${serviceTypesPath}`);
345
+ }
346
+ const serviceSdkPath = resolveFilePath(service.paths?.sdk ?? sdkConfig.external, sdkConfig.enabled, true, "{clientGraphql}/{serviceName}/sdk.ts", placeholders);
347
+ if (serviceSdkPath) {
348
+ mkdirSync(dirname(serviceSdkPath), { recursive: true });
349
+ writeFileSync(serviceSdkPath, types.sdk, "utf-8");
350
+ consola.success(`[graphql:${service.name}] Generated SDK at: ${serviceSdkPath}`);
351
+ }
352
+ if (nitro.options.framework?.name === "nuxt") generateExternalOfetchClient(nitro, service, service.endpoint);
303
353
  consola.success(`[graphql:${service.name}] External service types generated successfully`);
304
354
  } catch (error) {
305
355
  consola.error(`[graphql:${service.name}] External service generation failed:`, error);
@@ -0,0 +1,9 @@
1
+ //#region src/virtual/debug-info.d.ts
2
+ /**
3
+ * Virtual module stub for #nitro-graphql/debug-info
4
+ * This file is only used during build/bundling to prevent import resolution errors.
5
+ * At runtime, Nitro will override this with the actual virtual module.
6
+ */
7
+ declare const debugInfo: Record<string, any>;
8
+ //#endregion
9
+ export { debugInfo };
@@ -0,0 +1,26 @@
1
+ //#region src/virtual/debug-info.ts
2
+ /**
3
+ * Virtual module stub for #nitro-graphql/debug-info
4
+ * This file is only used during build/bundling to prevent import resolution errors.
5
+ * At runtime, Nitro will override this with the actual virtual module.
6
+ */
7
+ const debugInfo = {
8
+ isDev: false,
9
+ framework: "",
10
+ graphqlFramework: "",
11
+ federation: {},
12
+ scanned: {
13
+ schemas: 0,
14
+ schemaFiles: [],
15
+ resolvers: 0,
16
+ resolverFiles: [],
17
+ directives: 0,
18
+ directiveFiles: [],
19
+ documents: 0,
20
+ documentFiles: []
21
+ },
22
+ virtualModules: {}
23
+ };
24
+
25
+ //#endregion
26
+ export { debugInfo };
@@ -0,0 +1,9 @@
1
+ //#region src/virtual/graphql-config.d.ts
2
+ /**
3
+ * Virtual module stub for #nitro-graphql/graphql-config
4
+ * This file is only used during build/bundling to prevent import resolution errors.
5
+ * At runtime, Nitro will override this with the actual virtual module.
6
+ */
7
+ declare const importedConfig: {};
8
+ //#endregion
9
+ export { importedConfig };
@@ -0,0 +1,10 @@
1
+ //#region src/virtual/graphql-config.ts
2
+ /**
3
+ * Virtual module stub for #nitro-graphql/graphql-config
4
+ * This file is only used during build/bundling to prevent import resolution errors.
5
+ * At runtime, Nitro will override this with the actual virtual module.
6
+ */
7
+ const importedConfig = {};
8
+
9
+ //#endregion
10
+ export { importedConfig };
@@ -0,0 +1,9 @@
1
+ //#region src/virtual/module-config.d.ts
2
+ /**
3
+ * Virtual module stub for #nitro-graphql/module-config
4
+ * This file is only used during build/bundling to prevent import resolution errors.
5
+ * At runtime, Nitro will override this with the actual virtual module.
6
+ */
7
+ declare const moduleConfig: Record<string, any>;
8
+ //#endregion
9
+ export { moduleConfig };
@@ -0,0 +1,10 @@
1
+ //#region src/virtual/module-config.ts
2
+ /**
3
+ * Virtual module stub for #nitro-graphql/module-config
4
+ * This file is only used during build/bundling to prevent import resolution errors.
5
+ * At runtime, Nitro will override this with the actual virtual module.
6
+ */
7
+ const moduleConfig = {};
8
+
9
+ //#endregion
10
+ export { moduleConfig };
@@ -0,0 +1,11 @@
1
+ //#region src/virtual/server-directives.d.ts
2
+ /**
3
+ * Virtual module stub for #nitro-graphql/server-directives
4
+ * This file is only used during build/bundling to prevent import resolution errors.
5
+ * At runtime, Nitro will override this with the actual virtual module.
6
+ */
7
+ declare const directives: Array<{
8
+ directive: any;
9
+ }>;
10
+ //#endregion
11
+ export { directives };
@@ -0,0 +1,10 @@
1
+ //#region src/virtual/server-directives.ts
2
+ /**
3
+ * Virtual module stub for #nitro-graphql/server-directives
4
+ * This file is only used during build/bundling to prevent import resolution errors.
5
+ * At runtime, Nitro will override this with the actual virtual module.
6
+ */
7
+ const directives = [];
8
+
9
+ //#endregion
10
+ export { directives };
@@ -0,0 +1,11 @@
1
+ //#region src/virtual/server-resolvers.d.ts
2
+ /**
3
+ * Virtual module stub for #nitro-graphql/server-resolvers
4
+ * This file is only used during build/bundling to prevent import resolution errors.
5
+ * At runtime, Nitro will override this with the actual virtual module.
6
+ */
7
+ declare const resolvers: Array<{
8
+ resolver: any;
9
+ }>;
10
+ //#endregion
11
+ export { resolvers };
@@ -0,0 +1,10 @@
1
+ //#region src/virtual/server-resolvers.ts
2
+ /**
3
+ * Virtual module stub for #nitro-graphql/server-resolvers
4
+ * This file is only used during build/bundling to prevent import resolution errors.
5
+ * At runtime, Nitro will override this with the actual virtual module.
6
+ */
7
+ const resolvers = [];
8
+
9
+ //#endregion
10
+ export { resolvers };
@@ -0,0 +1,11 @@
1
+ //#region src/virtual/server-schemas.d.ts
2
+ /**
3
+ * Virtual module stub for #nitro-graphql/server-schemas
4
+ * This file is only used during build/bundling to prevent import resolution errors.
5
+ * At runtime, Nitro will override this with the actual virtual module.
6
+ */
7
+ declare const schemas: Array<{
8
+ def: string;
9
+ }>;
10
+ //#endregion
11
+ export { schemas };
@@ -0,0 +1,10 @@
1
+ //#region src/virtual/server-schemas.ts
2
+ /**
3
+ * Virtual module stub for #nitro-graphql/server-schemas
4
+ * This file is only used during build/bundling to prevent import resolution errors.
5
+ * At runtime, Nitro will override this with the actual virtual module.
6
+ */
7
+ const schemas = [];
8
+
9
+ //#endregion
10
+ export { schemas };
package/dist/vite.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ import { Plugin } from "vite";
2
+
3
+ //#region src/vite.d.ts
4
+
5
+ /**
6
+ * Vite plugin to load GraphQL files as strings
7
+ * This prevents Vite from trying to parse .graphql/.gql files as JavaScript
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import { defineConfig } from 'vite'
12
+ * import { nitro } from 'nitro/vite'
13
+ * import { graphql } from 'nitro-graphql/vite'
14
+ *
15
+ * export default defineConfig({
16
+ * plugins: [
17
+ * graphql(), // Must be before nitro()
18
+ * nitro()
19
+ * ]
20
+ * })
21
+ * ```
22
+ */
23
+ declare function graphql(): Plugin;
24
+ //#endregion
25
+ export { graphql };
package/dist/vite.js ADDED
@@ -0,0 +1,40 @@
1
+ import { readFile } from "node:fs/promises";
2
+
3
+ //#region src/vite.ts
4
+ /**
5
+ * Vite plugin to load GraphQL files as strings
6
+ * This prevents Vite from trying to parse .graphql/.gql files as JavaScript
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import { defineConfig } from 'vite'
11
+ * import { nitro } from 'nitro/vite'
12
+ * import { graphql } from 'nitro-graphql/vite'
13
+ *
14
+ * export default defineConfig({
15
+ * plugins: [
16
+ * graphql(), // Must be before nitro()
17
+ * nitro()
18
+ * ]
19
+ * })
20
+ * ```
21
+ */
22
+ function graphql() {
23
+ return {
24
+ name: "nitro-graphql:vite",
25
+ enforce: "pre",
26
+ async load(id) {
27
+ if (!/\.(?:graphql|gql)$/i.test(id)) return null;
28
+ try {
29
+ const content = await readFile(id, "utf-8");
30
+ return `export default ${JSON.stringify(content)}`;
31
+ } catch (error) {
32
+ if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") return null;
33
+ throw error;
34
+ }
35
+ }
36
+ };
37
+ }
38
+
39
+ //#endregion
40
+ export { graphql };