nitro-graphql 2.0.0-beta.37 → 2.0.0-beta.39

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 (204) hide show
  1. package/README.md +2 -2
  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 +43 -0
  7. package/dist/cli/commands/init.mjs +191 -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/{utils/codegen-plugin.d.mts → core/codegen/plugin.d.mts} +2 -2
  23. package/dist/{utils/codegen-plugin.mjs → core/codegen/plugin.mjs} +1 -1
  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/{codegen → core/codegen}/validation.d.mts +1 -1
  31. package/dist/{codegen → core/codegen}/validation.mjs +1 -1
  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/{utils/schema-builder.d.mts → core/schema/builder.d.mts} +7 -2
  53. package/dist/{utils/schema-builder.mjs → core/schema/builder.mjs} +22 -3
  54. package/dist/{utils → core/schema}/federation.d.mts +10 -5
  55. package/dist/{utils → core/schema}/federation.mjs +1 -1
  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/{types → core/types}/define.d.mts +3 -7
  62. package/dist/core/types/index.d.mts +5 -0
  63. package/dist/core/types/scanning.d.mts +69 -0
  64. package/dist/core/types/scanning.mjs +1 -0
  65. package/dist/{utils → core/utils}/directive-parser.d.mts +21 -5
  66. package/dist/{utils → core/utils}/directive-parser.mjs +25 -36
  67. package/dist/{utils → core/utils}/errors.d.mts +8 -4
  68. package/dist/{utils → core/utils}/errors.mjs +8 -4
  69. package/dist/core/utils/file-io.d.mts +24 -0
  70. package/dist/core/utils/file-io.mjs +47 -0
  71. package/dist/{utils → core/utils}/imports.d.mts +1 -1
  72. package/dist/{utils → core/utils}/imports.mjs +1 -1
  73. package/dist/core/utils/index.d.mts +7 -0
  74. package/dist/core/utils/index.mjs +8 -0
  75. package/dist/core/utils/logger.d.mts +19 -0
  76. package/dist/core/utils/logger.mjs +38 -0
  77. package/dist/{utils → core/utils}/ofetch-templates.d.mts +1 -1
  78. package/dist/{utils → core/utils}/ofetch-templates.mjs +1 -1
  79. package/dist/core/validation/external-services.d.mts +11 -0
  80. package/dist/{utils/validation.mjs → core/validation/external-services.mjs} +3 -3
  81. package/dist/core/validation/index.d.mts +2 -0
  82. package/dist/core/validation/index.mjs +3 -0
  83. package/dist/define.d.mts +2 -4
  84. package/dist/define.mjs +1 -1
  85. package/dist/index.d.mts +6 -44
  86. package/dist/index.mjs +5 -62
  87. package/dist/nitro/adapter.d.mts +30 -0
  88. package/dist/nitro/adapter.mjs +97 -0
  89. package/dist/{utils → nitro}/apollo.d.mts +1 -1
  90. package/dist/{utils → nitro}/apollo.mjs +1 -1
  91. package/dist/nitro/codegen.d.mts +19 -0
  92. package/dist/nitro/codegen.mjs +141 -0
  93. package/dist/nitro/config.d.mts +52 -0
  94. package/dist/nitro/config.mjs +58 -0
  95. package/dist/nitro/index.d.mts +46 -0
  96. package/dist/nitro/index.mjs +65 -0
  97. package/dist/{utils/path-resolver.d.mts → nitro/paths.d.mts} +3 -19
  98. package/dist/{utils/path-resolver.mjs → nitro/paths.mjs} +2 -36
  99. package/dist/{rollup.d.mts → nitro/rollup.d.mts} +1 -1
  100. package/dist/{rollup.mjs → nitro/rollup.mjs} +11 -23
  101. package/dist/{routes → nitro/routes}/apollo-server.d.mts +1 -1
  102. package/dist/{routes → nitro/routes}/apollo-server.mjs +5 -5
  103. package/dist/{routes → nitro/routes}/debug-template.d.mts +1 -1
  104. package/dist/{routes → nitro/routes}/debug-template.mjs +1 -1
  105. package/dist/{routes → nitro/routes}/debug.d.mts +10 -16
  106. package/dist/{routes → nitro/routes}/debug.mjs +2 -2
  107. package/dist/{routes → nitro/routes}/graphql-yoga.d.mts +1 -1
  108. package/dist/{routes → nitro/routes}/graphql-yoga.mjs +3 -3
  109. package/dist/{routes → nitro/routes}/health.d.mts +1 -1
  110. package/dist/{routes → nitro/routes}/health.mjs +1 -1
  111. package/dist/nitro/setup/file-watcher.d.mts +16 -0
  112. package/dist/{setup → nitro/setup}/file-watcher.mjs +14 -18
  113. package/dist/{setup.d.mts → nitro/setup/logging.d.mts} +5 -6
  114. package/dist/nitro/setup/logging.mjs +66 -0
  115. package/dist/nitro/setup/rollup-integration.d.mts +16 -0
  116. package/dist/{setup → nitro/setup}/rollup-integration.mjs +2 -2
  117. package/dist/nitro/setup/routes.d.mts +10 -0
  118. package/dist/nitro/setup/routes.mjs +35 -0
  119. package/dist/nitro/setup/ts-config.d.mts +11 -0
  120. package/dist/{setup → nitro/setup}/ts-config.mjs +3 -3
  121. package/dist/nitro/setup.d.mts +12 -0
  122. package/dist/{setup.mjs → nitro/setup.mjs} +33 -100
  123. package/dist/{types/index.d.mts → nitro/types.d.mts} +125 -43
  124. package/dist/nitro/types.mjs +1 -0
  125. package/dist/nitro/virtual/generators.d.mts +31 -0
  126. package/dist/nitro/virtual/generators.mjs +193 -0
  127. package/dist/nitro/virtual/stubs.d.mts +20 -0
  128. package/dist/nitro/virtual/stubs.mjs +31 -0
  129. package/dist/{ecosystem/nuxt.d.mts → nuxt.d.mts} +1 -1
  130. package/dist/{ecosystem/nuxt.mjs → nuxt.mjs} +2 -2
  131. package/dist/{graphql/server.d.mts → stubs/index.d.mts} +5 -1
  132. package/dist/stubs/index.mjs +1 -0
  133. package/package.json +45 -42
  134. package/dist/codegen/client-types.d.mts +0 -13
  135. package/dist/codegen/client-types.mjs +0 -131
  136. package/dist/codegen/external-types.d.mts +0 -12
  137. package/dist/codegen/external-types.mjs +0 -88
  138. package/dist/codegen/index.d.mts +0 -18
  139. package/dist/codegen/index.mjs +0 -24
  140. package/dist/codegen/server-types.d.mts +0 -13
  141. package/dist/codegen/server-types.mjs +0 -64
  142. package/dist/config/defaults.mjs +0 -36
  143. package/dist/constants/scalars.mjs +0 -27
  144. package/dist/constants.mjs +0 -106
  145. package/dist/graphql/index.d.mts +0 -5
  146. package/dist/setup/graphql-scanner.mjs +0 -25
  147. package/dist/setup/scaffold-generator.mjs +0 -109
  148. package/dist/types/standard-schema.d.mts +0 -59
  149. package/dist/utils/client-codegen.d.mts +0 -41
  150. package/dist/utils/client-codegen.mjs +0 -277
  151. package/dist/utils/file-generator.d.mts +0 -37
  152. package/dist/utils/file-generator.mjs +0 -72
  153. package/dist/utils/file-writer.d.mts +0 -35
  154. package/dist/utils/file-writer.mjs +0 -32
  155. package/dist/utils/index.d.mts +0 -13
  156. package/dist/utils/index.mjs +0 -13
  157. package/dist/utils/layers.d.mts +0 -22
  158. package/dist/utils/layers.mjs +0 -28
  159. package/dist/utils/scanning/common.d.mts +0 -23
  160. package/dist/utils/scanning/common.mjs +0 -39
  161. package/dist/utils/scanning/directives.d.mts +0 -11
  162. package/dist/utils/scanning/directives.mjs +0 -43
  163. package/dist/utils/scanning/documents.d.mts +0 -15
  164. package/dist/utils/scanning/documents.mjs +0 -46
  165. package/dist/utils/scanning/index.d.mts +0 -6
  166. package/dist/utils/scanning/index.mjs +0 -7
  167. package/dist/utils/scanning/resolvers.d.mts +0 -11
  168. package/dist/utils/scanning/resolvers.mjs +0 -100
  169. package/dist/utils/scanning/schemas.d.mts +0 -15
  170. package/dist/utils/scanning/schemas.mjs +0 -29
  171. package/dist/utils/server-codegen.d.mts +0 -7
  172. package/dist/utils/server-codegen.mjs +0 -113
  173. package/dist/utils/type-generation.d.mts +0 -6
  174. package/dist/utils/type-generation.mjs +0 -7
  175. package/dist/utils/validation.d.mts +0 -11
  176. package/dist/virtual/debug-info.d.mts +0 -9
  177. package/dist/virtual/debug-info.mjs +0 -26
  178. package/dist/virtual/generators/config.d.mts +0 -22
  179. package/dist/virtual/generators/config.mjs +0 -36
  180. package/dist/virtual/generators/debug.d.mts +0 -14
  181. package/dist/virtual/generators/debug.mjs +0 -53
  182. package/dist/virtual/generators/directives.d.mts +0 -14
  183. package/dist/virtual/generators/directives.mjs +0 -52
  184. package/dist/virtual/generators/index.d.mts +0 -6
  185. package/dist/virtual/generators/index.mjs +0 -7
  186. package/dist/virtual/generators/resolvers.d.mts +0 -14
  187. package/dist/virtual/generators/resolvers.mjs +0 -55
  188. package/dist/virtual/generators/schemas.d.mts +0 -14
  189. package/dist/virtual/generators/schemas.mjs +0 -43
  190. package/dist/virtual/graphql-config.d.mts +0 -9
  191. package/dist/virtual/graphql-config.mjs +0 -10
  192. package/dist/virtual/module-config.d.mts +0 -9
  193. package/dist/virtual/module-config.mjs +0 -10
  194. package/dist/virtual/server-directives.d.mts +0 -11
  195. package/dist/virtual/server-directives.mjs +0 -10
  196. package/dist/virtual/server-resolvers.d.mts +0 -11
  197. package/dist/virtual/server-resolvers.mjs +0 -10
  198. package/dist/virtual/server-schemas.d.mts +0 -11
  199. package/dist/virtual/server-schemas.mjs +0 -10
  200. /package/dist/{graphql/index.mjs → core/types/adapter.mjs} +0 -0
  201. /package/dist/{graphql/server.mjs → core/types/codegen.mjs} +0 -0
  202. /package/dist/{types/define.mjs → core/types/config.mjs} +0 -0
  203. /package/dist/{types/index.mjs → core/types/define.mjs} +0 -0
  204. /package/dist/{types/standard-schema.mjs → core/types/index.mjs} +0 -0
