@@ -6,7 +6,7 @@ import { GraphRsc } from "@effect-app-boilerplate/resources"
66import type { GraphMutationResponse } from "@effect-app-boilerplate/resources/Graph/Mutation"
77import type { GraphQueryRequest , GraphQueryResponse } from "@effect-app-boilerplate/resources/Graph/Query"
88import { dropUndefined } from "@effect-app/core/utils"
9- import { makeRequestId , RequestContext } from "@effect-app/infra/RequestContext"
9+ import { RequestContext , RequestId } from "@effect-app/infra/RequestContext"
1010import { RequestContextContainer } from "@effect-app/infra/services/RequestContextContainer"
1111import type { CTX } from "api/lib/routing.js"
1212import BlogControllers from "./Blog.Controllers.js"
@@ -25,24 +25,26 @@ function request<Key extends string>(
2525 ) => {
2626 const q = req [ name ]
2727 return q
28- ? Effect . gen ( function * ( $ ) {
29- yield * $ ( RequestContextContainer . flatMap ( _ =>
30- _ . update ( ctx =>
31- RequestContext . inherit ( ctx , {
32- id : makeRequestId ( ) ,
33- locale : ctx . locale ,
34- name : ReasonableString ( name ) // TODO: Use name from handler.Request
35- } )
36- )
37- ) )
28+ ? Effect
29+ . gen ( function * ( $ ) {
30+ yield * $ ( RequestContextContainer . flatMap ( ( _ ) =>
31+ _ . update ( ( ctx ) =>
32+ RequestContext . inherit ( ctx , {
33+ id : RequestId . make ( ) ,
34+ locale : ctx . locale ,
35+ name : ReasonableString ( name ) // TODO: Use name from handler.Request
36+ } )
37+ )
38+ ) )
3839
39- const ctx = yield * $ ( RequestContextContainer . get )
40+ const ctx = yield * $ ( RequestContextContainer . get )
4041
41- const r = yield * $ (
42- handler ( q . input ?? { } , { ...context , context : ctx } )
43- )
44- return r
45- } ) [ "|>" ] ( Effect . either )
42+ const r = yield * $ (
43+ handler ( q . input ?? { } , { ...context , context : ctx } )
44+ )
45+ return r
46+ } )
47+ [ "|>" ] ( Effect . either )
4648 : NoResponse
4749 }
4850}
@@ -89,17 +91,20 @@ function mutation<Key extends string>(
8991 resultQuery ?: ( inp : A , ctx : CTX ) => Effect < R2 , E2 , A2 >
9092 ) => {
9193 const q = req [ name ]
92- return f ( name , handler ) . flatMap ( x =>
94+ return f ( name , handler ) . flatMap ( ( x ) =>
9395 ! x
9496 ? Effect ( x )
9597 : x . isLeft ( )
96- ? Effect ( x )
98+ ? Effect ( Either . left ( x . left ) )
9799 : ( q ?. query
98- ? Effect . allPar ( {
99- query : Query . flatMap ( _ => _ ( q . query ! , ctx ) ) ,
100- result : resultQuery ? resultQuery ( x . right , ctx ) : emptyResponse
101- } ) . map ( ( { query, result } ) => ( { ...query , result } ) ) // TODO: Replace $ variables in the query parameters baed on mutation output!
102- : emptyResponse ) . map ( query => Either ( query ? { query, response : x . right } : { response : x . right } ) )
100+ ? Effect
101+ . allPar ( {
102+ query : Query . flatMap ( ( _ ) => _ ( q . query ! , ctx ) ) ,
103+ result : resultQuery ? resultQuery ( x . right , ctx ) : emptyResponse
104+ } )
105+ . map ( ( { query, result } ) => ( { ...query , result } ) ) // TODO: Replace $ variables in the query parameters baed on mutation output!
106+ : emptyResponse )
107+ . map ( ( query ) => Either ( query ? { query, response : x . right } : { response : x . right } ) )
103108 )
104109 }
105110}
@@ -116,8 +121,10 @@ const Mutation = graph.matchMutation.withEffect(
116121 "CreatePost" ,
117122 blogPostControllers . CreatePost . h ,
118123 ( id , ctx ) =>
119- blogPostControllers . FindPost . h ( { id } , ctx )
120- . flatMap ( x => ( ! x ? Effect . die ( "Post went away?" ) : Effect ( x ) ) )
124+ blogPostControllers
125+ . FindPost
126+ . h ( { id } , ctx )
127+ . flatMap ( ( x ) => ( ! x ? Effect . die ( "Post went away?" ) : Effect ( x ) ) )
121128 )
122129 // UpdatePurchaseOrder: handle("UpdatePurchaseOrder", UpdatePurchaseOrder.h, () =>
123130 // FindPurchaseOrder.h(req.UpdatePurchaseOrder!.input).flatMap(x =>
0 commit comments