nitro-graphql 1.5.6 → 2.0.0-beta.10

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 (38) hide show
  1. package/README.md +29 -1
  2. package/dist/ecosystem/nuxt.js +13 -55
  3. package/dist/index.d.ts +2 -2
  4. package/dist/index.js +43 -48
  5. package/dist/rollup.js +84 -52
  6. package/dist/routes/apollo-server.d.ts +2 -2
  7. package/dist/routes/apollo-server.js +5 -5
  8. package/dist/routes/debug.d.ts +5 -5
  9. package/dist/routes/debug.js +6 -6
  10. package/dist/routes/graphql-yoga.d.ts +1 -1
  11. package/dist/routes/graphql-yoga.js +7 -8
  12. package/dist/routes/health.d.ts +1 -1
  13. package/dist/routes/health.js +6 -4
  14. package/dist/types/index.d.ts +2 -2
  15. package/dist/types/standard-schema.d.ts +2 -2
  16. package/dist/utils/client-codegen.d.ts +2 -2
  17. package/dist/utils/client-codegen.js +4 -4
  18. package/dist/utils/directive-parser.js +3 -7
  19. package/dist/utils/index.d.ts +3 -4
  20. package/dist/utils/index.js +47 -26
  21. package/dist/utils/path-resolver.js +2 -2
  22. package/dist/utils/type-generation.d.ts +1 -1
  23. package/dist/utils/type-generation.js +2 -1
  24. package/dist/virtual/debug-info.d.ts +9 -0
  25. package/dist/virtual/debug-info.js +26 -0
  26. package/dist/virtual/graphql-config.d.ts +9 -0
  27. package/dist/virtual/graphql-config.js +10 -0
  28. package/dist/virtual/module-config.d.ts +9 -0
  29. package/dist/virtual/module-config.js +10 -0
  30. package/dist/virtual/server-directives.d.ts +11 -0
  31. package/dist/virtual/server-directives.js +10 -0
  32. package/dist/virtual/server-resolvers.d.ts +11 -0
  33. package/dist/virtual/server-resolvers.js +10 -0
  34. package/dist/virtual/server-schemas.d.ts +11 -0
  35. package/dist/virtual/server-schemas.js +10 -0
  36. package/dist/vite.d.ts +25 -0
  37. package/dist/vite.js +40 -0
  38. package/package.json +46 -18
@@ -1,4 +1,4 @@
1
- import * as h35 from "h3";
1
+ import * as h33 from "h3";
2
2
 
3
3
  //#region src/routes/debug.d.ts
4
4
 
@@ -10,7 +10,7 @@ import * as h35 from "h3";
10
10
  * - /_nitro/graphql/debug - HTML dashboard
11
11
  * - /_nitro/graphql/debug?format=json - JSON API
12
12
  */
13
- declare const _default: h35.EventHandler<h35.EventHandlerRequest, Promise<string | {
13
+ declare const _default: h33.EventHandlerWithFetch<h33.EventHandlerRequest, Promise<string | {
14
14
  timestamp: string;
15
15
  environment: {
16
16
  dev: any;
@@ -33,7 +33,7 @@ declare const _default: h35.EventHandler<h35.EventHandlerRequest, Promise<string
33
33
  runtime: {
34
34
  loadedResolvers: number;
35
35
  loadedSchemas: number;
36
- loadedDirectives: any;
36
+ loadedDirectives: number;
37
37
  };
38
38
  virtualModules: any;
39
39
  virtualModuleSamples: {
@@ -52,9 +52,9 @@ declare const _default: h35.EventHandler<h35.EventHandlerRequest, Promise<string
52
52
  }[];
53
53
  };
54
54
  'server-directives': {
55
- directiveCount: any;
55
+ directiveCount: number;
56
56
  };
57
- 'module-config': any;
57
+ 'module-config': Record<string, any>;
58
58
  };
59
59
  }>>;
60
60
  //#endregion