@@ -0,0 +1,212 @@
1
+ import { GraphQLFramework } from "../constants.mjs";
2
+
3
+ //#region src/core/types/config.d.ts
4
+
5
+ /**
6
+ * Core logger interface
7
+ * Abstracts logging functionality for framework independence
8
+ */
9
+ interface CoreLogger {
10
+ info: (message: string, ...args: unknown[]) => void;
11
+ warn: (message: string, ...args: unknown[]) => void;
12
+ error: (message: string, ...args: unknown[]) => void;
13
+ success: (message: string, ...args: unknown[]) => void;
14
+ debug: (message: string, ...args: unknown[]) => void;
15
+ }
16
+ /**
17
+ * GraphQL codegen configuration
18
+ */
19
+ interface CoreCodegenConfig {
20
+ /** Server-side codegen options */
21
+ server?: Record<string, unknown>;
22
+ /** Client-side codegen options */
23
+ client?: Record<string, unknown>;
24
+ /** Client SDK codegen options */
25
+ clientSDK?: Record<string, unknown>;
26
+ }
27
+ /**
28
+ * Security configuration options
29
+ */
30
+ interface CoreSecurityConfig {
31
+ /** Enable/disable GraphQL introspection */
32
+ introspection?: boolean;
33
+ /** Enable/disable GraphQL playground */
34
+ playground?: boolean;
35
+ /** Enable/disable error masking in responses */
36
+ maskErrors?: boolean;
37
+ /** Disable field suggestions in error messages */
38
+ disableSuggestions?: boolean;
39
+ }
40
+ /**
41
+ * External GraphQL service configuration
42
+ */
43
+ interface CoreExternalService {
44
+ /** Unique service name */
45
+ name: string;
46
+ /** GraphQL schema URL or file path */
47
+ schema: string;
48
+ /** GraphQL endpoint URL */
49
+ endpoint: string;
50
+ /** Headers for schema introspection */
51
+ headers?: Record<string, string> | (() => Record<string, string>);
52
+ /** Document patterns for this service */
53
+ documents?: string[];
54
+ /** Service-specific path overrides */
55
+ paths?: {
56
+ sdk?: string;
57
+ types?: string;
58
+ ofetch?: string;
59
+ };
60
+ }
61
+ /**
62
+ * Apollo Federation configuration
63
+ */
64
+ interface CoreFederationConfig {
65
+ /** Enable federation support */
66
+ enabled?: boolean;
67
+ /** Service name for federation */
68
+ serviceName?: string;
69
+ }
70
+ /**
71
+ * Path configuration with placeholders
72
+ */
73
+ interface CorePathsConfig {
74
+ /** Server GraphQL directory (default: 'server/graphql') */
75
+ serverGraphql?: string;
76
+ /** Client GraphQL directory (default: 'app/graphql' or 'graphql') */
77
+ clientGraphql?: string;
78
+ /** Build directory (default: '.nitro' or '.nuxt') */
79
+ buildDir?: string;
80
+ /** Types output directory (default: '{buildDir}/types') */
81
+ typesDir?: string;
82
+ }
83
+ /**
84
+ * Scaffold file generation configuration
85
+ */
86
+ interface CoreScaffoldConfig {
87
+ /** Master switch for all scaffold files */
88
+ enabled?: boolean;
89
+ /** Generate graphql.config.ts */
90
+ graphqlConfig?: boolean | string;
91
+ /** Generate server schema.ts */
92
+ serverSchema?: boolean | string;
93
+ /** Generate server config.ts */
94
+ serverConfig?: boolean | string;
95
+ /** Generate server context.d.ts */
96
+ serverContext?: boolean | string;
97
+ }
98
+ /**
99
+ * Type generation configuration
100
+ */
101
+ interface CoreTypesConfig {
102
+ /** Master switch for type generation */
103
+ enabled?: boolean;
104
+ /** Server types output path */
105
+ server?: boolean | string;
106
+ /** Client types output path */
107
+ client?: boolean | string;
108
+ /** External service types output path */
109
+ external?: boolean | string;
110
+ }
111
+ /**
112
+ * SDK generation configuration
113
+ */
114
+ interface CoreSdkConfig {
115
+ /** Master switch for SDK generation */
116
+ enabled?: boolean;
117
+ /** Main SDK output path */
118
+ main?: boolean | string;
119
+ /** External service SDK output path */
120
+ external?: boolean | string;
121
+ }
122
+ /**
123
+ * Client utilities configuration
124
+ */
125
+ interface CoreClientUtilsConfig {
126
+ /** Master switch for client utilities */
127
+ enabled?: boolean;
128
+ /** Index file output path */
129
+ index?: boolean | string;
130
+ /** Ofetch client output path */
131
+ ofetch?: boolean | string;
132
+ }
133
+ /**
134
+ * Core GraphQL options
135
+ * Framework-agnostic GraphQL configuration
136
+ */
137
+ interface CoreGraphQLOptions {
138
+ /** GraphQL framework to use */
139
+ framework?: GraphQLFramework;
140
+ /** GraphQL endpoint path */
141
+ endpoint?: string;
142
+ /** Codegen configuration */
143
+ codegen?: CoreCodegenConfig;
144
+ /** Security configuration */
145
+ security?: CoreSecurityConfig;
146
+ /** External GraphQL services */
147
+ externalServices?: CoreExternalService[];
148
+ /** Apollo Federation configuration */
149
+ federation?: CoreFederationConfig;
150
+ /** Path configuration */
151
+ paths?: CorePathsConfig;
152
+ /** Scaffold file configuration */
153
+ scaffold?: false | CoreScaffoldConfig;
154
+ /** Type generation configuration */
155
+ types?: false | CoreTypesConfig;
156
+ /** SDK generation configuration */
157
+ sdk?: false | CoreSdkConfig;
158
+ /** Client utilities configuration */
159
+ clientUtils?: false | CoreClientUtilsConfig;
160
+ }
161
+ /**
162
+ * Core configuration
163
+ * Main configuration interface that replaces Nitro-specific options
164
+ */
165
+ interface CoreConfig {
166
+ /** Root directory of the project */
167
+ rootDir: string;
168
+ /** Build output directory */
169
+ buildDir: string;
170
+ /** Server GraphQL directory */
171
+ serverDir: string;
172
+ /** Client GraphQL directory */
173
+ clientDir: string;
174
+ /** Types output directory */
175
+ typesDir: string;
176
+ /** GraphQL framework to use */
177
+ framework: GraphQLFramework;
178
+ /** Whether running in Nuxt context */
179
+ isNuxt: boolean;
180
+ /** Whether running in development mode */
181
+ isDev: boolean;
182
+ /** GraphQL options */
183
+ graphqlOptions: CoreGraphQLOptions;
184
+ /** Logger instance */
185
+ logger: CoreLogger;
186
+ /** Patterns to ignore during scanning */
187
+ ignorePatterns: string[];
188
+ /** Layer server directories (Nuxt) */
189
+ layerServerDirs?: string[];
190
+ /** Layer app directories (Nuxt) */
191
+ layerAppDirs?: string[];
192
+ }
193
+ /**
194
+ * Core context for runtime operations
195
+ * Holds resolved configuration and state
196
+ */
197
+ interface CoreContext {
198
+ /** Resolved configuration */
199
+ config: CoreConfig;
200
+ /** GraphQL build directory */
201
+ graphqlBuildDir: string;
202
+ /** Watch directories for file watching */
203
+ watchDirs: string[];
204
+ /** Relative directory paths */
205
+ dir: {
206
+ build: string;
207
+ client: string;
208
+ server: string;
209
+ };
210
+ }
211
+ //#endregion
212
+ export { CoreClientUtilsConfig, CoreCodegenConfig, CoreConfig, CoreContext, CoreExternalService, CoreFederationConfig, CoreGraphQLOptions, CoreLogger, CorePathsConfig, CoreScaffoldConfig, CoreSdkConfig, CoreSecurityConfig, CoreTypesConfig };
@@ -1,12 +1,8 @@
1
1
  import { GraphQLSchema } from "graphql";
