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

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