@@ -1,9 +1,9 @@
1
- import { moduleConfig } from "#nitro-internal-virtual/module-config";
2
- import { directives } from "#nitro-internal-virtual/server-directives";
3
- import { resolvers } from "#nitro-internal-virtual/server-resolvers";
4
- import { schemas } from "#nitro-internal-virtual/server-schemas";
1
+ import { moduleConfig } from "#nitro-graphql/module-config";
2
+ import { directives } from "#nitro-graphql/server-directives";
3
+ import { resolvers } from "#nitro-graphql/server-resolvers";
4
+ import { schemas } from "#nitro-graphql/server-schemas";
5
5
  import { defineEventHandler, getQuery, setResponseHeader } from "h3";
6
- import { debugInfo } from "#nitro-internal-virtual/debug-info";
6
+ import { debugInfo } from "#nitro-graphql/debug-info";
7
7
 
8
8
  //#region src/routes/debug.ts
9
9
  /**
@@ -360,7 +360,7 @@ function generateHtmlDashboard(debugInfo$1) {
360
360
  <div class="flex items-center gap-3">
361
361
  <span class="${colorConfig.text} text-lg">▸</span>
362
362
  <div>
363
- <span class="font-mono text-sm ${colorConfig.text} font-semibold">#nitro-internal-virtual/${moduleName}</span>
363
+ <span class="font-mono text-sm ${colorConfig.text} font-semibold">#nitro-graphql/${moduleName}</span>
364
364
  <div class="text-[10px] text-slate-500 mt-0.5">
365
365
  ${lineCount} lines · ${(byteSize / 1024).toFixed(2)} KB
366
366
  </div>
@@ -1,6 +1,6 @@
1
1
  import * as h30 from "h3";
2
2
 
3
3
  //#region src/routes/graphql-yoga.d.ts
4
- declare const _default: h30.EventHandler<h30.EventHandlerRequest, Promise<Response>>;
4
+ declare const _default: h30.EventHandlerWithFetch<h30.EventHandlerRequest, Promise<Response>>;
5
5
  //#endregion
6
6
  export { _default as default };
@@ -2,13 +2,13 @@ import { consola as consola$1 } from "consola";
2
2
  import defu from "defu";
3
3
  import { parse } from "graphql";
4
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";
5
+ import { importedConfig } from "#nitro-graphql/graphql-config";
6
+ import { moduleConfig } from "#nitro-graphql/module-config";
7
+ import { directives } from "#nitro-graphql/server-directives";
8
+ import { resolvers } from "#nitro-graphql/server-resolvers";
9
+ import { schemas } from "#nitro-graphql/server-schemas";
10
10
  import { makeExecutableSchema } from "@graphql-tools/schema";
11
- import { defineEventHandler, toWebRequest } from "h3";
11
+ import { defineEventHandler } from "h3";
12
12
  import { createYoga } from "graphql-yoga";
13
13
 
14
14
  //#region src/routes/graphql-yoga.ts
@@ -83,8 +83,7 @@ var graphql_yoga_default = defineEventHandler(async (event) => {
83
83
  landingPage: false,
84
84
  renderGraphiQL: () => apolloSandboxHtml
85
85
  }, importedConfig));
86
- const request = toWebRequest(event);
87
- const response = await yoga.handleRequest(request, event);
86
+ const response = await yoga.handleRequest(event.req, event);
88
87
  return new Response(response.body, response);
89
88
  });
90
89
 
@@ -1,7 +1,7 @@
1
1
  import * as h31 from "h3";
2
2
 
3
3
  //#region src/routes/health.d.ts
4
- declare const _default: h31.EventHandler<h31.EventHandlerRequest, Promise<{
4
+ declare const _default: h31.EventHandlerWithFetch<h31.EventHandlerRequest, Promise<{
5
5
  status: string;
6
6
  message: string;
7
7
  timestamp: string;
@@ -1,11 +1,12 @@
1
- import { defineEventHandler, setResponseStatus } from "h3";
2
- import { useRuntimeConfig } from "nitropack/runtime";
1
+ import { defineEventHandler } from "h3";
2
+ import { useRuntimeConfig } from "nitro/runtime";
3
3
 
4
4
  //#region src/routes/health.ts
5
5
  var health_default = defineEventHandler(async (event) => {
6
6
  const runtime = useRuntimeConfig();
7
7
  if (!runtime.graphql || !runtime.graphql.endpoint?.graphql) {
8
- setResponseStatus(event, 404);
8
+ event.res.status = 404;
9
+ event.res.statusText = "Not Found";
9
10
  return {
10
11
  status: "error",
11
12
  message: "GraphQL health check endpoint is not configured",
@@ -31,7 +32,8 @@ var health_default = defineEventHandler(async (event) => {
31
32
  };
32
33
  throw new Error("Invalid response from GraphQL server");
33
34
  } catch (error) {
34
- setResponseStatus(event, 503);
35
+ event.res.status = 503;
36
+ event.res.statusText = "Service Unavailable";
35
37
  return {
36
38
  status: "unhealthy",
37
39
  message: error instanceof Error ? error.message : "GraphQL server is not responding",
@@ -27,7 +27,7 @@ interface GenImport {
27
27
  imports: IESMImport[];
28
28
  options?: ESMCodeGenOptions;
29
29
  }
30
- declare module 'nitropack/types' {
30
+ declare module 'nitro/types' {
31
31
  interface Nitro {
32
32
  scanSchemas: string[];
33
33
  scanDocuments: string[];
@@ -46,7 +46,7 @@ declare module 'nitropack/types' {
46
46
  };
47
47
  }
48
48
  }
49
- declare module 'nitropack' {
49
+ declare module 'nitro/types' {
50
50
  interface NitroOptions {
51
51
  graphql?: NitroGraphQLOptions;
52
52
  }
@@ -1,8 +1,8 @@
1
1
  //#region src/types/standard-schema.d.ts
2
2
  /** The Standard Schema interface. */
