@effect-gql/core 0.1.0 → 1.0.0
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.
- package/README.md +100 -0
- package/builder/index.cjs +1431 -0
- package/builder/index.cjs.map +1 -0
- package/builder/index.d.cts +259 -0
- package/{dist/builder/pipe-api.d.ts → builder/index.d.ts} +49 -21
- package/builder/index.js +1390 -0
- package/builder/index.js.map +1 -0
- package/index.cjs +3419 -0
- package/index.cjs.map +1 -0
- package/index.d.cts +523 -0
- package/index.d.ts +523 -0
- package/index.js +3242 -0
- package/index.js.map +1 -0
- package/package.json +19 -28
- package/schema-builder-Cvdq7Kz_.d.cts +963 -0
- package/schema-builder-Cvdq7Kz_.d.ts +963 -0
- package/server/index.cjs +1555 -0
- package/server/index.cjs.map +1 -0
- package/server/index.d.cts +680 -0
- package/server/index.d.ts +680 -0
- package/server/index.js +1524 -0
- package/server/index.js.map +1 -0
- package/dist/analyzer-extension.d.ts +0 -105
- package/dist/analyzer-extension.d.ts.map +0 -1
- package/dist/analyzer-extension.js +0 -137
- package/dist/analyzer-extension.js.map +0 -1
- package/dist/builder/execute.d.ts +0 -26
- package/dist/builder/execute.d.ts.map +0 -1
- package/dist/builder/execute.js +0 -104
- package/dist/builder/execute.js.map +0 -1
- package/dist/builder/field-builders.d.ts +0 -30
- package/dist/builder/field-builders.d.ts.map +0 -1
- package/dist/builder/field-builders.js +0 -200
- package/dist/builder/field-builders.js.map +0 -1
- package/dist/builder/index.d.ts +0 -7
- package/dist/builder/index.d.ts.map +0 -1
- package/dist/builder/index.js +0 -31
- package/dist/builder/index.js.map +0 -1
- package/dist/builder/pipe-api.d.ts.map +0 -1
- package/dist/builder/pipe-api.js +0 -151
- package/dist/builder/pipe-api.js.map +0 -1
- package/dist/builder/schema-builder.d.ts +0 -301
- package/dist/builder/schema-builder.d.ts.map +0 -1
- package/dist/builder/schema-builder.js +0 -566
- package/dist/builder/schema-builder.js.map +0 -1
- package/dist/builder/type-registry.d.ts +0 -80
- package/dist/builder/type-registry.d.ts.map +0 -1
- package/dist/builder/type-registry.js +0 -505
- package/dist/builder/type-registry.js.map +0 -1
- package/dist/builder/types.d.ts +0 -283
- package/dist/builder/types.d.ts.map +0 -1
- package/dist/builder/types.js +0 -3
- package/dist/builder/types.js.map +0 -1
- package/dist/cli/generate-schema.d.ts +0 -29
- package/dist/cli/generate-schema.d.ts.map +0 -1
- package/dist/cli/generate-schema.js +0 -233
- package/dist/cli/generate-schema.js.map +0 -1
- package/dist/cli/index.d.ts +0 -19
- package/dist/cli/index.d.ts.map +0 -1
- package/dist/cli/index.js +0 -24
- package/dist/cli/index.js.map +0 -1
- package/dist/context.d.ts +0 -18
- package/dist/context.d.ts.map +0 -1
- package/dist/context.js +0 -11
- package/dist/context.js.map +0 -1
- package/dist/error.d.ts +0 -45
- package/dist/error.d.ts.map +0 -1
- package/dist/error.js +0 -29
- package/dist/error.js.map +0 -1
- package/dist/extensions.d.ts +0 -130
- package/dist/extensions.d.ts.map +0 -1
- package/dist/extensions.js +0 -78
- package/dist/extensions.js.map +0 -1
- package/dist/index.d.ts +0 -12
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -47
- package/dist/index.js.map +0 -1
- package/dist/loader.d.ts +0 -169
- package/dist/loader.d.ts.map +0 -1
- package/dist/loader.js +0 -237
- package/dist/loader.js.map +0 -1
- package/dist/resolver-context.d.ts +0 -154
- package/dist/resolver-context.d.ts.map +0 -1
- package/dist/resolver-context.js +0 -184
- package/dist/resolver-context.js.map +0 -1
- package/dist/schema-mapping.d.ts +0 -30
- package/dist/schema-mapping.d.ts.map +0 -1
- package/dist/schema-mapping.js +0 -280
- package/dist/schema-mapping.js.map +0 -1
- package/dist/server/cache-control.d.ts +0 -96
- package/dist/server/cache-control.d.ts.map +0 -1
- package/dist/server/cache-control.js +0 -308
- package/dist/server/cache-control.js.map +0 -1
- package/dist/server/complexity.d.ts +0 -165
- package/dist/server/complexity.d.ts.map +0 -1
- package/dist/server/complexity.js +0 -433
- package/dist/server/complexity.js.map +0 -1
- package/dist/server/config.d.ts +0 -66
- package/dist/server/config.d.ts.map +0 -1
- package/dist/server/config.js +0 -104
- package/dist/server/config.js.map +0 -1
- package/dist/server/graphiql.d.ts +0 -5
- package/dist/server/graphiql.d.ts.map +0 -1
- package/dist/server/graphiql.js +0 -43
- package/dist/server/graphiql.js.map +0 -1
- package/dist/server/index.d.ts +0 -18
- package/dist/server/index.d.ts.map +0 -1
- package/dist/server/index.js +0 -48
- package/dist/server/index.js.map +0 -1
- package/dist/server/router.d.ts +0 -79
- package/dist/server/router.d.ts.map +0 -1
- package/dist/server/router.js +0 -232
- package/dist/server/router.js.map +0 -1
- package/dist/server/schema-builder-extensions.d.ts +0 -42
- package/dist/server/schema-builder-extensions.d.ts.map +0 -1
- package/dist/server/schema-builder-extensions.js +0 -48
- package/dist/server/schema-builder-extensions.js.map +0 -1
- package/dist/server/sse-adapter.d.ts +0 -64
- package/dist/server/sse-adapter.d.ts.map +0 -1
- package/dist/server/sse-adapter.js +0 -227
- package/dist/server/sse-adapter.js.map +0 -1
- package/dist/server/sse-types.d.ts +0 -192
- package/dist/server/sse-types.d.ts.map +0 -1
- package/dist/server/sse-types.js +0 -63
- package/dist/server/sse-types.js.map +0 -1
- package/dist/server/ws-adapter.d.ts +0 -39
- package/dist/server/ws-adapter.d.ts.map +0 -1
- package/dist/server/ws-adapter.js +0 -247
- package/dist/server/ws-adapter.js.map +0 -1
- package/dist/server/ws-types.d.ts +0 -169
- package/dist/server/ws-types.d.ts.map +0 -1
- package/dist/server/ws-types.js +0 -11
- package/dist/server/ws-types.js.map +0 -1
- package/dist/server/ws-utils.d.ts +0 -42
- package/dist/server/ws-utils.d.ts.map +0 -1
- package/dist/server/ws-utils.js +0 -99
- package/dist/server/ws-utils.js.map +0 -1
- package/src/analyzer-extension.ts +0 -254
- package/src/builder/execute.ts +0 -153
- package/src/builder/field-builders.ts +0 -322
- package/src/builder/index.ts +0 -48
- package/src/builder/pipe-api.ts +0 -312
- package/src/builder/schema-builder.ts +0 -970
- package/src/builder/type-registry.ts +0 -670
- package/src/builder/types.ts +0 -305
- package/src/context.ts +0 -23
- package/src/error.ts +0 -32
- package/src/extensions.ts +0 -240
- package/src/index.ts +0 -32
- package/src/loader.ts +0 -363
- package/src/resolver-context.ts +0 -253
- package/src/schema-mapping.ts +0 -307
- package/src/server/cache-control.ts +0 -590
- package/src/server/complexity.ts +0 -774
- package/src/server/config.ts +0 -174
- package/src/server/graphiql.ts +0 -38
- package/src/server/index.ts +0 -96
- package/src/server/router.ts +0 -432
- package/src/server/schema-builder-extensions.ts +0 -51
- package/src/server/sse-adapter.ts +0 -327
- package/src/server/sse-types.ts +0 -234
- package/src/server/ws-adapter.ts +0 -355
- package/src/server/ws-types.ts +0 -192
- package/src/server/ws-utils.ts +0 -136
package/src/schema-mapping.ts
DELETED
|
@@ -1,307 +0,0 @@
|
|
|
1
|
-
import { Effect } from "effect"
|
|
2
|
-
import * as S from "effect/Schema"
|
|
3
|
-
import * as AST from "effect/SchemaAST"
|
|
4
|
-
import {
|
|
5
|
-
GraphQLObjectType,
|
|
6
|
-
GraphQLString,
|
|
7
|
-
GraphQLInt,
|
|
8
|
-
GraphQLFloat,
|
|
9
|
-
GraphQLBoolean,
|
|
10
|
-
GraphQLNonNull,
|
|
11
|
-
GraphQLList,
|
|
12
|
-
GraphQLOutputType,
|
|
13
|
-
GraphQLInputObjectType,
|
|
14
|
-
GraphQLInputType,
|
|
15
|
-
GraphQLFieldConfigMap,
|
|
16
|
-
GraphQLFieldConfigArgumentMap,
|
|
17
|
-
} from "graphql"
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Check if a number AST node represents an integer
|
|
21
|
-
*/
|
|
22
|
-
const isIntegerType = (ast: AST.AST): boolean => {
|
|
23
|
-
// Check for Refinement with integer filter
|
|
24
|
-
if (ast._tag === "Refinement") {
|
|
25
|
-
const refinement = ast as any
|
|
26
|
-
|
|
27
|
-
// S.Int uses a filter with a specific predicate
|
|
28
|
-
// Check the annotations for the integer identifier
|
|
29
|
-
const annotations = refinement.annotations
|
|
30
|
-
if (annotations) {
|
|
31
|
-
// Check for identifier annotation
|
|
32
|
-
const identifier = AST.getIdentifierAnnotation(refinement)
|
|
33
|
-
if (identifier._tag === "Some" && identifier.value === "Int") {
|
|
34
|
-
return true
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Recursively check the base type
|
|
39
|
-
return isIntegerType(refinement.from)
|
|
40
|
-
}
|
|
41
|
-
return false
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Convert an Effect Schema to a GraphQL output type
|
|
46
|
-
*/
|
|
47
|
-
export const toGraphQLType = (schema: S.Schema<any, any, any>): GraphQLOutputType => {
|
|
48
|
-
const ast = schema.ast
|
|
49
|
-
|
|
50
|
-
// Handle primitives
|
|
51
|
-
if (ast._tag === "StringKeyword") return GraphQLString
|
|
52
|
-
if (ast._tag === "NumberKeyword") return GraphQLFloat
|
|
53
|
-
if (ast._tag === "BooleanKeyword") return GraphQLBoolean
|
|
54
|
-
|
|
55
|
-
// Handle refinements (e.g., S.Int)
|
|
56
|
-
if (ast._tag === "Refinement") {
|
|
57
|
-
if (isIntegerType(ast)) {
|
|
58
|
-
return GraphQLInt
|
|
59
|
-
}
|
|
60
|
-
// For other refinements, use the base type
|
|
61
|
-
return toGraphQLType(S.make((ast as any).from))
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// Handle literals
|
|
65
|
-
if (ast._tag === "Literal") {
|
|
66
|
-
if (typeof ast.literal === "string") return GraphQLString
|
|
67
|
-
if (typeof ast.literal === "number") {
|
|
68
|
-
// Check if it's an integer literal
|
|
69
|
-
return Number.isInteger(ast.literal) ? GraphQLInt : GraphQLFloat
|
|
70
|
-
}
|
|
71
|
-
if (typeof ast.literal === "boolean") return GraphQLBoolean
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// Handle arrays - check for TupleType
|
|
75
|
-
if (ast._tag === "TupleType") {
|
|
76
|
-
const elements = ast.elements
|
|
77
|
-
if (elements.length > 0) {
|
|
78
|
-
const elementSchema = S.make(elements[0].type)
|
|
79
|
-
return new GraphQLList(toGraphQLType(elementSchema))
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Handle structs/objects
|
|
84
|
-
if (ast._tag === "TypeLiteral") {
|
|
85
|
-
const fields: GraphQLFieldConfigMap<any, any> = {}
|
|
86
|
-
|
|
87
|
-
for (const field of ast.propertySignatures) {
|
|
88
|
-
const fieldName = String(field.name)
|
|
89
|
-
const fieldSchema = S.make(field.type)
|
|
90
|
-
let fieldType = toGraphQLType(fieldSchema)
|
|
91
|
-
|
|
92
|
-
// Make non-optional fields non-null
|
|
93
|
-
if (!field.isOptional) {
|
|
94
|
-
fieldType = new GraphQLNonNull(fieldType)
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
fields[fieldName] = { type: fieldType }
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Generate a name from the schema or use a default
|
|
101
|
-
const typeName =
|
|
102
|
-
(schema as any).annotations?.identifier || `Object_${Math.random().toString(36).slice(2, 11)}`
|
|
103
|
-
|
|
104
|
-
return new GraphQLObjectType({
|
|
105
|
-
name: typeName,
|
|
106
|
-
fields,
|
|
107
|
-
})
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// Handle transformations - use the "to" side
|
|
111
|
-
if (ast._tag === "Transformation") {
|
|
112
|
-
return toGraphQLType(S.make(ast.to))
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// Handle unions (use first type as fallback)
|
|
116
|
-
if (ast._tag === "Union") {
|
|
117
|
-
const types = ast.types
|
|
118
|
-
if (types.length > 0) {
|
|
119
|
-
return toGraphQLType(S.make(types[0]))
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// Handle Suspend (recursive/self-referential schemas)
|
|
124
|
-
if (ast._tag === "Suspend") {
|
|
125
|
-
const innerAst = (ast as any).f()
|
|
126
|
-
return toGraphQLType(S.make(innerAst))
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// Default fallback
|
|
130
|
-
return GraphQLString
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Convert an Effect Schema to a GraphQL input type
|
|
135
|
-
*/
|
|
136
|
-
export const toGraphQLInputType = (schema: S.Schema<any, any, any>): GraphQLInputType => {
|
|
137
|
-
const ast = schema.ast
|
|
138
|
-
|
|
139
|
-
// Handle primitives
|
|
140
|
-
if (ast._tag === "StringKeyword") return GraphQLString
|
|
141
|
-
if (ast._tag === "NumberKeyword") return GraphQLFloat
|
|
142
|
-
if (ast._tag === "BooleanKeyword") return GraphQLBoolean
|
|
143
|
-
|
|
144
|
-
// Handle refinements (e.g., S.Int)
|
|
145
|
-
if (ast._tag === "Refinement") {
|
|
146
|
-
if (isIntegerType(ast)) {
|
|
147
|
-
return GraphQLInt
|
|
148
|
-
}
|
|
149
|
-
// For other refinements, use the base type
|
|
150
|
-
return toGraphQLInputType(S.make((ast as any).from))
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// Handle literals
|
|
154
|
-
if (ast._tag === "Literal") {
|
|
155
|
-
if (typeof ast.literal === "string") return GraphQLString
|
|
156
|
-
if (typeof ast.literal === "number") {
|
|
157
|
-
// Check if it's an integer literal
|
|
158
|
-
return Number.isInteger(ast.literal) ? GraphQLInt : GraphQLFloat
|
|
159
|
-
}
|
|
160
|
-
if (typeof ast.literal === "boolean") return GraphQLBoolean
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// Handle arrays
|
|
164
|
-
if (ast._tag === "TupleType") {
|
|
165
|
-
const elements = ast.elements
|
|
166
|
-
if (elements.length > 0) {
|
|
167
|
-
const elementSchema = S.make(elements[0].type)
|
|
168
|
-
return new GraphQLList(toGraphQLInputType(elementSchema))
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// Handle structs/objects as input types
|
|
173
|
-
if (ast._tag === "TypeLiteral") {
|
|
174
|
-
const fields: Record<string, { type: GraphQLInputType }> = {}
|
|
175
|
-
|
|
176
|
-
for (const field of ast.propertySignatures) {
|
|
177
|
-
const fieldName = String(field.name)
|
|
178
|
-
const fieldSchema = S.make(field.type)
|
|
179
|
-
let fieldType = toGraphQLInputType(fieldSchema)
|
|
180
|
-
|
|
181
|
-
// Make non-optional fields non-null
|
|
182
|
-
if (!field.isOptional) {
|
|
183
|
-
fieldType = new GraphQLNonNull(fieldType)
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
fields[fieldName] = { type: fieldType }
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const typeName =
|
|
190
|
-
(schema as any).annotations?.identifier || `Input_${Math.random().toString(36).slice(2, 11)}`
|
|
191
|
-
|
|
192
|
-
return new GraphQLInputObjectType({
|
|
193
|
-
name: typeName,
|
|
194
|
-
fields,
|
|
195
|
-
})
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// Handle transformations - use the "from" side for input
|
|
199
|
-
if (ast._tag === "Transformation") {
|
|
200
|
-
return toGraphQLInputType(S.make(ast.from))
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// Handle unions (use first type as fallback)
|
|
204
|
-
if (ast._tag === "Union") {
|
|
205
|
-
const types = ast.types
|
|
206
|
-
if (types.length > 0) {
|
|
207
|
-
return toGraphQLInputType(S.make(types[0]))
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
// Handle Suspend (recursive/self-referential schemas)
|
|
212
|
-
if (ast._tag === "Suspend") {
|
|
213
|
-
const innerAst = (ast as any).f()
|
|
214
|
-
return toGraphQLInputType(S.make(innerAst))
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
// Default fallback
|
|
218
|
-
return GraphQLString
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Additional field configuration for computed/relational fields
|
|
223
|
-
*/
|
|
224
|
-
export interface AdditionalField<Parent, Args, R, E, A> {
|
|
225
|
-
type: GraphQLOutputType
|
|
226
|
-
args?: GraphQLFieldConfigArgumentMap
|
|
227
|
-
description?: string
|
|
228
|
-
resolve: (parent: Parent, args: Args) => Effect.Effect<A, E, R>
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Create a GraphQL Object Type from an Effect Schema with a name
|
|
233
|
-
* Optionally add computed/relational fields with resolvers
|
|
234
|
-
*/
|
|
235
|
-
export const toGraphQLObjectType = <T>(
|
|
236
|
-
name: string,
|
|
237
|
-
schema: S.Schema<any, any, any>,
|
|
238
|
-
additionalFields?: Record<string, AdditionalField<T, any, any, any, any>>
|
|
239
|
-
): GraphQLObjectType => {
|
|
240
|
-
const ast = schema.ast
|
|
241
|
-
|
|
242
|
-
if (ast._tag === "TypeLiteral") {
|
|
243
|
-
const fields: GraphQLFieldConfigMap<any, any> = {}
|
|
244
|
-
|
|
245
|
-
// Add fields from schema
|
|
246
|
-
for (const field of ast.propertySignatures) {
|
|
247
|
-
const fieldName = String(field.name)
|
|
248
|
-
const fieldSchema = S.make(field.type)
|
|
249
|
-
let fieldType = toGraphQLType(fieldSchema)
|
|
250
|
-
|
|
251
|
-
// Make non-optional fields non-null
|
|
252
|
-
if (!field.isOptional) {
|
|
253
|
-
fieldType = new GraphQLNonNull(fieldType)
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
fields[fieldName] = { type: fieldType }
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
// Add additional computed/relational fields
|
|
260
|
-
if (additionalFields) {
|
|
261
|
-
for (const [fieldName, fieldConfig] of Object.entries(additionalFields)) {
|
|
262
|
-
fields[fieldName] = {
|
|
263
|
-
type: fieldConfig.type,
|
|
264
|
-
args: fieldConfig.args,
|
|
265
|
-
description: fieldConfig.description,
|
|
266
|
-
// Note: resolve will be set later when runtime is available
|
|
267
|
-
resolve: fieldConfig.resolve as any,
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
return new GraphQLObjectType({
|
|
273
|
-
name,
|
|
274
|
-
fields,
|
|
275
|
-
})
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
throw new Error(`Schema must be an object type to convert to GraphQLObjectType`)
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* Convert an Effect Schema to GraphQL arguments
|
|
283
|
-
*/
|
|
284
|
-
export const toGraphQLArgs = (schema: S.Schema<any, any, any>): GraphQLFieldConfigArgumentMap => {
|
|
285
|
-
const ast = schema.ast
|
|
286
|
-
|
|
287
|
-
if (ast._tag === "TypeLiteral") {
|
|
288
|
-
const args: GraphQLFieldConfigArgumentMap = {}
|
|
289
|
-
|
|
290
|
-
for (const field of ast.propertySignatures) {
|
|
291
|
-
const fieldName = String(field.name)
|
|
292
|
-
const fieldSchema = S.make(field.type)
|
|
293
|
-
let fieldType = toGraphQLInputType(fieldSchema)
|
|
294
|
-
|
|
295
|
-
// Make non-optional fields non-null
|
|
296
|
-
if (!field.isOptional) {
|
|
297
|
-
fieldType = new GraphQLNonNull(fieldType)
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
args[fieldName] = { type: fieldType }
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
return args
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
throw new Error(`Schema must be an object type to convert to GraphQL arguments`)
|
|
307
|
-
}
|