@fougere/adapter-graphql 0.2.0-alpha.2

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.
@@ -0,0 +1,177 @@
1
+ /**
2
+ * @fougere/adapter-graphql — génère des types Pothos depuis les entités fougere
3
+ */
4
+ import type SchemaBuilder from '@pothos/core';
5
+ import type { SchemaView, SchemaSource } from '@fougere/schema';
6
+ type EntityClass = SchemaView & (abstract new (...args: any[]) => any);
7
+ /** Presenter instance — each method is a computed field resolver. */
8
+ type PresenterInstance = Record<string, (parent: any) => any>;
9
+ export interface TypeConfig {
10
+ /** Nom du type GraphQL */
11
+ name: string;
12
+ /** Entity source */
13
+ /** The schema whose fields become the type — a live class, or a card that travelled. */
14
+ entity: SchemaSource;
15
+ /** Champs à exclure du type GraphQL */
16
+ exclude?: string[];
17
+ /** Relations à résoudre */
18
+ relations?: Record<string, RelationConfig>;
19
+ /** Presenter instance — adds computed fields as resolveFields on this type. */
20
+ presenter?: PresenterInstance;
21
+ /** Presenter field names (methods to expose). If absent, all methods are exposed. */
22
+ presenterFields?: string[];
23
+ /** Per-field type metadata from source parsing. */
24
+ presenterFieldMeta?: {
25
+ name: string;
26
+ returnType?: string;
27
+ list?: boolean;
28
+ nullable?: boolean;
29
+ }[];
30
+ /**
31
+ * The view a computed field emits, when the presenter declared one — the object type
32
+ * to build for it. Without a declaration the scan reads a scalar or nothing, and an
33
+ * object-valued field can only be serialized.
34
+ */
35
+ presenterViews?: Record<string, EntityClass | [EntityClass]>;
36
+ /** Builds (or reuses) the GraphQL object type for a declared view. */
37
+ viewType?: (view: EntityClass, fieldName: string) => any;
38
+ }
39
+ export interface RelationConfig {
40
+ /** Type GraphQL cible (retourné par registerType) */
41
+ type: any;
42
+ /** Est-ce une liste ? */
43
+ list?: boolean;
44
+ /** Résolveur personnalisé */
45
+ resolve: (parent: any) => any;
46
+ }
47
+ export interface InputConfig {
48
+ /** Nom de l'input GraphQL */
49
+ name: string;
50
+ /** SchemaView source (résultat de pick/omit/partial) */
51
+ schema: SchemaView;
52
+ }
53
+ /** Parsed method signature (mirrors core OperationMeta.signature). */
54
+ interface ParsedSignature {
55
+ name: string;
56
+ params: {
57
+ name: string;
58
+ type: {
59
+ raw: string;
60
+ name: string;
61
+ array?: boolean;
62
+ nullable?: boolean;
63
+ generics?: ParsedSignature['params'][0]['type'][];
64
+ };
65
+ optional?: boolean;
66
+ }[];
67
+ returnType?: {
68
+ raw: string;
69
+ name: string;
70
+ array?: boolean;
71
+ nullable?: boolean;
72
+ generics?: ParsedSignature['params'][0]['type'][];
73
+ };
74
+ }
75
+ /** Metadata for a handler operation (from scanner). */
76
+ interface OperationMeta {
77
+ input?: SchemaView;
78
+ output?: SchemaView;
79
+ signature?: ParsedSignature;
80
+ /**
81
+ * The operation in words. It reaches here already — `handler.operations` is core's
82
+ * `Map<string, OperationContract>`, and this narrowed view simply did not name the
83
+ * field, so an explorer showed every field undocumented while the sentence sat one
84
+ * property away.
85
+ */
86
+ description?: string;
87
+ }
88
+ export interface OperationsConfig {
89
+ /** Entity name (PascalCase). */
90
+ name: string;
91
+ /** GraphQL entity type ref (from registerType). */
92
+ type: any;
93
+ /** Handler facade — each op receives InvocationContext. */
94
+ facade: Record<string, Function>;
95
+ /** Operations metadata from scanner (signature + resolved schemas). */
96
+ operations: Map<string, OperationMeta>;
97
+ /** Per-op kind overrides from frond.config.ts (optional). */
98
+ operationsOverrides?: Record<string, {
99
+ kind?: 'query' | 'command';
100
+ }>;
101
+ /**
102
+ * The GraphQL type for a schema an operation declares as its return. The caller owns
103
+ * this because it alone knows whether the schema IS the entity's (then: the type
104
+ * already registered) or something else (then: a new named type).
105
+ */
106
+ viewType?: (view: SchemaView, opName: string) => any;
107
+ }
108
+ type ScalarName = 'string' | 'int' | 'float' | 'boolean';
109
+ /** Declarative field definition for registerObjectType. */
110
+ export interface ObjectFieldDef {
111
+ /** Scalar name ('string', 'int', 'float', 'boolean') or Pothos type ref. Use [ref] for lists. */
112
+ type: ScalarName | any;
113
+ nullable?: boolean;
114
+ /** Custom resolver. Defaults to `(parent) => parent[fieldName]`. */
115
+ resolve?: (parent: any) => any;
116
+ }
117
+ /**
118
+ * Register a GraphQL object type from a declarative field map.
119
+ *
120
+ * Each field auto-resolves from `parent[key]` unless a custom `resolve` is provided.
121
+ * Works for wrapper types, result types, or any structural type.
122
+ *
123
+ * ```ts
124
+ * const PostList = registerObjectType(builder, 'PostList', {
125
+ * items: { type: [PostType] },
126
+ * total: { type: 'int', nullable: true, resolve: async (p) => lazyCount(p) },
127
+ * hasMore: { type: 'boolean', nullable: true },
128
+ * endCursor: { type: 'string', nullable: true },
129
+ * });
130
+ * ```
131
+ */
132
+ export declare function registerObjectType(builder: InstanceType<typeof SchemaBuilder>, name: string, fieldDefs: Record<string, ObjectFieldDef>): any;
133
+ /**
134
+ * Enregistre un type GraphQL (lecture) depuis une entité fougere.
135
+ *
136
+ * ```ts
137
+ * const ProductType = registerType(builder, {
138
+ * name: 'Product',
139
+ * entity: Product,
140
+ * exclude: ['categoryId'],
141
+ * relations: {
142
+ * category: {
143
+ * type: CategoryType,
144
+ * resolve: (parent) => db.select()...
145
+ * },
146
+ * },
147
+ * });
148
+ * ```
149
+ */
150
+ export declare function registerType(builder: InstanceType<typeof SchemaBuilder>, config: TypeConfig): any;
151
+ /**
152
+ * Enregistre un input GraphQL (écriture) depuis un SchemaView.
153
+ *
154
+ * ```ts
155
+ * const CreateProductInput = registerInput(builder, {
156
+ * name: 'CreateProductInput',
157
+ * schema: CreateProduct,
158
+ * });
159
+ * ```
160
+ */
161
+ export declare function registerInput(builder: InstanceType<typeof SchemaBuilder>, config: InputConfig): any;
162
+ /**
163
+ * Register all GraphQL operations for an entity from parsed handler signatures.
164
+ *
165
+ * Each operation in the map is registered as a Query or Mutation field
166
+ * based on naming convention (list*, find*, get*, search* → Query, else → Mutation).
167
+ *
168
+ * Args are generated from the parsed method signature:
169
+ * - Primitives (string, number) → scalar args
170
+ * - Entity/object params → input types (derived from meta.input)
171
+ * - Partial<T> wrapper → all input fields nullable
172
+ * - ListOptions → standard pagination args
173
+ * - InvocationContext → skipped (injected by resolver)
174
+ */
175
+ export declare function registerOperations(builder: InstanceType<typeof SchemaBuilder>, config: OperationsConfig): void;
176
+ export {};
177
+ //# sourceMappingURL=pothos.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pothos.d.ts","sourceRoot":"","sources":["../src/pothos.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,aAAa,MAAM,cAAc,CAAC;AAE9C,OAAO,KAAK,EAAiB,UAAU,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAK/E,KAAK,WAAW,GAAG,UAAU,GAAG,CAAC,QAAQ,MAAM,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC,CAAC;AAEvE,qEAAqE;AACrE,KAAK,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,GAAG,CAAC,CAAC;AAE9D,MAAM,WAAW,UAAU;IACzB,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,oBAAoB;IACpB,wFAAwF;IACxF,MAAM,EAAE,YAAY,CAAC;IACrB,uCAAuC;IACvC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,2BAA2B;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAC3C,+EAA+E;IAC/E,SAAS,CAAC,EAAE,iBAAiB,CAAC;IAC9B,qFAAqF;IACrF,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,mDAAmD;IACnD,kBAAkB,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,EAAE,CAAC;IACjG;;;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