nitro-graphql 2.0.0-beta.7 → 2.0.0-beta.72

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