effect 4.0.3 → 4.0.4

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 (207) hide show
  1. package/AGENTS.md +24 -0
  2. package/CLAUDE.md +24 -0
  3. package/ai-docs/package.json +2 -2
  4. package/ai-docs/src/52_graphql/10_basics.ts +111 -0
  5. package/ai-docs/src/52_graphql/20_testing.ts +45 -0
  6. package/ai-docs/src/52_graphql/30_batching.ts +116 -0
  7. package/ai-docs/src/52_graphql/40_aliased-batching.ts +122 -0
  8. package/ai-docs/src/52_graphql/50_errors-and-retries.ts +74 -0
  9. package/ai-docs/src/52_graphql/index.md +6 -0
  10. package/dist/Context.d.ts.map +1 -1
  11. package/dist/Context.js +9 -0
  12. package/dist/Context.js.map +1 -1
  13. package/dist/RequestResolver.d.ts.map +1 -1
  14. package/dist/RequestResolver.js +4 -10
  15. package/dist/RequestResolver.js.map +1 -1
  16. package/dist/Scheduler.d.ts +9 -0
  17. package/dist/Scheduler.d.ts.map +1 -1
  18. package/dist/Scheduler.js +9 -0
  19. package/dist/Scheduler.js.map +1 -1
  20. package/dist/Schema.d.ts +8 -0
  21. package/dist/Schema.d.ts.map +1 -1
  22. package/dist/Schema.js +7 -0
  23. package/dist/Schema.js.map +1 -1
  24. package/dist/SchemaGetter.d.ts +4 -0
  25. package/dist/SchemaGetter.d.ts.map +1 -1
  26. package/dist/SchemaGetter.js +52 -33
  27. package/dist/SchemaGetter.js.map +1 -1
  28. package/dist/Sink.d.ts.map +1 -1
  29. package/dist/Sink.js +38 -17
  30. package/dist/Sink.js.map +1 -1
  31. package/dist/Stream.d.ts +11 -0
  32. package/dist/Stream.d.ts.map +1 -1
  33. package/dist/Stream.js +16 -1
  34. package/dist/Stream.js.map +1 -1
  35. package/dist/Utils.js +8 -3
  36. package/dist/Utils.js.map +1 -1
  37. package/dist/ai/AnthropicStructuredOutput.js +0 -2
  38. package/dist/ai/AnthropicStructuredOutput.js.map +1 -1
  39. package/dist/ai/Chat.d.ts +2 -2
  40. package/dist/ai/Chat.d.ts.map +1 -1
  41. package/dist/ai/LanguageModel.d.ts +38 -7
  42. package/dist/ai/LanguageModel.d.ts.map +1 -1
  43. package/dist/ai/LanguageModel.js +25 -7
  44. package/dist/ai/LanguageModel.js.map +1 -1
  45. package/dist/ai/McpServer.d.ts +55 -0
  46. package/dist/ai/McpServer.d.ts.map +1 -1
  47. package/dist/ai/McpServer.js +132 -22
  48. package/dist/ai/McpServer.js.map +1 -1
  49. package/dist/ai/Prompt.d.ts.map +1 -1
  50. package/dist/ai/Prompt.js +28 -5
  51. package/dist/ai/Prompt.js.map +1 -1
  52. package/dist/ai/Response.d.ts +4 -3
  53. package/dist/ai/Response.d.ts.map +1 -1
  54. package/dist/ai/Response.js.map +1 -1
  55. package/dist/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
  56. package/dist/cluster/ClusterWorkflowEngine.js +46 -8
  57. package/dist/cluster/ClusterWorkflowEngine.js.map +1 -1
  58. package/dist/cluster/Sharding.d.ts.map +1 -1
  59. package/dist/cluster/Sharding.js +6 -4
  60. package/dist/cluster/Sharding.js.map +1 -1
  61. package/dist/encoding/Sse.d.ts +6 -0
  62. package/dist/encoding/Sse.d.ts.map +1 -1
  63. package/dist/encoding/Sse.js +62 -70
  64. package/dist/encoding/Sse.js.map +1 -1
  65. package/dist/graphql/GraphQL.d.ts +349 -0
  66. package/dist/graphql/GraphQL.d.ts.map +1 -0
  67. package/dist/graphql/GraphQL.js +207 -0
  68. package/dist/graphql/GraphQL.js.map +1 -0
  69. package/dist/graphql/GraphQLClient.d.ts +562 -0
  70. package/dist/graphql/GraphQLClient.d.ts.map +1 -0
  71. package/dist/graphql/GraphQLClient.js +498 -0
  72. package/dist/graphql/GraphQLClient.js.map +1 -0
  73. package/dist/graphql/GraphQLClientError.d.ts +445 -0
  74. package/dist/graphql/GraphQLClientError.d.ts.map +1 -0
  75. package/dist/graphql/GraphQLClientError.js +479 -0
  76. package/dist/graphql/GraphQLClientError.js.map +1 -0
  77. package/dist/graphql/GraphQLGroup.d.ts +118 -0
  78. package/dist/graphql/GraphQLGroup.d.ts.map +1 -0
  79. package/dist/graphql/GraphQLGroup.js +109 -0
  80. package/dist/graphql/GraphQLGroup.js.map +1 -0
  81. package/dist/graphql/GraphQLMiddleware.d.ts +249 -0
  82. package/dist/graphql/GraphQLMiddleware.d.ts.map +1 -0
  83. package/dist/graphql/GraphQLMiddleware.js +130 -0
  84. package/dist/graphql/GraphQLMiddleware.js.map +1 -0
  85. package/dist/graphql/GraphQLProtocol.d.ts +731 -0
  86. package/dist/graphql/GraphQLProtocol.d.ts.map +1 -0
  87. package/dist/graphql/GraphQLProtocol.js +719 -0
  88. package/dist/graphql/GraphQLProtocol.js.map +1 -0
  89. package/dist/graphql/GraphQLResolver.d.ts +453 -0
  90. package/dist/graphql/GraphQLResolver.d.ts.map +1 -0
  91. package/dist/graphql/GraphQLResolver.js +552 -0
  92. package/dist/graphql/GraphQLResolver.js.map +1 -0
  93. package/dist/graphql/index.d.ts +40 -0
  94. package/dist/graphql/index.d.ts.map +1 -0
  95. package/dist/graphql/index.js +41 -0
  96. package/dist/graphql/index.js.map +1 -0
  97. package/dist/http/HttpClient.d.ts +15 -0
  98. package/dist/http/HttpClient.d.ts.map +1 -1
  99. package/dist/http/HttpClient.js +24 -10
  100. package/dist/http/HttpClient.js.map +1 -1
  101. package/dist/http/HttpEffect.d.ts.map +1 -1
  102. package/dist/http/HttpEffect.js +14 -7
  103. package/dist/http/HttpEffect.js.map +1 -1
  104. package/dist/http/HttpMiddleware.d.ts.map +1 -1
  105. package/dist/http/HttpMiddleware.js +31 -32
  106. package/dist/http/HttpMiddleware.js.map +1 -1
  107. package/dist/http/HttpRouter.d.ts +35 -0
  108. package/dist/http/HttpRouter.d.ts.map +1 -1
  109. package/dist/http/HttpRouter.js +35 -0
  110. package/dist/http/HttpRouter.js.map +1 -1
  111. package/dist/http/HttpServerResponse.d.ts +8 -6
  112. package/dist/http/HttpServerResponse.d.ts.map +1 -1
  113. package/dist/http/HttpServerResponse.js +27 -16
  114. package/dist/http/HttpServerResponse.js.map +1 -1
  115. package/dist/http/Multipart.d.ts.map +1 -1
  116. package/dist/http/Multipart.js +15 -1
  117. package/dist/http/Multipart.js.map +1 -1
  118. package/dist/http-api/HttpApiScalar.d.ts +5 -0
  119. package/dist/http-api/HttpApiScalar.d.ts.map +1 -1
  120. package/dist/http-api/HttpApiScalar.js.map +1 -1
  121. package/dist/internal/dateTime.js +40 -35
  122. package/dist/internal/dateTime.js.map +1 -1
  123. package/dist/internal/effect.js +8 -3
  124. package/dist/internal/effect.js.map +1 -1
  125. package/dist/internal/graphql.d.ts +2 -0
  126. package/dist/internal/graphql.d.ts.map +1 -0
  127. package/dist/internal/graphql.js +195 -0
  128. package/dist/internal/graphql.js.map +1 -0
  129. package/dist/internal/graphqlHeaders.d.ts +4 -0
  130. package/dist/internal/graphqlHeaders.d.ts.map +1 -0
  131. package/dist/internal/graphqlHeaders.js +11 -0
  132. package/dist/internal/graphqlHeaders.js.map +1 -0
  133. package/dist/internal/request.js +20 -1
  134. package/dist/internal/request.js.map +1 -1
  135. package/dist/internal/schema/toCodeDocument.js +4 -1
  136. package/dist/internal/schema/toCodeDocument.js.map +1 -1
  137. package/dist/internal/schema/toJsonSchemaDocument.js +29 -5
  138. package/dist/internal/schema/toJsonSchemaDocument.js.map +1 -1
  139. package/dist/internal/version.js +1 -1
  140. package/dist/net/Host.d.ts +49 -0
  141. package/dist/net/Host.d.ts.map +1 -1
  142. package/dist/net/Host.js +55 -0
  143. package/dist/net/Host.js.map +1 -1
  144. package/dist/net/NetAddress.d.ts +8 -0
  145. package/dist/net/NetAddress.d.ts.map +1 -1
  146. package/dist/net/NetAddress.js +8 -0
  147. package/dist/net/NetAddress.js.map +1 -1
  148. package/dist/rpc/RpcServer.d.ts.map +1 -1
  149. package/dist/rpc/RpcServer.js +36 -9
  150. package/dist/rpc/RpcServer.js.map +1 -1
  151. package/dist/socket/Socket.d.ts +6 -0
  152. package/dist/socket/Socket.d.ts.map +1 -1
  153. package/dist/socket/Socket.js.map +1 -1
  154. package/dist/workflow/DurableDeferred.d.ts.map +1 -1
  155. package/dist/workflow/DurableDeferred.js +32 -3
  156. package/dist/workflow/DurableDeferred.js.map +1 -1
  157. package/dist/workflow/WorkflowEngine.d.ts +24 -2
  158. package/dist/workflow/WorkflowEngine.d.ts.map +1 -1
  159. package/dist/workflow/WorkflowEngine.js +11 -2
  160. package/dist/workflow/WorkflowEngine.js.map +1 -1
  161. package/package.json +6 -3
  162. package/src/Context.ts +9 -0
  163. package/src/RequestResolver.ts +4 -10
  164. package/src/Scheduler.ts +9 -0
  165. package/src/Schema.ts +8 -0
  166. package/src/SchemaGetter.ts +47 -35
  167. package/src/Sink.ts +45 -18
  168. package/src/Stream.ts +33 -4
  169. package/src/Utils.ts +8 -5
  170. package/src/ai/AnthropicStructuredOutput.ts +2 -2
  171. package/src/ai/Chat.ts +2 -2
  172. package/src/ai/LanguageModel.ts +96 -24
  173. package/src/ai/McpServer.ts +244 -90
  174. package/src/ai/Prompt.ts +24 -10
  175. package/src/ai/Response.ts +6 -3
  176. package/src/cluster/ClusterWorkflowEngine.ts +51 -12
  177. package/src/cluster/Sharding.ts +12 -9
  178. package/src/encoding/Sse.ts +69 -79
  179. package/src/graphql/GraphQL.ts +494 -0
  180. package/src/graphql/GraphQLClient.ts +912 -0
  181. package/src/graphql/GraphQLClientError.ts +542 -0
  182. package/src/graphql/GraphQLGroup.ts +167 -0
  183. package/src/graphql/GraphQLMiddleware.ts +253 -0
  184. package/src/graphql/GraphQLProtocol.ts +1286 -0
  185. package/src/graphql/GraphQLResolver.ts +1010 -0
  186. package/src/graphql/index.ts +48 -0
  187. package/src/http/HttpClient.ts +54 -10
  188. package/src/http/HttpEffect.ts +11 -5
  189. package/src/http/HttpMiddleware.ts +33 -34
  190. package/src/http/HttpRouter.ts +35 -0
  191. package/src/http/HttpServerResponse.ts +28 -16
  192. package/src/http/Multipart.ts +17 -1
  193. package/src/http-api/HttpApiScalar.ts +5 -0
  194. package/src/internal/dateTime.ts +13 -10
  195. package/src/internal/effect.ts +8 -3
  196. package/src/internal/graphql.ts +263 -0
  197. package/src/internal/graphqlHeaders.ts +11 -0
  198. package/src/internal/request.ts +31 -3
  199. package/src/internal/schema/toCodeDocument.ts +7 -1
  200. package/src/internal/schema/toJsonSchemaDocument.ts +34 -2
  201. package/src/internal/version.ts +1 -1
  202. package/src/net/Host.ts +72 -0
  203. package/src/net/NetAddress.ts +9 -0
  204. package/src/rpc/RpcServer.ts +55 -15
  205. package/src/socket/Socket.ts +6 -0
  206. package/src/workflow/DurableDeferred.ts +43 -5
  207. package/src/workflow/WorkflowEngine.ts +48 -4