2
- import { ApolloServerOptions } from "@apollo/server";
3
- import { H3Event } from "nitro/h3";
4
- import { YogaServerOptions } from "graphql-yoga";
5
- import { NPMConfig } from "#graphql/server";
6
2
 
7
- //#region src/types/define.d.ts
3
+ //#region src/core/types/define.d.ts
4
+
8
5
  type Flatten<T> = T extends infer U ? { [K in keyof U]: U[K] } : never;
9
- type DefineServerConfig<T extends NPMConfig = NPMConfig> = T['framework'] extends 'graphql-yoga' ? Partial<YogaServerOptions<H3Event, Partial<H3Event>>> : T['framework'] extends 'apollo-server' ? Partial<ApolloServerOptions<H3Event>> : Partial<YogaServerOptions<H3Event, Partial<H3Event>>> | Partial<ApolloServerOptions<H3Event>>;
10
6
  type DirectiveLocationName = 'QUERY' | 'MUTATION' | 'SUBSCRIPTION' | 'FIELD' | 'FRAGMENT_DEFINITION' | 'FRAGMENT_SPREAD' | 'INLINE_FRAGMENT' | 'VARIABLE_DEFINITION' | 'SCHEMA' | 'SCALAR' | 'OBJECT' | 'FIELD_DEFINITION' | 'ARGUMENT_DEFINITION' | 'INTERFACE' | 'UNION' | 'ENUM' | 'ENUM_VALUE' | 'INPUT_OBJECT' | 'INPUT_FIELD_DEFINITION';