3
- interface StandardSchemaV1<Input$1 = unknown, Output$1 = Input$1> {
3
+ interface StandardSchemaV1<Input = unknown, Output = Input> {
4
4
  /** The Standard Schema properties. */
5
- readonly '~standard': StandardSchemaV1.Props<Input$1, Output$1>;
5
+ readonly '~standard': StandardSchemaV1.Props<Input, Output>;
6
6
  }
7
7
  declare namespace StandardSchemaV1 {
8
8
  /** The Standard Schema properties interface. */
@@ -23,14 +23,14 @@ declare function loadExternalSchema(service: ExternalGraphQLService, buildDir?:
23
23
  */
24
24
  declare function downloadAndSaveSchema(service: ExternalGraphQLService, buildDir: string): Promise<string | undefined>;
25
25
  declare function loadGraphQLDocuments(patterns: string | string[]): Promise<Source[]>;
26
- declare function generateClientTypes(schema: GraphQLSchema, docs: Source[], config?: CodegenClientConfig, sdkConfig?: GenericSdkConfig, outputPath?: string, serviceName?: string, virtualTypesPath?: string): Promise<false | {
26
+ declare function generateClientTypes(schema: GraphQLSchema, docs: Source[], config?: CodegenClientConfig, sdkConfig?: GenericSdkConfig, outputPath?: string, serviceName?: string): Promise<false | {
27
27
  types: string;
28
28
  sdk: string;
29
29
  }>;
30
30
  /**
31
31
  * Generate client types for external GraphQL service
32
32
  */
33
- declare function generateExternalClientTypes(service: ExternalGraphQLService, schema: GraphQLSchema, docs: Source[], virtualTypesPath?: string): Promise<{
33
+ declare function generateExternalClientTypes(service: ExternalGraphQLService, schema: GraphQLSchema, docs: Source[]): Promise<{
34
34
  types: string;
35
35
  sdk: string;
36
36
  } | false>;
@@ -165,7 +165,7 @@ async function loadGraphQLDocuments(patterns) {
165
165
  else throw e;
166
166
  }
167
167
  }
168
- async function generateClientTypes(schema, docs, config = {}, sdkConfig = {}, outputPath, serviceName, virtualTypesPath) {
168
+ async function generateClientTypes(schema, docs, config = {}, sdkConfig = {}, outputPath, serviceName) {
169
169
  if (docs.length === 0 && !serviceName) {
170
170
  consola$1.info("No client GraphQL files found. Skipping client type generation.");
171
171
  return false;
@@ -252,7 +252,7 @@ export function getSdk(requester: Requester): Sdk {
252
252
  typescriptOperations: { plugin: plugin$2 }
253
253
  }
254
254
  });
255
- const typesPath = virtualTypesPath || (serviceName ? `#graphql/client/${serviceName}` : "#graphql/client");
255
+ const typesPath = serviceName ? `#graphql/client/${serviceName}` : "#graphql/client";
256
256
  const sdkOutput = await preset.buildGeneratesSection({
257
257
  baseOutputDir: outputPath || "client-types.generated.ts",
258
258
  schema: parse(printSchemaWithDirectives(schema)),
@@ -282,8 +282,8 @@ export function getSdk(requester: Requester): Sdk {
282
282
  /**
283
283
  * Generate client types for external GraphQL service
284
284
  */
285
- async function generateExternalClientTypes(service, schema, docs, virtualTypesPath) {
286
- return generateClientTypes(schema, docs, service.codegen?.client || {}, service.codegen?.clientSDK || {}, void 0, service.name, virtualTypesPath);
285
+ async function generateExternalClientTypes(service, schema, docs) {
286
+ return generateClientTypes(schema, docs, service.codegen?.client || {}, service.codegen?.clientSDK || {}, void 0, service.name);
287
287
  }
288
288
 
289
289
  //#endregion
@@ -18,13 +18,9 @@ var DirectiveParser = class {
18
18
  sourceType: "module",
19
19
  astType: "ts"
20
20
  });
21
- if (result.errors.length > 0) {
22
- console.warn(`Parse errors in ${filePath}:`, result.errors.map((e) => e.message));
23
- return [];
24
- }
21
+ if (result.errors.length > 0) return [];
25
22
  return this.extractDirectiveDefinitions(result.program);
26
- } catch (error) {
27
- console.warn(`Failed to parse ${filePath} with oxc:`, error);
23
+ } catch {
28
24
  return [];
29
25
  }
30
26
  }
@@ -205,7 +201,7 @@ async function generateDirectiveSchemas(nitro, directives) {
205
201
  }
206
202
  }
207
203
  if (directiveSchemas.length > 0) {
208
- const directivesPath = resolve(nitro.graphql.serverDir, "_directives.graphql");
204
+ const directivesPath = resolve(nitro.graphql.buildDir, "_directives.graphql");
209
205
  const content = `# WARNING: This file is auto-generated by nitro-graphql
210
206
  # Do not modify this file directly. It will be overwritten.
211
207
  # To define custom directives, create .directive.ts files using defineDirective()
@@ -1,6 +1,6 @@
1
1
  import { GenImport } from "../types/index.js";
2
2
  import { directiveParser, generateDirectiveSchema, generateDirectiveSchemas } from "./directive-parser.js";
3
- import { Nitro } from "nitropack";
3
+ import { Nitro } from "nitro/types";
4
4
 
5
5
  //#region src/utils/index.d.ts
6
6
  declare const GLOB_SCAN_PATTERN = "**/*.{graphql,gql,js,mjs,cjs,ts,mts,cts,tsx,jsx}";
@@ -19,13 +19,12 @@ declare function getLayerAppDirectories(nitro: Nitro): string[];
19
19
  /**
20
20
  * Generate layer-aware ignore patterns for auto-generated files
21
21
  */
22
- declare function generateLayerIgnorePatterns(nitro: Nitro): string[];
22
+ declare function generateLayerIgnorePatterns(): string[];
23
23
  declare function getImportId(p: string, lazy?: boolean): string;
24
24
  declare function relativeWithDot(from: string, to: string): string;
25
25
  declare function scanGraphql(nitro: Nitro): Promise<string[]>;
26
26
  declare function scanResolvers(nitro: Nitro): Promise<GenImport[]>;
27
27
  declare function scanDirectives(nitro: Nitro): Promise<GenImport[]>;
28
- declare function scanTypeDefs(nitro: Nitro): Promise<string[]>;
29
28
  declare function scanSchemas(nitro: Nitro): Promise<string[]>;
30
29
  declare function scanDocs(nitro: Nitro): Promise<string[]>;
31
30
  /**
@@ -37,4 +36,4 @@ declare function scanExternalServiceDocs(nitro: Nitro, serviceName: string, patt
37
36
  */
38
37
  declare function validateExternalServices(services: unknown[]): string[];
39
38
  //#endregion
40
- export { GLOB_SCAN_PATTERN, directiveParser, generateDirectiveSchema, generateDirectiveSchemas, generateLayerIgnorePatterns, getImportId, getLayerAppDirectories, getLayerDirectories, getLayerServerDirectories, relativeWithDot, scanDirectives, scanDocs, scanExternalServiceDocs, scanGraphql, scanResolvers, scanSchemas, scanTypeDefs, validateExternalServices };
39
+ export { GLOB_SCAN_PATTERN, directiveParser, generateDirectiveSchema, generateDirectiveSchemas, generateLayerIgnorePatterns, getImportId, getLayerAppDirectories, getLayerDirectories, getLayerServerDirectories, relativeWithDot, scanDirectives, scanDocs, scanExternalServiceDocs, scanGraphql, scanResolvers, scanSchemas, validateExternalServices };
@@ -28,12 +28,8 @@ function getLayerAppDirectories(nitro) {
28
28
  /**
29
29
  * Generate layer-aware ignore patterns for auto-generated files
30
30
  */
31
- function generateLayerIgnorePatterns(nitro) {
32
- const patterns = [];
33
- patterns.push(`${nitro.graphql.serverDir}/_directives.graphql`);
34
- const layerServerDirs = nitro.options.graphql?.layerServerDirs || [];
35
- for (const layerServerDir of layerServerDirs) patterns.push(`${layerServerDir}/graphql/_directives.graphql`);
36
- return patterns;
31
+ function generateLayerIgnorePatterns() {
32
+ return [];
37
33
  }
38
34
  function getImportId(p, lazy) {
39
35
  return (lazy ? "_lazy_" : "_") + hash(p).replace(/-/g, "").slice(0, 6);
@@ -44,10 +40,30 @@ function relativeWithDot(from, to) {
44
40
  return RELATIVE_RE.test(rel) ? rel : `./${rel}`;
45
41
  }
46
42
  async function scanGraphql(nitro) {
47
- return (await scanFiles(nitro, "graphql")).map((f) => f.fullPath);
43
+ const serverDirRelative = relative(nitro.options.rootDir, nitro.graphql.serverDir);
44
+ const files = await scanDir(nitro, nitro.options.rootDir, serverDirRelative, "**/*.{graphql,gql}");
45
+ const layerServerDirs = getLayerServerDirectories(nitro);
46
+ const layerFiles = await Promise.all(layerServerDirs.map((layerServerDir) => scanDir(nitro, layerServerDir, "graphql", "**/*.{graphql,gql}"))).then((r) => r.flat());
47
+ const allFiles = [...files, ...layerFiles];
48
+ const seenPaths = /* @__PURE__ */ new Set();
49
+ return allFiles.filter((file) => {
50
+ if (seenPaths.has(file.fullPath)) return false;
51
+ seenPaths.add(file.fullPath);
52
+ return true;
53
+ }).map((f) => f.fullPath);
48
54
  }
49
55
  async function scanResolvers(nitro) {
50
- const files = await scanFiles(nitro, "graphql", "**/*.resolver.{ts,js}");
56
+ const serverDirRelative = relative(nitro.options.rootDir, nitro.graphql.serverDir);
57
+ const regularFiles = await scanDir(nitro, nitro.options.rootDir, serverDirRelative, "**/*.resolver.{ts,js}");
58
+ const layerServerDirs = getLayerServerDirectories(nitro);
59
+ const layerFiles = await Promise.all(layerServerDirs.map((layerServerDir) => scanDir(nitro, layerServerDir, "graphql", "**/*.resolver.{ts,js}"))).then((r) => r.flat());
60
+ const allFiles = [...regularFiles, ...layerFiles];
61
+ const seenPaths = /* @__PURE__ */ new Set();
62
+ const files = allFiles.filter((file) => {
63
+ if (seenPaths.has(file.fullPath)) return false;
64
+ seenPaths.add(file.fullPath);
65
+ return true;
66
+ });
51
67
  const exportName = [];
52
68
  const VALID_DEFINE_FUNCTIONS = [
53
69
  "defineResolver",
@@ -125,7 +141,17 @@ async function scanResolvers(nitro) {
125
141
  return exportName;
126
142
  }
127
143
  async function scanDirectives(nitro) {
128
- const files = await scanFiles(nitro, "graphql", "**/*.directive.{ts,js}");
144
+ const serverDirRelative = relative(nitro.options.rootDir, nitro.graphql.serverDir);
145
+ const regularFiles = await scanDir(nitro, nitro.options.rootDir, serverDirRelative, "**/*.directive.{ts,js}");
146
+ const layerServerDirs = getLayerServerDirectories(nitro);
147
+ const layerFiles = await Promise.all(layerServerDirs.map((layerServerDir) => scanDir(nitro, layerServerDir, "graphql", "**/*.directive.{ts,js}"))).then((r) => r.flat());
148
+ const allFiles = [...regularFiles, ...layerFiles];
149
+ const seenPaths = /* @__PURE__ */ new Set();
150
+ const files = allFiles.filter((file) => {
151
+ if (seenPaths.has(file.fullPath)) return false;
152
+ seenPaths.add(file.fullPath);
153
+ return true;
154
+ });
129
155
  const exportName = [];
130
156
  for (const file of files) {
131
157
  const fileContent = await readFile(file.fullPath, "utf-8");
@@ -149,11 +175,18 @@ async function scanDirectives(nitro) {
149
175
  }
150
176
  return exportName;
151
177
  }
152
- async function scanTypeDefs(nitro) {
153
- return (await scanFiles(nitro, "graphql", "**/*.typedef.{ts,js}")).map((f) => f.fullPath);
154
- }
155
178
  async function scanSchemas(nitro) {
156
- return (await scanFiles(nitro, "graphql", "**/*.graphql")).map((f) => f.fullPath);
179
+ const serverDirRelative = relative(nitro.options.rootDir, nitro.graphql.serverDir);
180
+ const files = await scanDir(nitro, nitro.options.rootDir, serverDirRelative, "**/*.graphql");
181
+ const layerServerDirs = getLayerServerDirectories(nitro);
182
+ const layerFiles = await Promise.all(layerServerDirs.map((layerServerDir) => scanDir(nitro, layerServerDir, "graphql", "**/*.graphql"))).then((r) => r.flat());
183
+ const allFiles = [...files, ...layerFiles];
184
+ const seenPaths = /* @__PURE__ */ new Set();
185
+ return allFiles.filter((file) => {
186
+ if (seenPaths.has(file.fullPath)) return false;
187
+ seenPaths.add(file.fullPath);
188
+ return true;
189
+ }).map((f) => f.fullPath);
157
190
  }
158
191
  async function scanDocs(nitro) {
159
192
  const files = await scanDir(nitro, nitro.options.rootDir, nitro.graphql.dir.client, "**/*.graphql");
@@ -221,18 +254,6 @@ function validateExternalServices(services) {
221
254
  }
222
255
  return errors;
223
256
  }
224
- async function scanFiles(nitro, name, globPattern = GLOB_SCAN_PATTERN) {
225
- const regularFiles = await Promise.all(nitro.options.scanDirs.map((dir) => scanDir(nitro, dir, name, globPattern))).then((r) => r.flat());
226
- const layerDirectories = getLayerDirectories(nitro);
227
- const layerFiles = await Promise.all(layerDirectories.map((layerDir) => scanDir(nitro, layerDir, `server/${name}`, globPattern))).then((r) => r.flat());
228
- const allFiles = [...regularFiles, ...layerFiles];
229
- const seenPaths = /* @__PURE__ */ new Set();
230
- return allFiles.filter((file) => {
231
- if (seenPaths.has(file.fullPath)) return false;
232
- seenPaths.add(file.fullPath);
233
- return true;
234
- });
235
- }
236
257
  async function scanDir(nitro, dir, name, globPattern = GLOB_SCAN_PATTERN) {
237
258
  return (await glob(join(name, globPattern), {
238
259
  cwd: dir,
@@ -254,4 +275,4 @@ async function scanDir(nitro, dir, name, globPattern = GLOB_SCAN_PATTERN) {
254
275
  }
255
276
 
256
277
  //#endregion
257
- export { GLOB_SCAN_PATTERN, directiveParser, generateDirectiveSchema, generateDirectiveSchemas, generateLayerIgnorePatterns, getImportId, getLayerAppDirectories, getLayerDirectories, getLayerServerDirectories, relativeWithDot, scanDirectives, scanDocs, scanExternalServiceDocs, scanGraphql, scanResolvers, scanSchemas, scanTypeDefs, validateExternalServices };
278
+ export { GLOB_SCAN_PATTERN, directiveParser, generateDirectiveSchema, generateDirectiveSchemas, generateLayerIgnorePatterns, getImportId, getLayerAppDirectories, getLayerDirectories, getLayerServerDirectories, relativeWithDot, scanDirectives, scanDocs, scanExternalServiceDocs, scanGraphql, scanResolvers, scanSchemas, validateExternalServices };
@@ -1,4 +1,4 @@
1
- import { isAbsolute, resolve } from "pathe";
1
+ import { resolve } from "pathe";
2
2
 
3
3
  //#region src/utils/path-resolver.ts
4
4
  /**
@@ -49,7 +49,7 @@ function resolveFilePath(config, categoryEnabled, topLevelEnabled, defaultPath,
49
49
  if (!shouldGenerateFile(config, categoryEnabled, topLevelEnabled)) return null;
50
50
  if (typeof config === "string") {
51
51
  const customPath = replacePlaceholders(config, placeholders);
52
- return isAbsolute(customPath) ? customPath : resolve(placeholders.rootDir, customPath);
52
+ return resolve(placeholders.rootDir, customPath);
53
53
  }
54
54
  const resolvedDefault = replacePlaceholders(defaultPath, placeholders);
55
55
  return resolve(placeholders.rootDir, resolvedDefault);
@@ -1,4 +1,4 @@
1
- import { Nitro } from "nitropack";
1
+ import { Nitro } from "nitro/types";
2
2
 
3
3
  //#region src/utils/type-generation.d.ts
4
4
  declare function serverTypeGeneration(app: Nitro): Promise<void>;
@@ -44,7 +44,8 @@ function generateNuxtOfetchClient(nitro, clientDir, serviceName = "default") {
44
44
  if (!ofetchPath) return;
45
45
  const serviceDir = dirname(ofetchPath);
46
46
  if (!existsSync(serviceDir)) mkdirSync(serviceDir, { recursive: true });
47
- if (!existsSync(ofetchPath)) writeFileIfNotExists(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
48
49
  // You can modify this file according to your needs
49
50
  import type { Requester } from './sdk'
50
51
  import { getSdk } from './sdk'
@@ -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 };