@@ -0,0 +1,494 @@
1
+ /**
2
+ * Typed GraphQL operations for `GraphQLGroup` and `GraphQLClient.make`,
3
+ * written by hand or generated by `@effect/graphql-generator`.
4
+ *
5
+ * Includes the generator's lenient decoders, {@link otherTypename} and
6
+ * {@link enumLiterals}.
7
+ *
8
+ * @stability experimental
9
+ * @since 4.0.0
10
+ */
11
+ import * as internal from "../internal/graphql.ts"
12
+ import { type Pipeable, pipeArguments } from "../Pipeable.ts"
13
+ import { hasProperty } from "../Predicate.ts"
14
+ import * as Schema from "../Schema.ts"
15
+ import type { GraphQLClientError } from "./GraphQLClientError.ts"
16
+ import type * as GraphQLMiddleware from "./GraphQLMiddleware.ts"
17
+
18
+ const TypeId = "~effect/graphql/GraphQL"
19
+
20
+ /**
21
+ * The three kinds of GraphQL operation.
22
+ *
23
+ * @stability experimental
24
+ * @category models
25
+ * @since 4.0.0
26
+ */
27
+ export type Kind = "query" | "mutation" | "subscription"
28
+
29
+ /**
30
+ * An operation document split into the pieces needed to rename and alias it
31
+ * without a GraphQL parser. The generator emits one for every query and
32
+ * mutation.
33
+ *
34
+ * **Details**
35
+ *
36
+ * A `body` is a {@link DocumentTemplate.Parts} array: literal text at even
37
+ * indices and, at odd indices, the variable names and fragment names that
38
+ * would be renamed if the operation were repeated under a prefix. Joining the
39
+ * pieces gives the printed document, which is what the operation sends.
40
+ *
41
+ * A fragment whose `body` has a name in it is per-slice: it references a
42
+ * variable, directly or through a fragment it spreads. Every other fragment is
43
+ * shared.
44
+ *
45
+ * @stability experimental
46
+ * @category models
47
+ * @since 4.0.0
48
+ */
49
+ export interface DocumentTemplate {
50
+ /** The variable definitions, in document order. */
51
+ readonly variables: ReadonlyArray<DocumentTemplate.Variable>
52
+ /** The operation's directives, if it has any. */
53
+ readonly directives?: DocumentTemplate.Parts | undefined
54
+ /** The root selections, in document order. */
55
+ readonly selections: ReadonlyArray<DocumentTemplate.Selection>
56
+ /** The fragments the operation uses, in the order they follow it. */
57
+ readonly fragments: ReadonlyArray<DocumentTemplate.Fragment>
58
+ }
59
+
60
+ /**
61
+ * The pieces of a {@link DocumentTemplate}.
62
+ *
63
+ * @stability experimental
64
+ * @since 4.0.0
65
+ */
66
+ export declare namespace DocumentTemplate {
67
+ /**
68
+ * Literal text at even indices and names to rename at odd indices.
69
+ *
70
+ * @stability experimental
71
+ * @category models
72
+ * @since 4.0.0
73
+ */
74
+ export type Parts = ReadonlyArray<string>
75
+
76
+ /**
77
+ * A variable definition: `$name:` followed by `body`, the type, default
78
+ * value and directives as printed.
79
+ *
80
+ * @stability experimental
81
+ * @category models
82
+ * @since 4.0.0
83
+ */
84
+ export interface Variable {
85
+ readonly name: string
86
+ readonly body: string
87
+ }
88
+
89
+ /**
90
+ * A root selection. For a field, `body` is everything after its name and
91
+ * the response key is `alias ?? name`. A fragment spread or inline fragment
92
+ * has no `name`, and `body` is the whole selection.
93
+ *
94
+ * @stability experimental
95
+ * @category models
96
+ * @since 4.0.0
97
+ */
98
+ export interface Selection {
99
+ readonly alias?: string | undefined
100
+ readonly name?: string | undefined
101
+ readonly body: Parts
102
+ }
103
+
104
+ /**
105
+ * A fragment definition: `fragment` and `name`, followed by `body`, which
106
+ * starts at its type condition.
107
+ *
108
+ * @stability experimental
109
+ * @category models
110
+ * @since 4.0.0
111
+ */
112
+ export interface Fragment {
113
+ readonly name: string
114
+ readonly body: Parts
115
+ }
116
+ }
117
+
118
+ /**
119
+ * A named GraphQL document with variable and result schemas and middleware.
120
+ * Variables are encoded before sending; results are decoded from `data`.
121
+ *
122
+ * @stability experimental
123
+ * @category models
124
+ * @since 4.0.0
125
+ */
126
+ export interface Operation<
127
+ out K extends Kind,
128
+ out Name extends string,
129
+ out Variables extends Schema.Top,
130
+ out Result extends Schema.Top,
131
+ out Middleware = never
132
+ > extends Pipeable {
133
+ readonly [TypeId]: typeof TypeId
134
+ readonly kind: K
135
+ readonly name: Name
136
+ /** The printed document, sent as-is. It is never parsed at runtime. */
137
+ readonly document: string
138
+ /** The template the document was joined from, if it was given as one. */
139
+ readonly template: DocumentTemplate | undefined
140
+ readonly variables: Variables
141
+ readonly result: Result
142
+ /** Middleware attached to this operation, outermost first. */
143
+ readonly middlewares: ReadonlyArray<GraphQLMiddleware.AnyService>
144
+ readonly "~middleware"?: Middleware
145
+ /**
146
+ * Returns a copy of this operation with `middleware` attached. Operation
147
+ * middleware runs inside any group middleware; within the operation,
148
+ * middleware run in the order they were attached.
149
+ */
150
+ middleware<M extends GraphQLMiddleware.AnyService>(
151
+ middleware: M
152
+ ): Operation<K, Name, Variables, Result, Middleware | M>
153
+ }
154
+
155
+ /**
156
+ * Any operation, with its type parameters erased.
157
+ *
158
+ * @stability experimental
159
+ * @category utility types
160
+ * @since 4.0.0
161
+ */
162
+ export type Any = Operation<Kind, string, Schema.Top, Schema.Top, any>
163
+
164
+ /**
165
+ * Extracts the union of middleware attached to an operation.
166
+ *
167
+ * @stability experimental
168
+ * @category utility types
169
+ * @since 4.0.0
170
+ */
171
+ export type Middleware<Op> = Op extends Operation<any, any, any, any, infer M> ? M : never
172
+
173
+ /**
174
+ * The decoded variables type of an operation, which is what a client method
175
+ * takes.
176
+ *
177
+ * @stability experimental
178
+ * @category utility types
179
+ * @since 4.0.0
180
+ */
181
+ export type Variables<Op extends Any> = Op["variables"]["Type"]
182
+
183
+ /**
184
+ * The decoded result type of an operation.
185
+ *
186
+ * @stability experimental
187
+ * @category utility types
188
+ * @since 4.0.0
189
+ */
190
+ export type Result<Op extends Any> = Op["result"]["Type"]
191
+
192
+ /**
193
+ * The error type of a client method for an operation: `GraphQLClientError`
194
+ * plus the errors of every attached middleware.
195
+ *
196
+ * @stability experimental
197
+ * @category utility types
198
+ * @since 4.0.0
199
+ */
200
+ export type Error<Op extends Any> = GraphQLClientError | GraphQLMiddleware.Error<Middleware<Op>>
201
+
202
+ /**
203
+ * The services a client method for an operation requires: the Schemas'
204
+ * encoding and decoding services plus the requirements of every attached
205
+ * middleware.
206
+ *
207
+ * @stability experimental
208
+ * @category utility types
209
+ * @since 4.0.0
210
+ */
211
+ export type Services<Op extends Any> =
212
+ | Op["variables"]["EncodingServices"]
213
+ | Op["result"]["DecodingServices"]
214
+ | GraphQLMiddleware.Requires<Middleware<Op>>
215
+
216
+ /**
217
+ * The type of an operation after attaching middleware `M`.
218
+ *
219
+ * @stability experimental
220
+ * @category utility types
221
+ * @since 4.0.0
222
+ */
223
+ export type AddMiddleware<Op, M> = Op extends Operation<infer K, infer N, infer V, infer R, infer Old>
224
+ ? Operation<K, N, V, R, Old | M>
225
+ : never
226
+
227
+ /**
228
+ * Tests whether a value is an {@link Operation}.
229
+ *
230
+ * @stability experimental
231
+ * @category guards
232
+ * @since 4.0.0
233
+ */
234
+ export const isOperation = (u: unknown): u is Any => hasProperty(u, TypeId)
235
+
236
+ const Proto = {
237
+ [TypeId]: TypeId,
238
+ pipe() {
239
+ return pipeArguments(this, arguments)
240
+ },
241
+ middleware(this: Any, middleware: GraphQLMiddleware.AnyService) {
242
+ return makeProto({ ...this, middlewares: [...this.middlewares, middleware] })
243
+ }
244
+ }
245
+
246
+ // The middleware type of an operation is phantom and its Schemas are erased to
247
+ // `Schema.Top` here, so the typed constructors below state their operation
248
+ // type with one assertion each.
249
+ const makeProto = (fields: Omit<Any, typeof TypeId | "pipe" | "middleware">): Any =>
250
+ Object.assign(Object.create(Proto), fields)
251
+
252
+ const makeOperation = <const K extends Kind>(kind: K) =>
253
+ <
254
+ const Name extends string,
255
+ Result extends Schema.Top,
256
+ Variables extends Schema.Top | Schema.Struct.Fields = Schema.Struct<{}>
257
+ >(
258
+ name: Name,
259
+ options: {
260
+ readonly document: string | DocumentTemplate
261
+ readonly variables?: Variables | undefined
262
+ readonly result: Result
263
+ }
264
+ ): Operation<K, Name, Variables extends Schema.Struct.Fields ? Schema.Struct<Variables> : Variables, Result> =>
265
+ makeProto({
266
+ kind,
267
+ name,
268
+ document: typeof options.document === "string"
269
+ ? options.document
270
+ : internal.joinTemplate(kind, name, options.document),
271
+ template: typeof options.document === "string" ? undefined : options.document,
272
+ variables: options.variables === undefined
273
+ ? Schema.Struct({})
274
+ : Schema.isSchema(options.variables)
275
+ ? options.variables
276
+ : Schema.Struct(options.variables as Schema.Struct.Fields),
277
+ result: options.result,
278
+ middlewares: []
279
+ }) as Operation<K, Name, Variables extends Schema.Struct.Fields ? Schema.Struct<Variables> : Variables, Result>
280
+
281
+ /**
282
+ * Defines a query. The client accepts decoded variables and encodes them
283
+ * through their Schema, including custom scalar codecs. `variables` accepts
284
+ * struct fields or a Schema; omit it for an operation without variables.
285
+ * `document` accepts printed text or a {@link DocumentTemplate}, joined once
286
+ * when the operation is defined.
287
+ *
288
+ * **Example** (A query with variables)
289
+ *
290
+ * ```ts import.meta.vitest
291
+ * import { Schema } from "effect"
292
+ * import { GraphQL } from "effect/graphql"
293
+ *
294
+ * const RepoIssues = GraphQL.query("RepoIssues", {
295
+ * document: "query RepoIssues($owner:String!,$name:String!){repository(owner:$owner,name:$name){issues(first:10){nodes{number title}}}}",
296
+ * variables: { owner: Schema.String, name: Schema.String },
297
+ * result: Schema.Struct({
298
+ * repository: Schema.NullOr(Schema.Struct({
299
+ * issues: Schema.Struct({
300
+ * nodes: Schema.NullOr(Schema.Array(Schema.NullOr(Schema.Struct({ number: Schema.Int, title: Schema.String }))))
301
+ * })
302
+ * }))
303
+ * })
304
+ * })
305
+ *
306
+ * RepoIssues.kind // => "query"
307
+ * RepoIssues.name // => "RepoIssues"
308
+ * ```
309
+ *
310
+ * @stability experimental
311
+ * @category constructors
312
+ * @since 4.0.0
313
+ */
314
+ export const query: <
315
+ const Name extends string,
316
+ Result extends Schema.Top,
317
+ Variables extends Schema.Top | Schema.Struct.Fields = Schema.Struct<{}>
318
+ >(
319
+ name: Name,
320
+ options: {
321
+ readonly document: string | DocumentTemplate
322
+ readonly variables?: Variables | undefined
323
+ readonly result: Result
324
+ }
325
+ ) => Operation<"query", Name, Variables extends Schema.Struct.Fields ? Schema.Struct<Variables> : Variables, Result> =
326
+ makeOperation("query")
327
+
328
+ /**
329
+ * Defines a mutation. Same shape as {@link query}.
330
+ *
331
+ * **Example** (A mutation)
332
+ *
333
+ * ```ts import.meta.vitest
334
+ * import { Schema } from "effect"
335
+ * import { GraphQL } from "effect/graphql"
336
+ *
337
+ * const AddComment = GraphQL.mutation("AddComment", {
338
+ * document: "mutation AddComment($subjectId:ID!,$body:String!){addComment(input:{subjectId:$subjectId,body:$body}){clientMutationId}}",
339
+ * variables: { subjectId: Schema.String, body: Schema.String },
340
+ * result: Schema.Struct({ addComment: Schema.NullOr(Schema.Struct({ clientMutationId: Schema.NullOr(Schema.String) })) })
341
+ * })
342
+ *
343
+ * AddComment.kind // => "mutation"
344
+ * ```
345
+ *
346
+ * @stability experimental
347
+ * @category constructors
348
+ * @since 4.0.0
349
+ */
350
+ export const mutation: <
351
+ const Name extends string,
352
+ Result extends Schema.Top,
353
+ Variables extends Schema.Top | Schema.Struct.Fields = Schema.Struct<{}>
354
+ >(
355
+ name: Name,
356
+ options: {
357
+ readonly document: string | DocumentTemplate
358
+ readonly variables?: Variables | undefined
359
+ readonly result: Result
360
+ }
361
+ ) => Operation<
362
+ "mutation",
363
+ Name,
364
+ Variables extends Schema.Struct.Fields ? Schema.Struct<Variables> : Variables,
365
+ Result
366
+ > = makeOperation("mutation")
367
+
368
+ /**
369
+ * Defines a subscription. The client method for a subscription returns a
370
+ * `Stream` of decoded events instead of an `Effect`.
371
+ *
372
+ * **Example** (A subscription)
373
+ *
374
+ * ```ts import.meta.vitest
375
+ * import { Schema } from "effect"
376
+ * import { GraphQL } from "effect/graphql"
377
+ *
378
+ * const IssueUpdated = GraphQL.subscription("IssueUpdated", {
379
+ * document: "subscription IssueUpdated($id:ID!){issueUpdated(id:$id){title}}",
380
+ * variables: { id: Schema.String },
381
+ * result: Schema.Struct({ issueUpdated: Schema.Struct({ title: Schema.String }) })
382
+ * })
383
+ *
384
+ * IssueUpdated.kind // => "subscription"
385
+ * ```
386
+ *
387
+ * @stability experimental
388
+ * @category constructors
389
+ * @since 4.0.0
390
+ */
391
+ export const subscription: <
392
+ const Name extends string,
393
+ Result extends Schema.Top,
394
+ Variables extends Schema.Top | Schema.Struct.Fields = Schema.Struct<{}>
395
+ >(
396
+ name: Name,
397
+ options: {
398
+ readonly document: string | DocumentTemplate
399
+ readonly variables?: Variables | undefined
400
+ readonly result: Result
401
+ }
402
+ ) => Operation<
403
+ "subscription",
404
+ Name,
405
+ Variables extends Schema.Struct.Fields ? Schema.Struct<Variables> : Variables,
406
+ Result
407
+ > = makeOperation("subscription")
408
+
409
+ /**
410
+ * The `__typename` Schema for the "every other type" member of a generated
411
+ * union.
412
+ *
413
+ * **Details**
414
+ *
415
+ * The type excludes selected names, allowing `__typename` narrowing. The
416
+ * decoder accepts any other string, including types added by the server
417
+ * later. Selected names are rejected so malformed selected results cannot
418
+ * fall through to the catch-all member.
419
+ *
420
+ * **Example** (The catch-all member of a union)
421
+ *
422
+ * ```ts import.meta.vitest
423
+ * import { Schema } from "effect"
424
+ * import { GraphQL } from "effect/graphql"
425
+ *
426
+ * type Node = "Issue" | "PullRequest" | "Repository"
427
+ *
428
+ * const OtherNode = Schema.Struct({
429
+ * __typename: GraphQL.otherTypename<Node>()(["Issue"]),
430
+ * id: Schema.String
431
+ * })
432
+ *
433
+ * Schema.decodeUnknownSync(OtherNode)({ __typename: "PullRequest", id: "1" }).__typename // => "PullRequest"
434
+ * Schema.decodeUnknownSync(OtherNode)({ __typename: "AddedLater", id: "2" }).__typename // => "AddedLater"
435
+ * Schema.is(OtherNode)({ __typename: "Issue", id: "3" }) // => false
436
+ * ```
437
+ *
438
+ * @stability experimental
439
+ * @category schemas
440
+ * @since 4.0.0
441
+ */
442
+ export const otherTypename = <All extends string>() =>
443
+ <const Selected extends ReadonlyArray<All>>(
444
+ selected: Selected
445
+ ): Schema.refine<Exclude<All, Selected[number]>, Schema.String> => {
446
+ const rejected = new Set<string>(selected)
447
+ // Type boundary: decoding is lenient by design. The guard passes any string
448
+ // other than the selected names, including names the server adds later, but
449
+ // the type only lists the names known when the code was generated.
450
+ return Schema.refine<Schema.String, Exclude<All, Selected[number]>>(
451
+ (name): name is Exclude<All, Selected[number]> => !rejected.has(name),
452
+ {
453
+ title: "otherTypename",
454
+ message: `Expected a __typename other than ${selected.map((s) => `"${s}"`).join(", ")}`
455
+ }
456
+ )(Schema.String)
457
+ }
458
+
459
+ /**
460
+ * The Schema for a GraphQL enum in a result position.
461
+ *
462
+ * **Details**
463
+ *
464
+ * It is typed as the declared literals but decodes any string, so a value the
465
+ * server adds later does not fail the whole query. Inputs stay strict: the
466
+ * generator uses `Schema.Literals` for enums in variables and input objects.
467
+ *
468
+ * **Example** (An enum that tolerates new values)
469
+ *
470
+ * ```ts import.meta.vitest
471
+ * import { Schema } from "effect"
472
+ * import { GraphQL } from "effect/graphql"
473
+ *
474
+ * const IssueState = GraphQL.enumLiterals(["OPEN", "CLOSED"])
475
+ *
476
+ * Schema.decodeUnknownSync(IssueState)("OPEN") // => "OPEN"
477
+ * Schema.decodeUnknownSync(IssueState)("MERGED") // => "MERGED"
478
+ * Schema.is(IssueState)(42) // => false
479
+ * ```
480
+ *
481
+ * @stability experimental
482
+ * @category schemas
483
+ * @since 4.0.0
484
+ */
485
+ export const enumLiterals = <const Literals extends ReadonlyArray<string>>(
486
+ literals: Literals
487
+ ): Schema.refine<Literals[number], Schema.String> =>
488
+ // Type boundary: decoding is lenient by design. The guard passes any string,
489
+ // including values the server adds later, but the type only lists the values
490
+ // known when the code was generated.
491
+ Schema.refine<Schema.String, Literals[number]>((_): _ is Literals[number] => true)(Schema.String).annotate({
492
+ title: `enum(${literals.join(" | ")})`,
493
+ description: `One of ${literals.map((l) => `"${l}"`).join(", ")}, or any string the server adds later`
494
+ })