You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -257,7 +289,7 @@ The server preset handles all resolver types and imports. So, you only need to i
257
289
258
290
This means instead of updating the `codegen.ts` config file, you make changes in each module. This keeps the GraphQL API maintainable at any scale.
259
291
260
-
Read more about this concept on our blog: [Scalability APIs with GraphQL Server Codegen Preset](https://the-guild.dev/blog/scalable-apis-with-graphql-server-codegen-preset)
292
+
Read more about this concept on our blog: [Scalable APIs with GraphQL Server Codegen Preset](https://the-guild.dev/blog/scalable-apis-with-graphql-server-codegen-preset)
261
293
262
294
</Callout>
263
295
@@ -322,22 +354,24 @@ Furthermore, the type is updated to use the recommended type from `graphql-scala
322
354
// ... other generated types
323
355
324
356
exporttypeScalars= {
325
-
ID:string
326
-
String:string
327
-
Boolean:boolean
328
-
Int:number
329
-
Float:number
330
-
DateTime:Date|string// Type comes from graphql-scalars
357
+
ID:{ input:string; output:string|number }
358
+
String:{ input:string; output:string }
359
+
Boolean:{ input:boolean; output:boolean }
360
+
Int:{ input:number; output:number }
361
+
Float:{ input:number; output:number }
362
+
DateTime:{ input:Date|string; output:Date|string }// Type comes from graphql-scalars
331
363
}
332
364
333
365
// ... other generated types
334
366
```
335
367
336
368
The type of any custom scalar is `any` by default. Without the server preset, you have to configure the `DateTime` type by manually updating `codegen.ts`.
337
369
338
-
#### Adding Mappers
370
+
#### Adding Mappers To Chain Resolvers
371
+
372
+
By default, the generated types make resolvers return objects that match the schema types. However, this means we must handle all field mapping in the root-level resolvers.
339
373
340
-
Mappers allow returning a different object interface in the resolvers. Object type's field resolvers are used to return the final value to clients.
374
+
This is where we can use [mappers](https://the-guild.dev/graphql/codegen/plugins/typescript/typescript-resolvers#use-your-model-types-mappers) to enable resolver chaining. When a mapper is used this way, it can be returned in one resolver, and become the `parent` argument in the next resolver in the chain.
341
375
342
376
With the server preset, you can add mappers by exporting interfaces or types with `Mapper` suffix from `*.mappers.ts` files in appropriate modules:
343
377
@@ -374,11 +408,11 @@ export type ResolversParentTypes = {
0 commit comments