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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/README.md +441 -27
  2. package/dist/cli/commands/generate.d.mts +26 -0
  3. package/dist/cli/commands/generate.mjs +196 -0
  4. package/dist/cli/commands/index.d.mts +4 -0
  5. package/dist/cli/commands/index.mjs +5 -0
  6. package/dist/cli/commands/init.d.mts +46 -0
  7. package/dist/cli/commands/init.mjs +195 -0
  8. package/dist/cli/commands/validate.d.mts +10 -0
  9. package/dist/cli/commands/validate.mjs +69 -0
  10. package/dist/cli/completions.d.mts +7 -0
  11. package/dist/cli/completions.mjs +34 -0
  12. package/dist/cli/config.d.mts +75 -0
  13. package/dist/cli/config.mjs +20 -0
  14. package/dist/cli/index.d.mts +24 -0
  15. package/dist/cli/index.mjs +253 -0
  16. package/dist/core/codegen/client.d.mts +23 -0
  17. package/dist/core/codegen/client.mjs +150 -0
  18. package/dist/core/codegen/document-loader.d.mts +10 -0
  19. package/dist/core/codegen/document-loader.mjs +18 -0
  20. package/dist/core/codegen/index.d.mts +8 -0
  21. package/dist/core/codegen/index.mjs +9 -0
  22. package/dist/core/codegen/plugin.d.mts +20 -0
  23. package/dist/core/codegen/plugin.mjs +30 -0
  24. package/dist/core/codegen/runtime.d.mts +20 -0
  25. package/dist/core/codegen/runtime.mjs +60 -0
  26. package/dist/core/codegen/schema-loader.d.mts +28 -0
  27. package/dist/core/codegen/schema-loader.mjs +128 -0
  28. package/dist/core/codegen/server.d.mts +28 -0
  29. package/dist/core/codegen/server.mjs +143 -0
  30. package/dist/core/codegen/validation.d.mts +13 -0
  31. package/dist/core/codegen/validation.mjs +96 -0
  32. package/dist/core/config.d.mts +50 -0
  33. package/dist/core/config.mjs +82 -0
  34. package/dist/core/constants.d.mts +188 -0
  35. package/dist/core/constants.mjs +210 -0
  36. package/dist/core/index.d.mts +32 -0
  37. package/dist/core/index.mjs +26 -0
  38. package/dist/core/scanning/ast-scanner.d.mts +23 -0
  39. package/dist/core/scanning/ast-scanner.mjs +103 -0
  40. package/dist/core/scanning/common.d.mts +37 -0
  41. package/dist/core/scanning/common.mjs +60 -0
  42. package/dist/core/scanning/directives.d.mts +10 -0
  43. package/dist/core/scanning/directives.mjs +29 -0
  44. package/dist/core/scanning/documents.d.mts +21 -0
  45. package/dist/core/scanning/documents.mjs +43 -0
  46. package/dist/core/scanning/index.d.mts +7 -0
  47. package/dist/core/scanning/index.mjs +8 -0
  48. package/dist/core/scanning/resolvers.d.mts +10 -0
  49. package/dist/core/scanning/resolvers.mjs +58 -0
  50. package/dist/core/scanning/schemas.d.mts +14 -0
  51. package/dist/core/scanning/schemas.mjs +64 -0
  52. package/dist/core/schema/builder.d.mts +53 -0
  53. package/dist/core/schema/builder.mjs +70 -0
  54. package/dist/core/schema/federation.d.mts +34 -0
  55. package/dist/core/schema/federation.mjs +40 -0
  56. package/dist/core/schema/index.d.mts +3 -0
  57. package/dist/core/schema/index.mjs +4 -0
  58. package/dist/core/types/adapter.d.mts +58 -0
  59. package/dist/core/types/codegen.d.mts +133 -0
  60. package/dist/core/types/config.d.mts +212 -0
  61. package/dist/core/types/config.mjs +1 -0
  62. package/dist/{utils/define.d.ts → core/types/define.d.mts} +3 -30
  63. package/dist/core/types/define.mjs +1 -0
  64. package/dist/core/types/index.d.mts +5 -0
  65. package/dist/core/types/index.mjs +1 -0
  66. package/dist/core/types/scanning.d.mts +69 -0
  67. package/dist/core/types/scanning.mjs +1 -0
  68. package/dist/{utils/directive-parser.d.ts → core/utils/directive-parser.d.mts} +21 -4
  69. package/dist/{utils/directive-parser.js → core/utils/directive-parser.mjs} +25 -34
  70. package/dist/core/utils/errors.d.mts +77 -0
  71. package/dist/core/utils/errors.mjs +93 -0
  72. package/dist/core/utils/file-io.d.mts +24 -0
  73. package/dist/core/utils/file-io.mjs +47 -0
  74. package/dist/core/utils/imports.d.mts +15 -0
  75. package/dist/core/utils/imports.mjs +25 -0
  76. package/dist/core/utils/index.d.mts +7 -0
  77. package/dist/core/utils/index.mjs +8 -0
  78. package/dist/core/utils/logger.d.mts +19 -0
  79. package/dist/core/utils/logger.mjs +38 -0
  80. package/dist/core/utils/ofetch-templates.d.mts +30 -0
  81. package/dist/core/utils/ofetch-templates.mjs +135 -0
  82. package/dist/core/validation/external-services.d.mts +11 -0
  83. package/dist/core/validation/external-services.mjs +34 -0
  84. package/dist/core/validation/index.d.mts +2 -0
  85. package/dist/core/validation/index.mjs +3 -0
  86. package/dist/define.d.mts +294 -0
  87. package/dist/define.mjs +323 -0
  88. package/dist/index.d.mts +6 -0
  89. package/dist/index.mjs +6 -0
  90. package/dist/nitro/adapter.d.mts +30 -0
  91. package/dist/nitro/adapter.mjs +97 -0
  92. package/dist/{utils/apollo.d.ts → nitro/apollo.d.mts} +3 -3
  93. package/dist/nitro/apollo.mjs +59 -0
  94. package/dist/nitro/codegen.d.mts +19 -0
  95. package/dist/nitro/codegen.mjs +141 -0
  96. package/dist/nitro/config.d.mts +52 -0
  97. package/dist/nitro/config.mjs +58 -0
  98. package/dist/nitro/index.d.mts +46 -0
  99. package/dist/nitro/index.mjs +65 -0
  100. package/dist/nitro/paths.d.mts +54 -0
  101. package/dist/nitro/paths.mjs +93 -0
  102. package/dist/nitro/rollup.d.mts +6 -0
  103. package/dist/nitro/rollup.mjs +95 -0
  104. package/dist/nitro/routes/apollo-server.d.mts +6 -0
  105. package/dist/nitro/routes/apollo-server.mjs +71 -0
  106. package/dist/nitro/routes/debug-template.d.mts +15 -0
  107. package/dist/nitro/routes/debug-template.mjs +385 -0
  108. package/dist/nitro/routes/debug.d.mts +55 -0
  109. package/dist/nitro/routes/debug.mjs +102 -0
  110. package/dist/nitro/routes/graphql-yoga.d.mts +6 -0
  111. package/dist/nitro/routes/graphql-yoga.mjs +62 -0
  112. package/dist/nitro/routes/health.d.mts +10 -0
  113. package/dist/{routes/health.js → nitro/routes/health.mjs} +4 -3
  114. package/dist/nitro/setup/file-watcher.d.mts +16 -0
  115. package/dist/nitro/setup/file-watcher.mjs +80 -0
  116. package/dist/nitro/setup/logging.d.mts +17 -0
  117. package/dist/nitro/setup/logging.mjs +66 -0
  118. package/dist/nitro/setup/rollup-integration.d.mts +16 -0
  119. package/dist/nitro/setup/rollup-integration.mjs +90 -0
  120. package/dist/nitro/setup/routes.d.mts +10 -0
  121. package/dist/nitro/setup/routes.mjs +35 -0
  122. package/dist/nitro/setup/ts-config.d.mts +11 -0
  123. package/dist/nitro/setup/ts-config.mjs +69 -0
  124. package/dist/nitro/setup.d.mts +12 -0
  125. package/dist/nitro/setup.mjs +231 -0
  126. package/dist/nitro/types.d.mts +378 -0
  127. package/dist/nitro/types.mjs +1 -0
  128. package/dist/nitro/virtual/generators.d.mts +31 -0
  129. package/dist/nitro/virtual/generators.mjs +193 -0
  130. package/dist/nitro/virtual/stubs.d.mts +20 -0
  131. package/dist/nitro/virtual/stubs.mjs +31 -0
  132. package/dist/{ecosystem/nuxt.d.ts → nuxt.d.mts} +1 -1
  133. package/dist/nuxt.mjs +109 -0
  134. package/dist/{graphql/server.d.ts → stubs/index.d.mts} +5 -1
  135. package/dist/stubs/index.mjs +1 -0
  136. package/package.json +97 -78
  137. package/dist/ecosystem/nuxt.js +0 -67
  138. package/dist/graphql/index.d.ts +0 -5
  139. package/dist/index.d.ts +0 -8
  140. package/dist/index.js +0 -264
  141. package/dist/rollup.js +0 -119
  142. package/dist/routes/apollo-server.d.ts +0 -6
  143. package/dist/routes/apollo-server.js +0 -89
  144. package/dist/routes/graphql-yoga.d.ts +0 -6
  145. package/dist/routes/graphql-yoga.js +0 -91
  146. package/dist/routes/health.d.ts +0 -6
  147. package/dist/types/index.d.ts +0 -128
  148. package/dist/types/standard-schema.d.ts +0 -59
  149. package/dist/utils/apollo.js +0 -61
  150. package/dist/utils/client-codegen.d.ts +0 -38
  151. package/dist/utils/client-codegen.js +0 -290
  152. package/dist/utils/define.js +0 -57
  153. package/dist/utils/index.d.ts +0 -39
  154. package/dist/utils/index.js +0 -250
  155. package/dist/utils/server-codegen.d.ts +0 -7
  156. package/dist/utils/server-codegen.js +0 -136
  157. package/dist/utils/type-generation.d.ts +0 -7
  158. package/dist/utils/type-generation.js +0 -287
  159. package/dist/vite.d.ts +0 -25
  160. package/dist/vite.js +0 -40
  161. /package/dist/{graphql/index.js → core/types/adapter.mjs} +0 -0
  162. /package/dist/{graphql/server.js → core/types/codegen.mjs} +0 -0