11
7
  type GraphQLScalarType = 'String' | 'Int' | 'Float' | 'Boolean' | 'ID' | 'JSON' | 'DateTime';
12
8
  type GraphQLBaseType = GraphQLScalarType | (string & {});
@@ -46,4 +42,4 @@ interface DefineDirectiveConfig {
46
42
  transformer?: (schema: GraphQLSchema) => GraphQLSchema;
47
43
  }
48
44
  //#endregion
49
- export { DefineDirectiveConfig, DefineServerConfig, DirectiveArgument, DirectiveDefinition, Flatten, GraphQLArgumentType, GraphQLBaseType, GraphQLScalarType };
45
+ export { DefineDirectiveConfig, DirectiveArgument, DirectiveDefinition, Flatten, GraphQLArgumentType, GraphQLBaseType, GraphQLScalarType };
@@ -0,0 +1,5 @@
1
+ import { ClientCodegenConfig, ClientCodegenInput, ClientCodegenResult, ExternalServiceCodegenConfig, ScalarType, SchemaLoadOptions, SdkCodegenConfig, ServerCodegenConfig, ServerCodegenInput, ServerCodegenResult } from "./codegen.mjs";
2
+ import { CoreClientUtilsConfig, CoreCodegenConfig, CoreConfig, CoreContext, CoreExternalService, CoreFederationConfig, CoreGraphQLOptions, CoreLogger, CorePathsConfig, CoreScaffoldConfig, CoreSdkConfig, CoreSecurityConfig, CoreTypesConfig } from "./config.mjs";
3
+ import { DefineDirectiveConfig, DirectiveArgument, DirectiveDefinition, Flatten, GraphQLArgumentType, GraphQLBaseType, GraphQLScalarType } from "./define.mjs";
4
+ import { ResolverImport, ScanContext, ScanResult, ScannedFile, ScannedResolver } from "./scanning.mjs";
5
+ export { ClientCodegenConfig, ClientCodegenInput, ClientCodegenResult, CoreClientUtilsConfig, CoreCodegenConfig, CoreConfig, CoreContext, CoreExternalService, CoreFederationConfig, CoreGraphQLOptions, CoreLogger, CorePathsConfig, CoreScaffoldConfig, CoreSdkConfig, CoreSecurityConfig, CoreTypesConfig, DefineDirectiveConfig, DirectiveArgument, DirectiveDefinition, ExternalServiceCodegenConfig, Flatten, GraphQLArgumentType, GraphQLBaseType, GraphQLScalarType, ResolverImport, ScalarType, ScanContext, ScanResult, ScannedFile, ScannedResolver, SchemaLoadOptions, SdkCodegenConfig, ServerCodegenConfig, ServerCodegenInput, ServerCodegenResult };
@@ -0,0 +1,69 @@
1
+ import { CoreLogger } from "./config.mjs";
2
+
3
+ //#region src/core/types/scanning.d.ts
4
+
5
+ /**
6
+ * Scan context for file scanning operations
7
+ * Provides all necessary information for scanning without framework dependencies
8
+ */
9
+ interface ScanContext {
10
+ /** Root directory of the project */
11
+ rootDir: string;
12
+ /** Server GraphQL directory */
13
+ serverDir: string;
14
+ /** Client GraphQL directory */
15
+ clientDir: string;
16
+ /** Patterns to ignore during scanning */
17
+ ignorePatterns: string[];
18
+ /** Whether running in development mode */
19
+ isDev: boolean;
20
+ /** Logger instance */
21
+ logger: CoreLogger;
22
+ /** Layer server directories (Nuxt layers) */
23
+ layerServerDirs?: string[];
24
+ /** Layer app directories (Nuxt layers) */
25
+ layerAppDirs?: string[];
26
+ }
27
+ /**
28
+ * Generic scan result wrapper
29
+ * Provides consistent result structure with warnings and errors
30
+ */
31
+ interface ScanResult<T> {
32
+ /** Scanned items */
33
+ items: T[];
34
+ /** Non-fatal warnings encountered during scanning */
35
+ warnings: string[];
36
+ /** Errors encountered during scanning */
37
+ errors: string[];
38
+ }
39
+ /**
40
+ * File information from scanning
41
+ */
42
+ interface ScannedFile {
43
+ /** Relative path from scan directory */
44
+ path: string;
45
+ /** Absolute file path */
46
+ fullPath: string;
47
+ }
48
+ /**
49
+ * Resolver import information
50
+ */
51
+ interface ResolverImport {
52
+ /** Export name */
53
+ name: string;
54
+ /** Resolver type (query, mutation, resolver, type, subscription, directive) */
55
+ type: 'query' | 'mutation' | 'resolver' | 'type' | 'subscription' | 'directive';
56
+ /** Aliased import name */
57
+ as: string;
58
+ }
59
+ /**
60
+ * Scanned resolver information
61
+ */
62
+ interface ScannedResolver {
63
+ /** File specifier (path) */
64
+ specifier: string;
65
+ /** Exports from this file */
66
+ imports: ResolverImport[];
67
+ }
68
+ //#endregion
69
+ export { ResolverImport, ScanContext, ScanResult, ScannedFile, ScannedResolver };
@@ -0,0 +1 @@
1
+ export { };
@@ -1,4 +1,8 @@
1
- //#region src/utils/directive-parser.d.ts
1
+ //#region src/core/utils/directive-parser.d.ts
2
+ /**
3
+ * Directive parser utilities
4
+ * AST-based parsing for GraphQL directive definitions
5
+ */
2
6
  interface ParsedDirective {
3
7
  name: string;
4
8
  locations: string[];
@@ -69,13 +73,25 @@ declare class DirectiveParser {
69
73
  */
70
74
  declare function generateDirectiveSchema(directive: ParsedDirective): string;
71
75
  /**
72
- * Generate directive schemas file from scanned directives
73
- * @returns The path to the generated _directives.graphql file, or null if no directives
76
+ * Directive file reference
77
+ * Can be either { fullPath } or { specifier } (for GenImport compatibility)
74
78
  */
75
- declare function generateDirectiveSchemas(nitro: any, directives: any[]): Promise<string | null>;
79
+ type DirectiveFileRef = {
80
+ fullPath: string;
81
+ } | {
82
+ specifier: string;
83
+ };
76
84
  /**
77
85
  * Singleton instance for reuse
78
86
  */
79
87
  declare const directiveParser: DirectiveParser;
88
+ /**
89
+ * Generate GraphQL schemas from an array of parsed directives
90
+ */
91
+ declare function generateDirectiveSchemas(nitro: {
92
+ graphql: {
93
+ buildDir: string;
94
+ };
95
+ }, directives: DirectiveFileRef[]): Promise<string | null>;
80
96
  //#endregion
81
- export { DirectiveParser, ParsedDirective, directiveParser, generateDirectiveSchema, generateDirectiveSchemas };
97
+ export { DirectiveFileRef, DirectiveParser, ParsedDirective, directiveParser, generateDirectiveSchema, generateDirectiveSchemas };
@@ -1,4 +1,4 @@
1
- //#region src/utils/directive-parser.ts
1
+ //#region src/core/utils/directive-parser.ts
2
2
  /**
3
3
  * Clean AST-based directive parser using oxc-parser
4
4
  */
@@ -180,47 +180,36 @@ function generateDirectiveSchema(directive) {
180
180
  return `directive @${directive.name}${args} on ${locations}`;
181
181
  }
182
182
  /**
183
- * Generate directive schemas file from scanned directives
184
- * @returns The path to the generated _directives.graphql file, or null if no directives
183
+ * Get the file path from a directive reference
185
184
  */
186
- async function generateDirectiveSchemas(nitro, directives) {
187
- if (directives.length === 0) return null;
188
- const { existsSync, readFileSync, writeFileSync, mkdirSync } = await import("node:fs");
189
- const { readFile } = await import("node:fs/promises");
190
- const { resolve, dirname } = await import("pathe");
191
- const directiveSchemas = [];
192
- const seenDirectives = /* @__PURE__ */ new Set();
193
- const parser = new DirectiveParser();
194
- for (const dir of directives) for (const _imp of dir.imports) {
195
- const fileContent = await readFile(dir.specifier, "utf-8");
196
- const directiveDefs = await parser.parseDirectives(fileContent, dir.specifier);
197
- for (const def of directiveDefs) {
198
- if (seenDirectives.has(def.name)) continue;
199
- seenDirectives.add(def.name);
200
- const schema = generateDirectiveSchema(def);
201
- directiveSchemas.push(schema);
202
- }
203
- }
204
- if (directiveSchemas.length > 0) {
205
- const directivesPath = resolve(nitro.graphql.buildDir, "_directives.graphql");
206
- const content = `# WARNING: This file is auto-generated by nitro-graphql
207
- # Do not modify this file directly. It will be overwritten.
208
- # To define custom directives, create .directive.ts files using defineDirective()
209
-
210
- ${directiveSchemas.join("\n\n")}`;
211
- const targetDir = dirname(directivesPath);
212
- if (!existsSync(targetDir)) mkdirSync(targetDir, { recursive: true });
213
- let shouldWrite = true;
214
- if (existsSync(directivesPath)) shouldWrite = readFileSync(directivesPath, "utf-8") !== content;
215
- if (shouldWrite) writeFileSync(directivesPath, content, "utf-8");
216
- return directivesPath;
217
- }
218
- return null;
185
+ function getFilePath(ref) {
186
+ return "fullPath" in ref ? ref.fullPath : ref.specifier;
219
187
  }
220
188
  /**
221
189
  * Singleton instance for reuse
222
190
  */
223
191
  const directiveParser = new DirectiveParser();
192
+ /**
193
+ * Generate GraphQL schemas from an array of parsed directives
194
+ */
195
+ async function generateDirectiveSchemas(nitro, directives) {
196
+ if (directives.length === 0) return null;
197
+ const fs = await import("node:fs");
198
+ const path = await import("pathe");
199
+ const allParsedDirectives = [];
200
+ for (const directive of directives) try {
201
+ const filePath = getFilePath(directive);
202
+ const content = fs.readFileSync(filePath, "utf-8");
203
+ const parsed = await directiveParser.parseDirectives(content, filePath);
204
+ allParsedDirectives.push(...parsed);
205
+ } catch {}
206
+ if (allParsedDirectives.length === 0) return null;
207
+ const schemaContent = allParsedDirectives.map((d) => generateDirectiveSchema(d)).join("\n\n");
208
+ const directivesPath = path.join(nitro.graphql.buildDir, "_directives.graphql");
209
+ fs.mkdirSync(path.dirname(directivesPath), { recursive: true });
210
+ fs.writeFileSync(directivesPath, schemaContent, "utf-8");
211
+ return directivesPath;
212
+ }
224
213
 
225
214
  //#endregion
226
215
  export { DirectiveParser, directiveParser, generateDirectiveSchema, generateDirectiveSchemas };
@@ -1,4 +1,8 @@
1
- //#region src/utils/errors.d.ts
1
+ //#region src/core/utils/errors.d.ts
2
+ /**
3
+ * Error handling utilities for GraphQL
4
+ * Framework-agnostic error masking and handling
5
+ */
2
6
  interface MaskErrorOptions {
3
7
  /**
4
8
  * Default HTTP status code for validation errors (ZodError)
@@ -20,7 +24,7 @@ interface MaskErrorOptions {
20
24
  * @example Basic usage
21
25
  * ```ts
22
26
  * import { defineGraphQLConfig } from 'nitro-graphql/define'
23
- * import { createDefaultMaskError } from 'nitro-graphql/utils'
27
+ * import { createDefaultMaskError } from 'nitro-graphql/core'
24
28
  *
25
29
  * export default defineGraphQLConfig({
26
30
  * maskedErrors: {
@@ -32,7 +36,7 @@ interface MaskErrorOptions {
32
36
  * @example Custom status codes
33
37
  * ```ts
34
38
  * import { defineGraphQLConfig } from 'nitro-graphql/define'
35
- * import { createDefaultMaskError } from 'nitro-graphql/utils'
39
+ * import { createDefaultMaskError } from 'nitro-graphql/core'
36
40
  *
37
41
  * export default defineGraphQLConfig({
38
42
  * maskedErrors: {
@@ -47,7 +51,7 @@ interface MaskErrorOptions {
47
51
  * @example Custom error handling with fallback to default
48
52
  * ```ts
49
53
  * import { defineGraphQLConfig } from 'nitro-graphql/define'
50
- * import { createDefaultMaskError } from 'nitro-graphql/utils'
54
+ * import { createDefaultMaskError } from 'nitro-graphql/core'
51
55
  *
52
56
  * const defaultMaskError = createDefaultMaskError()
53
57
  *
@@ -1,6 +1,10 @@
1
1
  import { GraphQLError } from "graphql";
2
2
 
3
- //#region src/utils/errors.ts
3
+ //#region src/core/utils/errors.ts
4
+ /**
5
+ * Error handling utilities for GraphQL
6
+ * Framework-agnostic error masking and handling
7
+ */
4
8
  /**
5
9
  * Default error masking function for GraphQL Yoga
6
10
  * Handles common error types like ZodError and HTTPError
@@ -10,7 +14,7 @@ import { GraphQLError } from "graphql";
10
14
  * @example Basic usage
11
15
  * ```ts
12
16
  * import { defineGraphQLConfig } from 'nitro-graphql/define'
13
- * import { createDefaultMaskError } from 'nitro-graphql/utils'
17
+ * import { createDefaultMaskError } from 'nitro-graphql/core'
14
18
  *
15
19
  * export default defineGraphQLConfig({
16
20
  * maskedErrors: {
@@ -22,7 +26,7 @@ import { GraphQLError } from "graphql";
22
26
  * @example Custom status codes
23
27
  * ```ts
24
28
  * import { defineGraphQLConfig } from 'nitro-graphql/define'
25
- * import { createDefaultMaskError } from 'nitro-graphql/utils'
29
+ * import { createDefaultMaskError } from 'nitro-graphql/core'
26
30
  *
27
31
  * export default defineGraphQLConfig({
28
32
  * maskedErrors: {
@@ -37,7 +41,7 @@ import { GraphQLError } from "graphql";
37
41
  * @example Custom error handling with fallback to default
38
42
  * ```ts
39
43
  * import { defineGraphQLConfig } from 'nitro-graphql/define'
40
- * import { createDefaultMaskError } from 'nitro-graphql/utils'
44
+ * import { createDefaultMaskError } from 'nitro-graphql/core'
41
45
  *
42
46
  * const defaultMaskError = createDefaultMaskError()
43
47
  *
@@ -0,0 +1,24 @@
1
+ //#region src/core/utils/file-io.d.ts
2
+ /**
3
+ * Unified file I/O utilities
4
+ * Centralizes file writing patterns used across the codebase
5
+ */
6
+ /**
7
+ * Write file with automatic directory creation
8
+ */
9
+ declare function writeFile(path: string, content: string): void;
10
+ /**
11
+ * Write file only if content changed (for dev mode optimization)
12
+ * Returns true if file was written, false if unchanged
13
+ */
14
+ declare function writeFileIfChanged(path: string, content: string): boolean;
15
+ /**
16
+ * Ensure directory exists
17
+ */
18
+ declare function ensureDir(path: string): void;
19
+ /**
20
+ * Read file safely, returns undefined if file doesn't exist
21
+ */
22
+ declare function readFileSafe(path: string): string | undefined;
23
+ //#endregion
24
+ export { ensureDir, readFileSafe, writeFile, writeFileIfChanged };
@@ -0,0 +1,47 @@
1
+ import { dirname } from "pathe";
2
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
3
+
4
+ //#region src/core/utils/file-io.ts
5
+ /**
6
+ * Unified file I/O utilities
7
+ * Centralizes file writing patterns used across the codebase
8
+ */
9
+ /**
10
+ * Write file with automatic directory creation
11
+ */
12
+ function writeFile(path, content) {
13
+ mkdirSync(dirname(path), { recursive: true });
14
+ writeFileSync(path, content, "utf-8");
15
+ }
16
+ /**
17
+ * Write file only if content changed (for dev mode optimization)
18
+ * Returns true if file was written, false if unchanged
19
+ */
20
+ function writeFileIfChanged(path, content) {
21
+ try {
22
+ if (existsSync(path)) {
23
+ if (readFileSync(path, "utf-8") === content) return false;
24
+ }
25
+ } catch {}
26
+ writeFile(path, content);
27
+ return true;
28
+ }
29
+ /**
30
+ * Ensure directory exists
31
+ */
32
+ function ensureDir(path) {
33
+ mkdirSync(path, { recursive: true });
34
+ }
35
+ /**
36
+ * Read file safely, returns undefined if file doesn't exist
37
+ */
38
+ function readFileSafe(path) {
39
+ try {
40
+ return readFileSync(path, "utf-8");
41
+ } catch {
42
+ return;
43
+ }
44
+ }
45
+
46
+ //#endregion
47
+ export { ensureDir, readFileSafe, writeFile, writeFileIfChanged };
@@ -1,4 +1,4 @@
1
- //#region src/utils/imports.d.ts
1
+ //#region src/core/utils/imports.d.ts
2
2
  /**
3
3
  * Import utilities
4
4
  * Helpers for generating import IDs and relative paths
@@ -1,7 +1,7 @@
1
1
  import { relative } from "pathe";
2
2
  import { hash } from "ohash";
3
3
 
4
- //#region src/utils/imports.ts
4
+ //#region src/core/utils/imports.ts
5
5
  /**
6
6
  * Import utilities
7
7
  * Helpers for generating import IDs and relative paths
@@ -0,0 +1,7 @@
1
+ import { DirectiveFileRef, DirectiveParser, ParsedDirective, directiveParser, generateDirectiveSchema, generateDirectiveSchemas } from "./directive-parser.mjs";
2
+ import { MaskErrorOptions, createDefaultMaskError } from "./errors.mjs";
3
+ import { ensureDir, readFileSafe, writeFile, writeFileIfChanged } from "./file-io.mjs";
4
+ import { getImportId, relativeWithDot } from "./imports.mjs";
5
+ import { createLogger, createSilentLogger, defaultLogger } from "./logger.mjs";
6
+ import { OfetchTemplateOptions, generateOfetchTemplate } from "./ofetch-templates.mjs";
7
+ export { DirectiveFileRef, DirectiveParser, MaskErrorOptions, OfetchTemplateOptions, ParsedDirective, createDefaultMaskError, createLogger, createSilentLogger, defaultLogger, directiveParser, ensureDir, generateDirectiveSchema, generateDirectiveSchemas, generateOfetchTemplate, getImportId, readFileSafe, relativeWithDot, writeFile, writeFileIfChanged };
@@ -0,0 +1,8 @@
1
+ import { ensureDir, readFileSafe, writeFile, writeFileIfChanged } from "./file-io.mjs";
2
+ import { createLogger, createSilentLogger, defaultLogger } from "./logger.mjs";
3
+ import { DirectiveParser, directiveParser, generateDirectiveSchema, generateDirectiveSchemas } from "./directive-parser.mjs";
4
+ import { createDefaultMaskError } from "./errors.mjs";
5
+ import { getImportId, relativeWithDot } from "./imports.mjs";
6
+ import { generateOfetchTemplate } from "./ofetch-templates.mjs";
7
+
8
+ export { DirectiveParser, createDefaultMaskError, createLogger, createSilentLogger, defaultLogger, directiveParser, ensureDir, generateDirectiveSchema, generateDirectiveSchemas, generateOfetchTemplate, getImportId, readFileSafe, relativeWithDot, writeFile, writeFileIfChanged };
@@ -0,0 +1,19 @@
1
+ import { CoreLogger } from "../types/config.mjs";
2
+
3
+ //#region src/core/utils/logger.d.ts
4
+
5
+ /**
6
+ * Create a logger instance with the nitro-graphql tag
7
+ */
8
+ declare function createLogger(tag?: string): CoreLogger;
9
+ /**
10
+ * Default logger instance
11
+ */
12
+ declare const defaultLogger: CoreLogger;
13
+ /**
14
+ * Create a silent logger (no output)
15
+ * Useful for testing or when logging should be suppressed
16
+ */
17
+ declare function createSilentLogger(): CoreLogger;
18
+ //#endregion
19
+ export { createLogger, createSilentLogger, defaultLogger };
@@ -0,0 +1,38 @@
1
+ import { LOG_TAG } from "../constants.mjs";
2
+ import { consola as consola$1 } from "consola";
3
+
4
+ //#region src/core/utils/logger.ts
5
+ /**
6
+ * Create a logger instance with the nitro-graphql tag
7
+ */
8
+ function createLogger(tag = LOG_TAG) {
9
+ const logger = consola$1.withTag(tag);
10
+ return {
11
+ info: (message, ...args) => logger.info(message, ...args),
12
+ warn: (message, ...args) => logger.warn(message, ...args),
13
+ error: (message, ...args) => logger.error(message, ...args),
14
+ success: (message, ...args) => logger.success(message, ...args),
15
+ debug: (message, ...args) => logger.debug(message, ...args)
16
+ };
17
+ }
18
+ /**
19
+ * Default logger instance
20
+ */
21
+ const defaultLogger = createLogger();
22
+ /**
23
+ * Create a silent logger (no output)
24
+ * Useful for testing or when logging should be suppressed
25
+ */
26
+ function createSilentLogger() {
27
+ const noop = () => {};
28
+ return {
29
+ info: noop,
30
+ warn: noop,
31
+ error: noop,
32
+ success: noop,
33
+ debug: noop
34
+ };
35
+ }
36
+
37
+ //#endregion
38
+ export { createLogger, createSilentLogger, defaultLogger };