@gqlkit-ts/runtime 0.0.1 → 0.1.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/LICENSE +21 -0
- package/dist/index.d.ts +542 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +49 -0
- package/dist/index.js.map +1 -0
- package/package.json +38 -7
- package/README.md +0 -45
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Masayuki Izumi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,542 @@
|
|
|
1
|
+
import type { GraphQLResolveInfo } from "graphql";
|
|
2
|
+
/**
|
|
3
|
+
* Represents the locations where a directive can be applied.
|
|
4
|
+
* This corresponds to GraphQL Type System Directive Locations.
|
|
5
|
+
*/
|
|
6
|
+
export type DirectiveLocation = "SCHEMA" | "SCALAR" | "OBJECT" | "FIELD_DEFINITION" | "ARGUMENT_DEFINITION" | "INTERFACE" | "UNION" | "ENUM" | "ENUM_VALUE" | "INPUT_OBJECT" | "INPUT_FIELD_DEFINITION";
|
|
7
|
+
/**
|
|
8
|
+
* Represents a GraphQL directive with name, arguments, and location.
|
|
9
|
+
* Used to define custom directives that can be attached to types and fields.
|
|
10
|
+
*
|
|
11
|
+
* @typeParam Name - The directive name (without @)
|
|
12
|
+
* @typeParam Args - The argument types for the directive
|
|
13
|
+
* @typeParam Location - The location(s) where the directive can be applied
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* type AuthDirective<R extends string[]> = GqlDirective<"auth", { roles: R }, "FIELD_DEFINITION">;
|
|
18
|
+
* type CacheDirective = GqlDirective<"cache", { maxAge: number }, "FIELD_DEFINITION" | "OBJECT">;
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export type GqlDirective<Name extends string, Args extends Record<string, unknown> = Record<string, never>, Location extends DirectiveLocation | DirectiveLocation[] = DirectiveLocation> = {
|
|
22
|
+
readonly " $directiveName": Name;
|
|
23
|
+
readonly " $directiveArgs": Args;
|
|
24
|
+
readonly " $directiveLocation": Location;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Metadata structure for field-level GraphQL metadata.
|
|
28
|
+
* Used to attach directives, default values, and other metadata to individual fields.
|
|
29
|
+
*
|
|
30
|
+
* @typeParam Meta - The metadata configuration object
|
|
31
|
+
*/
|
|
32
|
+
export interface GqlFieldMetaShape<Meta extends {
|
|
33
|
+
directives?: ReadonlyArray<GqlDirective<string, Record<string, unknown>, DirectiveLocation | DirectiveLocation[]>>;
|
|
34
|
+
defaultValue?: unknown;
|
|
35
|
+
}> {
|
|
36
|
+
readonly directives?: Meta["directives"];
|
|
37
|
+
readonly defaultValue?: Meta["defaultValue"];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Attaches metadata to a field type.
|
|
41
|
+
* The metadata is embedded as optional properties to maintain compatibility
|
|
42
|
+
* with the underlying type.
|
|
43
|
+
*
|
|
44
|
+
* The structure uses two properties:
|
|
45
|
+
* - `$gqlkitFieldMeta`: Contains the metadata object with directives and defaultValue
|
|
46
|
+
* - `$gqlkitOriginalType`: Preserves the original type T to maintain nullability information
|
|
47
|
+
*
|
|
48
|
+
* This design is necessary because TypeScript normalizes `(T | null) & { metadata }` to
|
|
49
|
+
* `(T & { metadata }) | never`, which loses the null part of the union. By storing
|
|
50
|
+
* the original type in `$gqlkitOriginalType`, we can recover the full type information
|
|
51
|
+
* during CLI analysis.
|
|
52
|
+
*
|
|
53
|
+
* @typeParam T - The base type to attach metadata to
|
|
54
|
+
* @typeParam Meta - The metadata configuration object containing directives and/or defaultValue
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* // With directives
|
|
59
|
+
* type User = {
|
|
60
|
+
* id: GqlField<IDString, { directives: [AuthDirective<{ role: ["USER"] }>] }>;
|
|
61
|
+
* bio: GqlField<string | null, { directives: [AuthDirective<{ role: ["ADMIN"] }>] }>;
|
|
62
|
+
* };
|
|
63
|
+
*
|
|
64
|
+
* // With default value
|
|
65
|
+
* type PaginationInput = {
|
|
66
|
+
* limit: GqlField<Int, { defaultValue: 10 }>;
|
|
67
|
+
* offset: GqlField<Int, { defaultValue: 0 }>;
|
|
68
|
+
* };
|
|
69
|
+
*
|
|
70
|
+
* // With both directives and default value
|
|
71
|
+
* type SearchInput = {
|
|
72
|
+
* query: GqlField<string, { defaultValue: ""; directives: [SomeDirective] }>;
|
|
73
|
+
* };
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export type GqlField<T, Meta extends {
|
|
77
|
+
directives?: ReadonlyArray<GqlDirective<string, Record<string, unknown>, DirectiveLocation | DirectiveLocation[]>>;
|
|
78
|
+
defaultValue?: unknown;
|
|
79
|
+
} = object> = T & {
|
|
80
|
+
readonly " $gqlkitFieldMeta"?: GqlFieldMetaShape<Meta>;
|
|
81
|
+
readonly " $gqlkitOriginalType"?: T;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Marker type for GqlInterface - used internally for type discrimination.
|
|
85
|
+
*/
|
|
86
|
+
export type GqlInterfaceMarker = Record<string, unknown>;
|
|
87
|
+
/**
|
|
88
|
+
* Interface metadata structure embedded in intersection types.
|
|
89
|
+
* Used by CLI to detect and identify interface types through type analysis.
|
|
90
|
+
*
|
|
91
|
+
* @typeParam Meta - The metadata configuration object containing implements
|
|
92
|
+
*/
|
|
93
|
+
export interface GqlInterfaceMetaShape<Meta extends {
|
|
94
|
+
implements?: ReadonlyArray<GqlInterfaceMarker>;
|
|
95
|
+
} = object> {
|
|
96
|
+
readonly " $gqlkitInterface": true;
|
|
97
|
+
readonly implements?: Meta["implements"];
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* GraphQL interface type definition utility.
|
|
101
|
+
* Use this to define GraphQL interface types that can be implemented by object types.
|
|
102
|
+
*
|
|
103
|
+
* @typeParam T - The interface field definitions as an object type
|
|
104
|
+
* @typeParam Meta - Optional metadata containing implements for interface inheritance
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* // Basic interface definition
|
|
109
|
+
* export type Node = GqlInterface<{
|
|
110
|
+
* id: IDString;
|
|
111
|
+
* }>;
|
|
112
|
+
*
|
|
113
|
+
* export type Timestamped = GqlInterface<{
|
|
114
|
+
* createdAt: DateTime;
|
|
115
|
+
* updatedAt: DateTime;
|
|
116
|
+
* }>;
|
|
117
|
+
*
|
|
118
|
+
* // Interface inheriting other interfaces
|
|
119
|
+
* export type Entity = GqlInterface<
|
|
120
|
+
* {
|
|
121
|
+
* id: IDString;
|
|
122
|
+
* createdAt: DateTime;
|
|
123
|
+
* updatedAt: DateTime;
|
|
124
|
+
* },
|
|
125
|
+
* { implements: [Node, Timestamped] }
|
|
126
|
+
* >;
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
export type GqlInterface<T extends Record<string, unknown>, Meta extends {
|
|
130
|
+
implements?: ReadonlyArray<GqlInterfaceMarker>;
|
|
131
|
+
} = object> = T & {
|
|
132
|
+
readonly " $gqlkitInterfaceMeta"?: GqlInterfaceMetaShape<Meta>;
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* Metadata structure for type-level GraphQL metadata.
|
|
136
|
+
* Used to attach directives and other metadata to types.
|
|
137
|
+
*
|
|
138
|
+
* @typeParam Meta - The metadata configuration object
|
|
139
|
+
*/
|
|
140
|
+
export interface GqlTypeMetaShape<Meta extends {
|
|
141
|
+
directives?: ReadonlyArray<GqlDirective<string, Record<string, unknown>, DirectiveLocation | DirectiveLocation[]>>;
|
|
142
|
+
implements?: ReadonlyArray<GqlInterfaceMarker>;
|
|
143
|
+
}> {
|
|
144
|
+
readonly directives?: Meta["directives"];
|
|
145
|
+
readonly implements?: Meta["implements"];
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Attaches metadata to a type definition.
|
|
149
|
+
* The metadata is embedded as optional properties to maintain compatibility
|
|
150
|
+
* with the underlying type.
|
|
151
|
+
*
|
|
152
|
+
* The structure uses two properties:
|
|
153
|
+
* - `$gqlkitTypeMeta`: Contains the metadata object with directives and implements
|
|
154
|
+
* - `$gqlkitOriginalType`: Preserves the original type T to maintain nullability information
|
|
155
|
+
*
|
|
156
|
+
* @typeParam T - The base type to attach metadata to
|
|
157
|
+
* @typeParam Meta - The metadata configuration object containing directives and/or implements
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```typescript
|
|
161
|
+
* // Type with directives only
|
|
162
|
+
* type User = GqlObject<
|
|
163
|
+
* {
|
|
164
|
+
* id: string;
|
|
165
|
+
* name: string;
|
|
166
|
+
* },
|
|
167
|
+
* { directives: [CacheDirective<{ maxAge: 60 }>] }
|
|
168
|
+
* >;
|
|
169
|
+
*
|
|
170
|
+
* // Type implementing an interface
|
|
171
|
+
* type User = GqlObject<
|
|
172
|
+
* {
|
|
173
|
+
* id: IDString;
|
|
174
|
+
* name: string;
|
|
175
|
+
* },
|
|
176
|
+
* { implements: [Node] }
|
|
177
|
+
* >;
|
|
178
|
+
*
|
|
179
|
+
* // Type with both directives and implements
|
|
180
|
+
* type Post = GqlObject<
|
|
181
|
+
* {
|
|
182
|
+
* id: IDString;
|
|
183
|
+
* title: string;
|
|
184
|
+
* createdAt: DateTime;
|
|
185
|
+
* },
|
|
186
|
+
* {
|
|
187
|
+
* implements: [Node, Timestamped],
|
|
188
|
+
* directives: [CacheDirective<{ maxAge: 60 }>]
|
|
189
|
+
* }
|
|
190
|
+
* >;
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
export type GqlObject<T, Meta extends {
|
|
194
|
+
directives?: ReadonlyArray<GqlDirective<string, Record<string, unknown>, DirectiveLocation | DirectiveLocation[]>>;
|
|
195
|
+
implements?: ReadonlyArray<GqlInterfaceMarker>;
|
|
196
|
+
} = {
|
|
197
|
+
directives: [];
|
|
198
|
+
}> = T & {
|
|
199
|
+
readonly " $gqlkitTypeMeta"?: GqlTypeMetaShape<Meta>;
|
|
200
|
+
readonly " $gqlkitOriginalType"?: T;
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* Scalar metadata structure embedded in intersection types.
|
|
204
|
+
* Used by CLI to detect and identify scalar types through type analysis.
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```typescript
|
|
208
|
+
* // A type with scalar metadata
|
|
209
|
+
* type MyScalar = Base & { " $gqlkitScalar"?: ScalarMetadataShape };
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
export interface ScalarMetadataShape {
|
|
213
|
+
readonly name: string;
|
|
214
|
+
readonly only?: "input" | "output";
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Utility type for defining custom scalar types with metadata.
|
|
218
|
+
* The metadata is embedded as an optional property to maintain compatibility
|
|
219
|
+
* with the underlying base type.
|
|
220
|
+
*
|
|
221
|
+
* @typeParam Name - The GraphQL scalar name
|
|
222
|
+
* @typeParam Base - The underlying TypeScript type
|
|
223
|
+
* @typeParam Only - Usage constraint: "input" for input-only, "output" for output-only, undefined for both
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* ```typescript
|
|
227
|
+
* // Basic custom scalar
|
|
228
|
+
* type DateTime = GqlScalar<"DateTime", Date>;
|
|
229
|
+
*
|
|
230
|
+
* // Input-only scalar
|
|
231
|
+
* type DateTimeInput = GqlScalar<"DateTime", Date, "input">;
|
|
232
|
+
*
|
|
233
|
+
* // Output-only scalar (can accept multiple base types)
|
|
234
|
+
* type DateTimeOutput = GqlScalar<"DateTime", Date | string, "output">;
|
|
235
|
+
* ```
|
|
236
|
+
*/
|
|
237
|
+
export type GqlScalar<Name extends string, Base, Only extends "input" | "output" | undefined = undefined> = Base & {
|
|
238
|
+
" $gqlkitScalar"?: {
|
|
239
|
+
name: Name;
|
|
240
|
+
only: Only;
|
|
241
|
+
};
|
|
242
|
+
};
|
|
243
|
+
/**
|
|
244
|
+
* GraphQL Int scalar type.
|
|
245
|
+
* Use this to explicitly mark a field as an integer.
|
|
246
|
+
* Includes metadata for CLI detection.
|
|
247
|
+
*/
|
|
248
|
+
export type Int = GqlScalar<"Int", number>;
|
|
249
|
+
/**
|
|
250
|
+
* GraphQL Float scalar type.
|
|
251
|
+
* Use this to explicitly mark a field as a floating-point number.
|
|
252
|
+
* Note: Plain `number` type will also map to Float by default.
|
|
253
|
+
* Includes metadata for CLI detection.
|
|
254
|
+
*/
|
|
255
|
+
export type Float = GqlScalar<"Float", number>;
|
|
256
|
+
/**
|
|
257
|
+
* GraphQL ID scalar type (string-based).
|
|
258
|
+
* Use this when the ID is represented as a string in your system.
|
|
259
|
+
* Includes metadata for CLI detection.
|
|
260
|
+
*/
|
|
261
|
+
export type IDString = GqlScalar<"ID", string>;
|
|
262
|
+
/**
|
|
263
|
+
* GraphQL ID scalar type (number-based).
|
|
264
|
+
* Use this when the ID is represented as a number in your system.
|
|
265
|
+
* Includes metadata for CLI detection.
|
|
266
|
+
*/
|
|
267
|
+
export type IDNumber = GqlScalar<"ID", number>;
|
|
268
|
+
/**
|
|
269
|
+
* Type alias representing no arguments for a resolver.
|
|
270
|
+
* Use this when defining resolvers that don't accept any arguments.
|
|
271
|
+
*/
|
|
272
|
+
export type NoArgs = Record<string, never>;
|
|
273
|
+
/**
|
|
274
|
+
* Type for Query resolver functions.
|
|
275
|
+
* @typeParam TArgs - The type of arguments the resolver accepts
|
|
276
|
+
* @typeParam TResult - The return type of the resolver
|
|
277
|
+
* @typeParam TContext - The context type (defaults to unknown)
|
|
278
|
+
*/
|
|
279
|
+
export type QueryResolverFn<TArgs, TResult, TContext = unknown> = (root: undefined, args: TArgs, context: TContext, info: GraphQLResolveInfo) => TResult | Promise<TResult>;
|
|
280
|
+
/**
|
|
281
|
+
* Type for Mutation resolver functions.
|
|
282
|
+
* @typeParam TArgs - The type of arguments the resolver accepts
|
|
283
|
+
* @typeParam TResult - The return type of the resolver
|
|
284
|
+
* @typeParam TContext - The context type (defaults to unknown)
|
|
285
|
+
*/
|
|
286
|
+
export type MutationResolverFn<TArgs, TResult, TContext = unknown> = (root: undefined, args: TArgs, context: TContext, info: GraphQLResolveInfo) => TResult | Promise<TResult>;
|
|
287
|
+
/**
|
|
288
|
+
* Type for Field resolver functions.
|
|
289
|
+
* @typeParam TParent - The parent type this field belongs to
|
|
290
|
+
* @typeParam TArgs - The type of arguments the resolver accepts
|
|
291
|
+
* @typeParam TResult - The return type of the resolver
|
|
292
|
+
* @typeParam TContext - The context type (defaults to unknown)
|
|
293
|
+
*/
|
|
294
|
+
export type FieldResolverFn<TParent, TArgs, TResult, TContext = unknown> = (parent: TParent, args: TArgs, context: TContext, info: GraphQLResolveInfo) => TResult | Promise<TResult>;
|
|
295
|
+
/**
|
|
296
|
+
* The kind of resolver.
|
|
297
|
+
*/
|
|
298
|
+
export type ResolverKind = "query" | "mutation" | "field";
|
|
299
|
+
/**
|
|
300
|
+
* The kind of abstract type resolver.
|
|
301
|
+
*/
|
|
302
|
+
export type AbstractResolverKind = "resolveType" | "isTypeOf";
|
|
303
|
+
/**
|
|
304
|
+
* Type for resolveType resolver functions.
|
|
305
|
+
* Used to resolve the concrete type of a union or interface type at runtime.
|
|
306
|
+
* @typeParam TAbstract - The abstract type (union or interface) to resolve
|
|
307
|
+
* @typeParam TContext - The context type (defaults to unknown)
|
|
308
|
+
*/
|
|
309
|
+
export type ResolveTypeResolverFn<TAbstract, TContext = unknown> = (value: TAbstract, context: TContext, info: GraphQLResolveInfo) => string | Promise<string>;
|
|
310
|
+
/**
|
|
311
|
+
* Type for isTypeOf resolver functions.
|
|
312
|
+
* Used to check if a value belongs to a specific object type.
|
|
313
|
+
* @typeParam TContext - The context type (defaults to unknown)
|
|
314
|
+
*/
|
|
315
|
+
export type IsTypeOfResolverFn<TContext = unknown> = (value: unknown, context: TContext, info: GraphQLResolveInfo) => boolean | Promise<boolean>;
|
|
316
|
+
/**
|
|
317
|
+
* Abstract type resolver metadata structure embedded in intersection types.
|
|
318
|
+
* Used by CLI to detect and identify abstract type resolvers through type analysis.
|
|
319
|
+
*/
|
|
320
|
+
export interface AbstractResolverMetadataShape {
|
|
321
|
+
readonly kind: AbstractResolverKind;
|
|
322
|
+
readonly targetType: unknown;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* resolveType resolver type with metadata.
|
|
326
|
+
* The metadata is embedded as an optional property with space-prefixed key
|
|
327
|
+
* to avoid collision with user-defined properties.
|
|
328
|
+
* @typeParam TAbstract - The abstract type (union or interface) to resolve
|
|
329
|
+
* @typeParam TContext - The context type (defaults to unknown)
|
|
330
|
+
*/
|
|
331
|
+
export type ResolveTypeResolver<TAbstract, TContext = unknown> = ResolveTypeResolverFn<TAbstract, TContext> & {
|
|
332
|
+
" $gqlkitAbstractResolver"?: {
|
|
333
|
+
kind: "resolveType";
|
|
334
|
+
targetType: TAbstract;
|
|
335
|
+
};
|
|
336
|
+
};
|
|
337
|
+
/**
|
|
338
|
+
* isTypeOf resolver type with metadata.
|
|
339
|
+
* The metadata is embedded as an optional property with space-prefixed key
|
|
340
|
+
* to avoid collision with user-defined properties.
|
|
341
|
+
* @typeParam TObject - The object type to check
|
|
342
|
+
* @typeParam TContext - The context type (defaults to unknown)
|
|
343
|
+
*/
|
|
344
|
+
export type IsTypeOfResolver<TObject, TContext = unknown> = IsTypeOfResolverFn<TContext> & {
|
|
345
|
+
" $gqlkitAbstractResolver"?: {
|
|
346
|
+
kind: "isTypeOf";
|
|
347
|
+
targetType: TObject;
|
|
348
|
+
};
|
|
349
|
+
};
|
|
350
|
+
/**
|
|
351
|
+
* Resolver metadata structure embedded in intersection types.
|
|
352
|
+
* Used by CLI to detect and identify resolver types through type analysis.
|
|
353
|
+
*/
|
|
354
|
+
export interface ResolverMetadataShape {
|
|
355
|
+
readonly kind: ResolverKind;
|
|
356
|
+
readonly args: unknown;
|
|
357
|
+
readonly result: unknown;
|
|
358
|
+
readonly parent?: unknown;
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Query resolver type with metadata.
|
|
362
|
+
* The metadata is embedded as an optional property with space-prefixed key
|
|
363
|
+
* to avoid collision with user-defined properties.
|
|
364
|
+
* @typeParam TArgs - The type of arguments the resolver accepts
|
|
365
|
+
* @typeParam TResult - The return type of the resolver
|
|
366
|
+
* @typeParam TContext - The context type (defaults to unknown)
|
|
367
|
+
* @typeParam TDirectives - Array of directives to attach to this field (defaults to [])
|
|
368
|
+
*/
|
|
369
|
+
export type QueryResolver<TArgs, TResult, TContext = unknown, TDirectives extends ReadonlyArray<GqlDirective<string, Record<string, unknown>, DirectiveLocation | DirectiveLocation[]>> = []> = QueryResolverFn<TArgs, TResult, TContext> & {
|
|
370
|
+
" $gqlkitResolver"?: {
|
|
371
|
+
kind: "query";
|
|
372
|
+
args: TArgs;
|
|
373
|
+
result: TResult;
|
|
374
|
+
directives: TDirectives;
|
|
375
|
+
};
|
|
376
|
+
};
|
|
377
|
+
/**
|
|
378
|
+
* Mutation resolver type with metadata.
|
|
379
|
+
* The metadata is embedded as an optional property with space-prefixed key
|
|
380
|
+
* to avoid collision with user-defined properties.
|
|
381
|
+
* @typeParam TArgs - The type of arguments the resolver accepts
|
|
382
|
+
* @typeParam TResult - The return type of the resolver
|
|
383
|
+
* @typeParam TContext - The context type (defaults to unknown)
|
|
384
|
+
* @typeParam TDirectives - Array of directives to attach to this field (defaults to [])
|
|
385
|
+
*/
|
|
386
|
+
export type MutationResolver<TArgs, TResult, TContext = unknown, TDirectives extends ReadonlyArray<GqlDirective<string, Record<string, unknown>, DirectiveLocation | DirectiveLocation[]>> = []> = MutationResolverFn<TArgs, TResult, TContext> & {
|
|
387
|
+
" $gqlkitResolver"?: {
|
|
388
|
+
kind: "mutation";
|
|
389
|
+
args: TArgs;
|
|
390
|
+
result: TResult;
|
|
391
|
+
directives: TDirectives;
|
|
392
|
+
};
|
|
393
|
+
};
|
|
394
|
+
/**
|
|
395
|
+
* Field resolver type with metadata.
|
|
396
|
+
* The metadata is embedded as an optional property with space-prefixed key
|
|
397
|
+
* to avoid collision with user-defined properties.
|
|
398
|
+
* @typeParam TParent - The parent type this field belongs to
|
|
399
|
+
* @typeParam TArgs - The type of arguments the resolver accepts
|
|
400
|
+
* @typeParam TResult - The return type of the resolver
|
|
401
|
+
* @typeParam TContext - The context type (defaults to unknown)
|
|
402
|
+
* @typeParam TDirectives - Array of directives to attach to this field (defaults to [])
|
|
403
|
+
*/
|
|
404
|
+
export type FieldResolver<TParent, TArgs, TResult, TContext = unknown, TDirectives extends ReadonlyArray<GqlDirective<string, Record<string, unknown>, DirectiveLocation | DirectiveLocation[]>> = []> = FieldResolverFn<TParent, TArgs, TResult, TContext> & {
|
|
405
|
+
" $gqlkitResolver"?: {
|
|
406
|
+
kind: "field";
|
|
407
|
+
parent: TParent;
|
|
408
|
+
args: TArgs;
|
|
409
|
+
result: TResult;
|
|
410
|
+
directives: TDirectives;
|
|
411
|
+
};
|
|
412
|
+
};
|
|
413
|
+
/**
|
|
414
|
+
* The API set returned by createGqlkitApis.
|
|
415
|
+
* Contains typed define functions for Query, Mutation, and Field resolvers.
|
|
416
|
+
* @typeParam TContext - The context type for all resolvers in this API set
|
|
417
|
+
*/
|
|
418
|
+
export interface GqlkitApis<TContext> {
|
|
419
|
+
/**
|
|
420
|
+
* Defines a Query field resolver with the specified Context type.
|
|
421
|
+
* @typeParam TArgs - The type of arguments the resolver accepts
|
|
422
|
+
* @typeParam TResult - The return type of the resolver
|
|
423
|
+
* @typeParam TDirectives - Array of directives to attach to this field (defaults to [])
|
|
424
|
+
* @param resolver - The resolver function
|
|
425
|
+
* @returns The resolver with metadata for CLI detection
|
|
426
|
+
*
|
|
427
|
+
* @example
|
|
428
|
+
* ```typescript
|
|
429
|
+
* // Without directives
|
|
430
|
+
* export const users = defineQuery<NoArgs, User[]>(() => []);
|
|
431
|
+
*
|
|
432
|
+
* // With directives
|
|
433
|
+
* export const me = defineQuery<NoArgs, User, [AuthDirective<{ role: ["USER"] }>]>(
|
|
434
|
+
* (root, args, ctx) => ctx.currentUser
|
|
435
|
+
* );
|
|
436
|
+
* ```
|
|
437
|
+
*/
|
|
438
|
+
defineQuery: <TArgs, TResult, TDirectives extends ReadonlyArray<GqlDirective<string, Record<string, unknown>, DirectiveLocation | DirectiveLocation[]>> = []>(resolver: QueryResolverFn<TArgs, TResult, TContext>) => QueryResolver<TArgs, TResult, TContext, TDirectives>;
|
|
439
|
+
/**
|
|
440
|
+
* Defines a Mutation field resolver with the specified Context type.
|
|
441
|
+
* @typeParam TArgs - The type of arguments the resolver accepts
|
|
442
|
+
* @typeParam TResult - The return type of the resolver
|
|
443
|
+
* @typeParam TDirectives - Array of directives to attach to this field (defaults to [])
|
|
444
|
+
* @param resolver - The resolver function
|
|
445
|
+
* @returns The resolver with metadata for CLI detection
|
|
446
|
+
*
|
|
447
|
+
* @example
|
|
448
|
+
* ```typescript
|
|
449
|
+
* // Without directives
|
|
450
|
+
* export const createUser = defineMutation<CreateUserInput, User>((root, args) => ({ ... }));
|
|
451
|
+
*
|
|
452
|
+
* // With directives
|
|
453
|
+
* export const deleteUser = defineMutation<{ id: string }, boolean, [AuthDirective<{ role: ["ADMIN"] }>]>(
|
|
454
|
+
* (root, args, ctx) => true
|
|
455
|
+
* );
|
|
456
|
+
* ```
|
|
457
|
+
*/
|
|
458
|
+
defineMutation: <TArgs, TResult, TDirectives extends ReadonlyArray<GqlDirective<string, Record<string, unknown>, DirectiveLocation | DirectiveLocation[]>> = []>(resolver: MutationResolverFn<TArgs, TResult, TContext>) => MutationResolver<TArgs, TResult, TContext, TDirectives>;
|
|
459
|
+
/**
|
|
460
|
+
* Defines an object type field resolver with the specified Context type.
|
|
461
|
+
* @typeParam TParent - The parent type this field belongs to
|
|
462
|
+
* @typeParam TArgs - The type of arguments the resolver accepts
|
|
463
|
+
* @typeParam TResult - The return type of the resolver
|
|
464
|
+
* @typeParam TDirectives - Array of directives to attach to this field (defaults to [])
|
|
465
|
+
* @param resolver - The resolver function
|
|
466
|
+
* @returns The resolver with metadata for CLI detection
|
|
467
|
+
*
|
|
468
|
+
* @example
|
|
469
|
+
* ```typescript
|
|
470
|
+
* // Without directives
|
|
471
|
+
* export const userPosts = defineField<User, NoArgs, Post[]>((parent) => []);
|
|
472
|
+
*
|
|
473
|
+
* // With directives
|
|
474
|
+
* export const userEmail = defineField<User, NoArgs, string, [AuthDirective<{ role: ["ADMIN"] }>]>(
|
|
475
|
+
* (parent) => parent.email
|
|
476
|
+
* );
|
|
477
|
+
* ```
|
|
478
|
+
*/
|
|
479
|
+
defineField: <TParent, TArgs, TResult, TDirectives extends ReadonlyArray<GqlDirective<string, Record<string, unknown>, DirectiveLocation | DirectiveLocation[]>> = []>(resolver: FieldResolverFn<TParent, TArgs, TResult, TContext>) => FieldResolver<TParent, TArgs, TResult, TContext, TDirectives>;
|
|
480
|
+
/**
|
|
481
|
+
* Defines a resolveType resolver for union or interface types.
|
|
482
|
+
* Used to determine the concrete type of an abstract type at runtime.
|
|
483
|
+
* @typeParam TAbstract - The abstract type (union or interface) to resolve
|
|
484
|
+
* @param resolver - The resolver function that returns the concrete type name
|
|
485
|
+
* @returns The resolver with metadata for CLI detection
|
|
486
|
+
*
|
|
487
|
+
* @example
|
|
488
|
+
* ```typescript
|
|
489
|
+
* type Animal = Dog | Cat;
|
|
490
|
+
*
|
|
491
|
+
* export const animalResolveType = defineResolveType<Animal>((value) => {
|
|
492
|
+
* return value.kind === "dog" ? "Dog" : "Cat";
|
|
493
|
+
* });
|
|
494
|
+
* ```
|
|
495
|
+
*/
|
|
496
|
+
defineResolveType: <TAbstract>(resolver: ResolveTypeResolverFn<TAbstract, TContext>) => ResolveTypeResolver<TAbstract, TContext>;
|
|
497
|
+
/**
|
|
498
|
+
* Defines an isTypeOf resolver for object types.
|
|
499
|
+
* Used to check if a value belongs to a specific object type.
|
|
500
|
+
* @typeParam TObject - The object type to check
|
|
501
|
+
* @param resolver - The resolver function that returns true if the value is of this type
|
|
502
|
+
* @returns The resolver with metadata for CLI detection
|
|
503
|
+
*
|
|
504
|
+
* @example
|
|
505
|
+
* ```typescript
|
|
506
|
+
* export const dogIsTypeOf = defineIsTypeOf<Dog>((value) => {
|
|
507
|
+
* return typeof value === "object" && value !== null && "kind" in value && value.kind === "dog";
|
|
508
|
+
* });
|
|
509
|
+
* ```
|
|
510
|
+
*/
|
|
511
|
+
defineIsTypeOf: <TObject>(resolver: IsTypeOfResolverFn<TContext>) => IsTypeOfResolver<TObject, TContext>;
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* Creates a set of typed define functions for GraphQL resolvers.
|
|
515
|
+
* Use this factory to create API sets with custom Context types.
|
|
516
|
+
*
|
|
517
|
+
* @typeParam TContext - The context type for all resolvers (defaults to unknown)
|
|
518
|
+
* @returns An object containing defineQuery, defineMutation, and defineField functions
|
|
519
|
+
*
|
|
520
|
+
* @example
|
|
521
|
+
* ```typescript
|
|
522
|
+
* type MyContext = { userId: string; db: Database };
|
|
523
|
+
*
|
|
524
|
+
* const { defineQuery, defineMutation, defineField } = createGqlkitApis<MyContext>();
|
|
525
|
+
*
|
|
526
|
+
* export const me = defineQuery<NoArgs, User>(
|
|
527
|
+
* (root, args, ctx, info) => ctx.db.findUser(ctx.userId)
|
|
528
|
+
* );
|
|
529
|
+
* ```
|
|
530
|
+
*
|
|
531
|
+
* @example
|
|
532
|
+
* ```typescript
|
|
533
|
+
* // Multiple schemas with different contexts
|
|
534
|
+
* type AdminContext = { adminId: string };
|
|
535
|
+
* type PublicContext = { sessionId: string };
|
|
536
|
+
*
|
|
537
|
+
* const adminApis = createGqlkitApis<AdminContext>();
|
|
538
|
+
* const publicApis = createGqlkitApis<PublicContext>();
|
|
539
|
+
* ```
|
|
540
|
+
*/
|
|
541
|
+
export declare function createGqlkitApis<TContext = unknown>(): GqlkitApis<TContext>;
|
|
542
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GACzB,QAAQ,GACR,QAAQ,GACR,QAAQ,GACR,kBAAkB,GAClB,qBAAqB,GACrB,WAAW,GACX,OAAO,GACP,MAAM,GACN,YAAY,GACZ,cAAc,GACd,wBAAwB,CAAC;AAE7B;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,YAAY,CACtB,IAAI,SAAS,MAAM,EACnB,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,OA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ACnC,gBAAgB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;CAC1C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,GAAG,OAAO,KAAK,UAAU,CAAC,QAAQ,CAAC,CA2B3E"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a set of typed define functions for GraphQL resolvers.
|
|
3
|
+
* Use this factory to create API sets with custom Context types.
|
|
4
|
+
*
|
|
5
|
+
* @typeParam TContext - The context type for all resolvers (defaults to unknown)
|
|
6
|
+
* @returns An object containing defineQuery, defineMutation, and defineField functions
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* type MyContext = { userId: string; db: Database };
|
|
11
|
+
*
|
|
12
|
+
* const { defineQuery, defineMutation, defineField } = createGqlkitApis<MyContext>();
|
|
13
|
+
*
|
|
14
|
+
* export const me = defineQuery<NoArgs, User>(
|
|
15
|
+
* (root, args, ctx, info) => ctx.db.findUser(ctx.userId)
|
|
16
|
+
* );
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* // Multiple schemas with different contexts
|
|
22
|
+
* type AdminContext = { adminId: string };
|
|
23
|
+
* type PublicContext = { sessionId: string };
|
|
24
|
+
*
|
|
25
|
+
* const adminApis = createGqlkitApis<AdminContext>();
|
|
26
|
+
* const publicApis = createGqlkitApis<PublicContext>();
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export function createGqlkitApis() {
|
|
30
|
+
const apis = {
|
|
31
|
+
defineQuery: (resolver) => {
|
|
32
|
+
return resolver;
|
|
33
|
+
},
|
|
34
|
+
defineMutation: (resolver) => {
|
|
35
|
+
return resolver;
|
|
36
|
+
},
|
|
37
|
+
defineField: (resolver) => {
|
|
38
|
+
return resolver;
|
|
39
|
+
},
|
|
40
|
+
defineResolveType: (resolver) => {
|
|
41
|
+
return resolver;
|
|
42
|
+
},
|
|
43
|
+
defineIsTypeOf: (resolver) => {
|
|
44
|
+
return resolver;
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
return apis;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAosBA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,gBAAgB;IAC9B,MAAM,IAAI,GAAG;QACX,WAAW,EAAE,CACX,QAAmD,EACnD,EAAE;YACF,OAAO,QAAQ,CAAC;QAClB,CAAC;QACD,cAAc,EAAE,CACd,QAAsD,EACtD,EAAE;YACF,OAAO,QAAQ,CAAC;QAClB,CAAC;QACD,WAAW,EAAE,CACX,QAA4D,EAC5D,EAAE;YACF,OAAO,QAAQ,CAAC;QAClB,CAAC;QACD,iBAAiB,EAAE,CACjB,QAAoD,EACpD,EAAE;YACF,OAAO,QAAQ,CAAC;QAClB,CAAC;QACD,cAAc,EAAE,CAAC,QAAsC,EAAE,EAAE;YACzD,OAAO,QAAQ,CAAC;QAClB,CAAC;KACF,CAAC;IACF,OAAO,IAAuC,CAAC;AACjD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gqlkit-ts/runtime",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Runtime utilities for gqlkit - type-safe resolver definition functions",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
5
17
|
"keywords": [
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
]
|
|
10
|
-
|
|
18
|
+
"graphql",
|
|
19
|
+
"resolver",
|
|
20
|
+
"typescript"
|
|
21
|
+
],
|
|
22
|
+
"author": "izumin5210 <m@izum.in>",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "https://github.com/izumin5210/gqlkit.git",
|
|
27
|
+
"directory": "packages/runtime"
|
|
28
|
+
},
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/izumin5210/gqlkit/issues"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://gqlkit.izumin.dev",
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc --build",
|
|
38
|
+
"test": "pnpm -w vitest run --project=runtime --typecheck",
|
|
39
|
+
"typecheck": "tsc --noEmit"
|
|
40
|
+
}
|
|
41
|
+
}
|
package/README.md
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
# @gqlkit-ts/runtime
|
|
2
|
-
|
|
3
|
-
## ⚠️ IMPORTANT NOTICE ⚠️
|
|
4
|
-
|
|
5
|
-
**This package is created solely for the purpose of setting up OIDC (OpenID Connect) trusted publishing with npm.**
|
|
6
|
-
|
|
7
|
-
This is **NOT** a functional package and contains **NO** code or functionality beyond the OIDC setup configuration.
|
|
8
|
-
|
|
9
|
-
## Purpose
|
|
10
|
-
|
|
11
|
-
This package exists to:
|
|
12
|
-
1. Configure OIDC trusted publishing for the package name `@gqlkit-ts/runtime`
|
|
13
|
-
2. Enable secure, token-less publishing from CI/CD workflows
|
|
14
|
-
3. Establish provenance for packages published under this name
|
|
15
|
-
|
|
16
|
-
## What is OIDC Trusted Publishing?
|
|
17
|
-
|
|
18
|
-
OIDC trusted publishing allows package maintainers to publish packages directly from their CI/CD workflows without needing to manage npm access tokens. Instead, it uses OpenID Connect to establish trust between the CI/CD provider (like GitHub Actions) and npm.
|
|
19
|
-
|
|
20
|
-
## Setup Instructions
|
|
21
|
-
|
|
22
|
-
To properly configure OIDC trusted publishing for this package:
|
|
23
|
-
|
|
24
|
-
1. Go to [npmjs.com](https://www.npmjs.com/) and navigate to your package settings
|
|
25
|
-
2. Configure the trusted publisher (e.g., GitHub Actions)
|
|
26
|
-
3. Specify the repository and workflow that should be allowed to publish
|
|
27
|
-
4. Use the configured workflow to publish your actual package
|
|
28
|
-
|
|
29
|
-
## DO NOT USE THIS PACKAGE
|
|
30
|
-
|
|
31
|
-
This package is a placeholder for OIDC configuration only. It:
|
|
32
|
-
- Contains no executable code
|
|
33
|
-
- Provides no functionality
|
|
34
|
-
- Should not be installed as a dependency
|
|
35
|
-
- Exists only for administrative purposes
|
|
36
|
-
|
|
37
|
-
## More Information
|
|
38
|
-
|
|
39
|
-
For more details about npm's trusted publishing feature, see:
|
|
40
|
-
- [npm Trusted Publishing Documentation](https://docs.npmjs.com/generating-provenance-statements)
|
|
41
|
-
- [GitHub Actions OIDC Documentation](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect)
|
|
42
|
-
|
|
43
|
-
---
|
|
44
|
-
|
|
45
|
-
**Maintained for OIDC setup purposes only**
|