@@ -0,0 +1,294 @@
1
+ import { DefineDirectiveConfig, DefineServerConfig, DirectiveDefinition, Flatten, StandardSchemaV1 } from "./nitro/types.mjs";
2
+ import { NPMConfig, Resolvers, ResolversTypes } from "#graphql/server";
3
+
4
+ //#region src/define.d.ts
5
+
6
+ /**
7
+ * Define schema extensions programmatically for GraphQL types.
8
+ *
9
+ * This function allows you to provide runtime schema definitions that extend
10
+ * your GraphQL types with additional validation or transformation logic using
11
+ * StandardSchemaV1 compliant validators (e.g., Valibot, Zod, ArkType).
12
+ *
13
+ * @template T - A partial record mapping GraphQL type names to their schema definitions
14
+ * @param config - An object mapping GraphQL type names to StandardSchemaV1 schema instances
15
+ * @returns The flattened schema configuration with proper type inference
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import * as v from 'valibot'
20
+ *
21
+ * export const schemas = defineSchema({
22
+ * CreateUserInput: v.object({
23
+ * email: v.pipe(v.string(), v.email()),
24
+ * age: v.pipe(v.number(), v.minValue(18))
25
+ * })
26
+ * })
27
+ * ```
28
+ */
29
+ declare function defineSchema<T extends Partial<Record<keyof ResolversTypes, StandardSchemaV1>>>(config: T): Flatten<T>;
30
+ /**
31
+ * Define a complete GraphQL resolver object with full type safety.
32
+ *
33
+ * Use this function when you need to define multiple resolver types (Query, Mutation,
34
+ * Subscription, and custom types) in a single resolver file. This provides type inference
35
+ * and auto-completion for all resolver fields.
36
+ *
37
+ * @param resolvers - A complete resolver object containing Query, Mutation, Subscription, or custom type resolvers
38
+ * @returns The same resolver object with preserved type information
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * export const userResolvers = defineResolver({
43
+ * Query: {
44
+ * user: async (parent, { id }, context) => {
45
+ * return await context.storage.getItem(`user:${id}`)
46
+ * }
47
+ * },
48
+ * Mutation: {
49
+ * createUser: async (parent, { input }, context) => {
50
+ * const user = { id: generateId(), ...input }
51
+ * await context.storage.setItem(`user:${user.id}`, user)
52
+ * return user
53
+ * }
54
+ * },
55
+ * User: {
56
+ * fullName: (parent, args, context) => `${parent.firstName} ${parent.lastName}`
57
+ * }
58
+ * })
59
+ * ```
60
+ */
61
+ declare function defineResolver(resolvers: Resolvers): Resolvers;
62
+ /**
63
+ * Define GraphQL Query resolvers with full type safety.
64
+ *
65
+ * Use this helper when you only need to define Query resolvers. It automatically
66
+ * wraps your resolvers in the correct structure and provides type inference for
67
+ * all query fields defined in your GraphQL schema.
68
+ *
69
+ * @param resolvers - An object containing Query field resolvers (defaults to empty object)
70
+ * @returns A Resolvers object with the Query field populated
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * export const userQueries = defineQuery({
75
+ * user: async (parent, { id }, context) => {
76
+ * return await fetchUser(id)
77
+ * },
78
+ * users: async (parent, args, context) => {
79
+ * return await fetchAllUsers()
80
+ * }
81
+ * })
82
+ * ```
83
+ *
84
+ * @remarks
85
+ * Named exports are required. Do not use default exports with this function.
86
+ */
87
+ declare function defineQuery(resolvers?: Resolvers['Query']): Resolvers;
88
+ /**
89
+ * Define GraphQL Mutation resolvers with full type safety.
90
+ *
91
+ * Use this helper when you only need to define Mutation resolvers. It automatically
92
+ * wraps your resolvers in the correct structure and provides type inference for
93
+ * all mutation fields defined in your GraphQL schema.
94
+ *
95
+ * @param resolvers - An object containing Mutation field resolvers (defaults to empty object)
96
+ * @returns A Resolvers object with the Mutation field populated
97
+ *
98
+ * @example
99
+ * ```typescript
100
+ * export const userMutations = defineMutation({
101
+ * createUser: async (parent, { input }, context) => {
102
+ * const user = await context.db.users.create(input)
103
+ * return user
104
+ * },
105
+ * updateUser: async (parent, { id, input }, context) => {
106
+ * return await context.db.users.update(id, input)
107
+ * },
108
+ * deleteUser: async (parent, { id }, context) => {
109
+ * return await context.db.users.delete(id)
110
+ * }
111
+ * })
112
+ * ```
113
+ *
114
+ * @remarks
115
+ * Named exports are required. Do not use default exports with this function.
116
+ */
117
+ declare function defineMutation(resolvers?: Resolvers['Mutation']): Resolvers;
118
+ /**
119
+ * Define GraphQL Subscription resolvers with full type safety.
120
+ *
121
+ * Use this helper when you need to define real-time Subscription resolvers. It automatically
122
+ * wraps your resolvers in the correct structure and provides type inference for
123
+ * all subscription fields defined in your GraphQL schema.
124
+ *
125
+ * @param resolvers - An object containing Subscription field resolvers (defaults to empty object)
126
+ * @returns A Resolvers object with the Subscription field populated
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * import { Repeater } from '@repeaterjs/repeater'
131
+ *
132
+ * export const messageSubscriptions = defineSubscription({
133
+ * messageAdded: {
134
+ * subscribe: async function* (parent, { channelId }, context) {
135
+ * const pubsub = context.pubsub
136
+ * yield* pubsub.subscribe(`channel:${channelId}`)
137
+ * }
138
+ * },
139
+ * userStatusChanged: {
140
+ * subscribe: async (parent, args, context) => {
141
+ * return new Repeater(async (push, stop) => {
142
+ * // Real-time subscription logic
143
+ * })
144
+ * }
145
+ * }
146
+ * })
147
+ * ```
148
+ *
149
+ * @remarks
150
+ * Named exports are required. Subscriptions require async iterators or generators.
151
+ */
152
+ declare function defineSubscription(resolvers?: Resolvers['Subscription']): Resolvers;
153
+ /**
154
+ * Define custom GraphQL type resolvers with full type safety.
155
+ *
156
+ * Use this function to define field resolvers for custom GraphQL types (non-scalar types).
157
+ * This is useful for computed fields, field-level transformations, or resolving relationships
158
+ * between types. The function provides type inference for all custom types in your schema.
159
+ *
160
+ * @param resolvers - An object containing custom type field resolvers
161
+ * @returns The same resolver object with preserved type information
162
+ *
163
+ * @example
164
+ * ```typescript
165
+ * // For a User type with computed fields
166
+ * export const userTypeResolvers = defineField({
167
+ * User: {
168
+ * fullName: (parent) => `${parent.firstName} ${parent.lastName}`,
169
+ * age: (parent) => {
170
+ * const today = new Date()
171
+ * return today.getFullYear() - parent.birthYear
172
+ * },
173
+ * posts: async (parent, _, context) => {
174
+ * return await context.db.posts.findByUserId(parent.id)
175
+ * }
176
+ * }
177
+ * })
178
+ * ```
179
+ *
180
+ * @remarks
181
+ * This is functionally equivalent to defineResolver but semantically indicates
182
+ * you're defining type-specific field resolvers rather than root-level operations.
183
+ */
184
+ declare function defineField(resolvers: Resolvers): Resolvers;
185
+ /**
186
+ * Define GraphQL server configuration with full type safety.
187
+ *
188
+ * Use this function to configure your GraphQL server settings including schema,
189
+ * context, plugins, and framework-specific options. Supports both GraphQL Yoga
190
+ * and Apollo Server configurations with proper type inference.
191
+ *
192
+ * @template T - The NPMConfig type (GraphQL Yoga or Apollo Server config)
193
+ * @param config - Partial server configuration object
194
+ * @returns The same configuration object with preserved type information
195
+ *
196
+ * @example
197
+ * ```typescript
198
+ * import { createDefaultMaskError } from 'nitro-graphql/core'
199
+ *
200
+ * // GraphQL Yoga configuration
201
+ * export default defineGraphQLConfig({
202
+ * schema: {
203
+ * // Schema directives, custom scalars, etc.
204
+ * },
205
+ * context: async (event) => {
206
+ * return {
207
+ * user: await getUserFromEvent(event),
208
+ * db: getDatabase()
209
+ * }
210
+ * },
211
+ * maskedErrors: {
212
+ * maskError: createDefaultMaskError()
213
+ * },
214
+ * graphiql: true
215
+ * })
216
+ * ```
217
+ *
218
+ * @example
219
+ * ```typescript
220
+ * // Apollo Server configuration
221
+ * export default defineGraphQLConfig({
222
+ * apollo: {
223
+ * introspection: true,
224
+ * csrfPrevention: true,
225
+ * plugins: [ApolloServerPluginLandingPageGraphQLPlayground()]
226
+ * }
227
+ * })
228
+ * ```
229
+ */
230
+ declare function defineGraphQLConfig<T extends NPMConfig = NPMConfig>(config: Partial<DefineServerConfig<T>>): Partial<DefineServerConfig<T>>;
231
+ /**
232
+ * Define a custom GraphQL directive with full type safety.
233
+ *
234
+ * This function creates a GraphQL directive definition that can be used to add
235
+ * custom behavior to your GraphQL schema. It automatically generates the directive's
236
+ * schema definition string and provides runtime transformation capabilities.
237
+ *
238
+ * @param config - The directive configuration object
239
+ * @param config.name - The name of the directive (without the @ symbol)
240
+ * @param config.locations - Array of GraphQL directive locations where this directive can be applied
241
+ * @param config.args - Optional arguments the directive accepts with their types and default values
242
+ * @param config.transformer - Optional function to transform the schema when this directive is applied
243
+ * @returns A DirectiveDefinition object with the schema definition and runtime behavior
244
+ *
245
+ * @example
246
+ * ```typescript
247
+ * import { mapSchema, getDirective, MapperKind } from '@graphql-tools/utils'
248
+ *
249
+ * export const upperDirective = defineDirective({
250
+ * name: 'upper',
251
+ * locations: ['FIELD_DEFINITION'],
252
+ * transformer: (schema) => {
253
+ * return mapSchema(schema, {
254
+ * [MapperKind.OBJECT_FIELD]: (fieldConfig) => {
255
+ * const directive = getDirective(schema, fieldConfig, 'upper')?.[0]
256
+ * if (directive) {
257
+ * const { resolve = defaultFieldResolver } = fieldConfig
258
+ * fieldConfig.resolve = async (source, args, context, info) => {
259
+ * const result = await resolve(source, args, context, info)
260
+ * return typeof result === 'string' ? result.toUpperCase() : result
261
+ * }
262
+ * }
263
+ * return fieldConfig
264
+ * }
265
+ * })
266
+ * }
267
+ * })
268
+ * ```
269
+ *
270
+ * @example
271
+ * ```typescript
272
+ * // Directive with arguments
273
+ * export const authDirective = defineDirective({
274
+ * name: 'auth',
275
+ * locations: ['FIELD_DEFINITION', 'OBJECT'],
276
+ * args: {
277
+ * requires: {
278
+ * type: 'Role!',
279
+ * defaultValue: 'USER'
280
+ * }
281
+ * },
282
+ * transformer: (schema) => {
283
+ * // Implementation for auth checking
284
+ * }
285
+ * })
286
+ * ```
287
+ *
288
+ * @remarks
289
+ * The generated directive schema definition is stored as a non-enumerable `__schema`
290
+ * property on the returned object and is automatically included in your GraphQL schema.
291
+ */
292
+ declare function defineDirective(config: DefineDirectiveConfig): DirectiveDefinition;
293
+ //#endregion
294
+ export { defineDirective, defineField, defineGraphQLConfig, defineMutation, defineQuery, defineResolver, defineSchema, defineSubscription };
@@ -0,0 +1,323 @@
1
+ //#region src/define.ts
2
+ /**
3
+ * Define schema extensions programmatically for GraphQL types.
4
+ *
5
+ * This function allows you to provide runtime schema definitions that extend
6
+ * your GraphQL types with additional validation or transformation logic using
7
+ * StandardSchemaV1 compliant validators (e.g., Valibot, Zod, ArkType).
8
+ *
9
+ * @template T - A partial record mapping GraphQL type names to their schema definitions
10
+ * @param config - An object mapping GraphQL type names to StandardSchemaV1 schema instances
11
+ * @returns The flattened schema configuration with proper type inference
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import * as v from 'valibot'
16
+ *
17
+ * export const schemas = defineSchema({
18
+ * CreateUserInput: v.object({
19
+ * email: v.pipe(v.string(), v.email()),
20
+ * age: v.pipe(v.number(), v.minValue(18))
21
+ * })
22
+ * })
23
+ * ```
24
+ */
25
+ function defineSchema(config) {
26
+ return config;
27
+ }
28
+ /**
29
+ * Define a complete GraphQL resolver object with full type safety.
30
+ *
31
+ * Use this function when you need to define multiple resolver types (Query, Mutation,
32
+ * Subscription, and custom types) in a single resolver file. This provides type inference
33
+ * and auto-completion for all resolver fields.
34
+ *
35
+ * @param resolvers - A complete resolver object containing Query, Mutation, Subscription, or custom type resolvers
36
+ * @returns The same resolver object with preserved type information
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * export const userResolvers = defineResolver({
41
+ * Query: {
42
+ * user: async (parent, { id }, context) => {
43
+ * return await context.storage.getItem(`user:${id}`)
44
+ * }
45
+ * },
46
+ * Mutation: {
47
+ * createUser: async (parent, { input }, context) => {
48
+ * const user = { id: generateId(), ...input }
49
+ * await context.storage.setItem(`user:${user.id}`, user)
50
+ * return user
51
+ * }
52
+ * },
53
+ * User: {
54
+ * fullName: (parent, args, context) => `${parent.firstName} ${parent.lastName}`
55
+ * }
56
+ * })
57
+ * ```
58
+ */
59
+ function defineResolver(resolvers) {
60
+ return resolvers;
61
+ }
62
+ /**
63
+ * Define GraphQL Query resolvers with full type safety.
64
+ *
65
+ * Use this helper when you only need to define Query resolvers. It automatically
66
+ * wraps your resolvers in the correct structure and provides type inference for
67
+ * all query fields defined in your GraphQL schema.
68
+ *
69
+ * @param resolvers - An object containing Query field resolvers (defaults to empty object)
70
+ * @returns A Resolvers object with the Query field populated
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * export const userQueries = defineQuery({
75
+ * user: async (parent, { id }, context) => {
76
+ * return await fetchUser(id)
77
+ * },
78
+ * users: async (parent, args, context) => {
79
+ * return await fetchAllUsers()
80
+ * }
81
+ * })
82
+ * ```
83
+ *
84
+ * @remarks
85
+ * Named exports are required. Do not use default exports with this function.
86
+ */
87
+ function defineQuery(resolvers = {}) {
88
+ return { Query: { ...resolvers } };
89
+ }
90
+ /**
91
+ * Define GraphQL Mutation resolvers with full type safety.
92
+ *
93
+ * Use this helper when you only need to define Mutation resolvers. It automatically
94
+ * wraps your resolvers in the correct structure and provides type inference for
95
+ * all mutation fields defined in your GraphQL schema.
96
+ *
97
+ * @param resolvers - An object containing Mutation field resolvers (defaults to empty object)
98
+ * @returns A Resolvers object with the Mutation field populated
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * export const userMutations = defineMutation({
103
+ * createUser: async (parent, { input }, context) => {
104
+ * const user = await context.db.users.create(input)
105
+ * return user
106
+ * },
107
+ * updateUser: async (parent, { id, input }, context) => {
108
+ * return await context.db.users.update(id, input)
109
+ * },
110
+ * deleteUser: async (parent, { id }, context) => {
111
+ * return await context.db.users.delete(id)
112
+ * }
113
+ * })
114
+ * ```
115
+ *
116
+ * @remarks
117
+ * Named exports are required. Do not use default exports with this function.
118
+ */
119
+ function defineMutation(resolvers = {}) {
120
+ return { Mutation: { ...resolvers } };
121
+ }
122
+ /**
123
+ * Define GraphQL Subscription resolvers with full type safety.
124
+ *
125
+ * Use this helper when you need to define real-time Subscription resolvers. It automatically
126
+ * wraps your resolvers in the correct structure and provides type inference for
127
+ * all subscription fields defined in your GraphQL schema.
128
+ *
129
+ * @param resolvers - An object containing Subscription field resolvers (defaults to empty object)
130
+ * @returns A Resolvers object with the Subscription field populated
131
+ *
132
+ * @example
133
+ * ```typescript
134
+ * import { Repeater } from '@repeaterjs/repeater'
135
+ *
136
+ * export const messageSubscriptions = defineSubscription({
137
+ * messageAdded: {
138
+ * subscribe: async function* (parent, { channelId }, context) {
139
+ * const pubsub = context.pubsub
140
+ * yield* pubsub.subscribe(`channel:${channelId}`)
141
+ * }
142
+ * },
143
+ * userStatusChanged: {
144
+ * subscribe: async (parent, args, context) => {
145
+ * return new Repeater(async (push, stop) => {
146
+ * // Real-time subscription logic
147
+ * })
148
+ * }
149
+ * }
150
+ * })
151
+ * ```
152
+ *
153
+ * @remarks
154
+ * Named exports are required. Subscriptions require async iterators or generators.
155
+ */
156
+ function defineSubscription(resolvers = {}) {
157
+ return { Subscription: { ...resolvers } };
158
+ }
159
+ /**
160
+ * Define custom GraphQL type resolvers with full type safety.
161
+ *
162
+ * Use this function to define field resolvers for custom GraphQL types (non-scalar types).
163
+ * This is useful for computed fields, field-level transformations, or resolving relationships
164
+ * between types. The function provides type inference for all custom types in your schema.
165
+ *
166
+ * @param resolvers - An object containing custom type field resolvers
167
+ * @returns The same resolver object with preserved type information
168
+ *
169
+ * @example
170
+ * ```typescript
171
+ * // For a User type with computed fields
172
+ * export const userTypeResolvers = defineField({
173
+ * User: {
174
+ * fullName: (parent) => `${parent.firstName} ${parent.lastName}`,
175
+ * age: (parent) => {
176
+ * const today = new Date()
177
+ * return today.getFullYear() - parent.birthYear
178
+ * },
179
+ * posts: async (parent, _, context) => {
180
+ * return await context.db.posts.findByUserId(parent.id)
181
+ * }
182
+ * }
183
+ * })
184
+ * ```
185
+ *
186
+ * @remarks
187
+ * This is functionally equivalent to defineResolver but semantically indicates
188
+ * you're defining type-specific field resolvers rather than root-level operations.
189
+ */
190
+ function defineField(resolvers) {
191
+ return resolvers;
192
+ }
193
+ /**
194
+ * Define GraphQL server configuration with full type safety.
195
+ *
196
+ * Use this function to configure your GraphQL server settings including schema,
197
+ * context, plugins, and framework-specific options. Supports both GraphQL Yoga
198
+ * and Apollo Server configurations with proper type inference.
199
+ *
200
+ * @template T - The NPMConfig type (GraphQL Yoga or Apollo Server config)
201
+ * @param config - Partial server configuration object
202
+ * @returns The same configuration object with preserved type information
203
+ *
204
+ * @example
205
+ * ```typescript
206
+ * import { createDefaultMaskError } from 'nitro-graphql/core'
207
+ *
208
+ * // GraphQL Yoga configuration
209
+ * export default defineGraphQLConfig({
210
+ * schema: {
211
+ * // Schema directives, custom scalars, etc.
212
+ * },
213
+ * context: async (event) => {
214
+ * return {
215
+ * user: await getUserFromEvent(event),
216
+ * db: getDatabase()
217
+ * }
218
+ * },
219
+ * maskedErrors: {
220
+ * maskError: createDefaultMaskError()
221
+ * },
222
+ * graphiql: true
223
+ * })
224
+ * ```
225
+ *
226
+ * @example
227
+ * ```typescript
228
+ * // Apollo Server configuration
229
+ * export default defineGraphQLConfig({
230
+ * apollo: {
231
+ * introspection: true,
232
+ * csrfPrevention: true,
233
+ * plugins: [ApolloServerPluginLandingPageGraphQLPlayground()]
234
+ * }
235
+ * })
236
+ * ```
237
+ */
238
+ function defineGraphQLConfig(config) {
239
+ return config;
240
+ }
241
+ /**
242
+ * Define a custom GraphQL directive with full type safety.
243
+ *
244
+ * This function creates a GraphQL directive definition that can be used to add
245
+ * custom behavior to your GraphQL schema. It automatically generates the directive's
246
+ * schema definition string and provides runtime transformation capabilities.
247
+ *
248
+ * @param config - The directive configuration object
249
+ * @param config.name - The name of the directive (without the @ symbol)
250
+ * @param config.locations - Array of GraphQL directive locations where this directive can be applied
251
+ * @param config.args - Optional arguments the directive accepts with their types and default values
252
+ * @param config.transformer - Optional function to transform the schema when this directive is applied
253
+ * @returns A DirectiveDefinition object with the schema definition and runtime behavior
254
+ *
255
+ * @example
256
+ * ```typescript
257
+ * import { mapSchema, getDirective, MapperKind } from '@graphql-tools/utils'
258
+ *
259
+ * export const upperDirective = defineDirective({
260
+ * name: 'upper',
261
+ * locations: ['FIELD_DEFINITION'],
262
+ * transformer: (schema) => {
263
+ * return mapSchema(schema, {
264
+ * [MapperKind.OBJECT_FIELD]: (fieldConfig) => {
265
+ * const directive = getDirective(schema, fieldConfig, 'upper')?.[0]
266
+ * if (directive) {
267
+ * const { resolve = defaultFieldResolver } = fieldConfig
268
+ * fieldConfig.resolve = async (source, args, context, info) => {
269
+ * const result = await resolve(source, args, context, info)
270
+ * return typeof result === 'string' ? result.toUpperCase() : result
271
+ * }
272
+ * }
273
+ * return fieldConfig
274
+ * }
275
+ * })
276
+ * }
277
+ * })
278
+ * ```
279
+ *
280
+ * @example
281
+ * ```typescript
282
+ * // Directive with arguments
283
+ * export const authDirective = defineDirective({
284
+ * name: 'auth',
285
+ * locations: ['FIELD_DEFINITION', 'OBJECT'],
286
+ * args: {
287
+ * requires: {
288
+ * type: 'Role!',
289
+ * defaultValue: 'USER'
290
+ * }
291
+ * },
292
+ * transformer: (schema) => {
293
+ * // Implementation for auth checking
294
+ * }
295
+ * })
296
+ * ```
297
+ *
298
+ * @remarks
299
+ * The generated directive schema definition is stored as a non-enumerable `__schema`
300
+ * property on the returned object and is automatically included in your GraphQL schema.
301
+ */
302
+ function defineDirective(config) {
303
+ const args = config.args ? Object.entries(config.args).map(([name, arg]) => {
304
+ const defaultValue = arg.defaultValue !== void 0 ? ` = ${JSON.stringify(arg.defaultValue)}` : "";
305
+ return `${name}: ${arg.type}${defaultValue}`;
306
+ }).join(", ") : "";
307
+ const argsString = args ? `(${args})` : "";
308
+ const locations = config.locations.join(" | ");
309
+ const schemaDefinition = `directive @${config.name}${argsString} on ${locations}`;
310
+ Object.defineProperty(config, "__schema", {
311
+ value: schemaDefinition,
312
+ enumerable: false,
313
+ configurable: false,
314
+ writable: false
315
+ });
316
+ return {
317
+ ...config,
318
+ locations: [...config.locations]
319
+ };
320
+ }
321
+
322
+ //#endregion
323
+ export { defineDirective, defineField, defineGraphQLConfig, defineMutation, defineQuery, defineResolver, defineSchema, defineSubscription };
@@ -0,0 +1,6 @@
1
+ import { ExternalGraphQLService, NitroGraphQLOptions, SecurityConfig } from "./nitro/types.mjs";
2
+ import { NitroAdapter } from "./nitro/adapter.mjs";
3
+ import { resolveSecurityConfig } from "./nitro/setup/logging.mjs";
4
+ import { setupNitroGraphQL } from "./nitro/setup.mjs";
5
+ import graphqlModule from "./nitro/index.mjs";
6
+ export { type ExternalGraphQLService, NitroAdapter, type NitroGraphQLOptions, type SecurityConfig, graphqlModule as default, resolveSecurityConfig, setupNitroGraphQL };
package/dist/index.mjs ADDED
@@ -0,0 +1,6 @@
1
+ import { NitroAdapter } from "./nitro/adapter.mjs";
2
+ import { resolveSecurityConfig } from "./nitro/setup/logging.mjs";
3
+ import { setupNitroGraphQL } from "./nitro/setup.mjs";
4
+ import nitro_default from "./nitro/index.mjs";
5
+
6
+ export { NitroAdapter, nitro_default as default, resolveSecurityConfig, setupNitroGraphQL };
@@ -0,0 +1,30 @@
1
+ import { CoreConfig, CoreContext, CoreLogger } from "../core/types/config.mjs";
2
+ import { ScanContext } from "../core/types/scanning.mjs";
3
+ import "../core/types/index.mjs";
4
+ import { FrameworkAdapter, ScanAdapter } from "../core/types/adapter.mjs";
5
+ import { Nitro } from "nitro/types";
6
+
7
+ //#region src/nitro/adapter.d.ts
8
+
9
+ /**
10
+ * Create a CoreLogger from Nitro's logger
11
+ */
12
+ declare function createLoggerFromNitro(nitro: Nitro): CoreLogger;
13
+ /**
14
+ * Create a ScanContext from Nitro instance
15
+ */
16
+ declare function createScanContextFromNitro(nitro: Nitro): ScanContext;
17
+ /**
18
+ * Create a CoreConfig from Nitro instance
19
+ */
20
+ declare function createCoreConfigFromNitro(nitro: Nitro): CoreConfig;
21
+ /**
22
+ * Create a CoreContext from Nitro instance
23
+ */
24
+ declare function createCoreContextFromNitro(nitro: Nitro): CoreContext;
25
+ /**
26
+ * Nitro framework adapter implementation
27
+ */
28
+ declare const NitroAdapter: FrameworkAdapter<Nitro> & ScanAdapter<Nitro>;
29
+ //#endregion
30
+ export { NitroAdapter, NitroAdapter as default, createCoreConfigFromNitro, createCoreContextFromNitro, createLoggerFromNitro, createScanContextFromNitro };