Skip to content

Commit 67a3cc3

Browse files
committed
Leverage graph
1 parent 3c9d063 commit 67a3cc3

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

_project/frontend-nuxt/pages/blog/index.vue

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
<script setup lang="ts">
2-
import { BlogRsc } from "@effect-app-boilerplate/resources"
2+
import { BlogRsc, GraphRsc } from "@effect-app-boilerplate/resources"
33
44
const blogClient = clientFor(BlogRsc)
5+
const graphClient = clientFor(GraphRsc)
56
6-
const [, createPost_] = useMutation(blogClient.createPost)
7-
const [, latestPosts, reloadPosts] = useSafeQuery(blogClient.getPosts)
7+
const [, mutate] = useMutation(graphClient.mutation)
8+
const [, latestPosts, reloadPosts, { mutate: mutatePosts }] = useSafeQuery(
9+
blogClient.getPosts
10+
)
811
9-
const createPost = flow(createPost_, _ => _.then(_ => reloadPosts()))
12+
const createPost = (input: BlogRsc.CreatePost.CreatePostRequest) =>
13+
pipe(mutate({ CreatePost: { input, query: { result: true } } }), _ =>
14+
_.then(_ => {
15+
const r = _["|>"](Either.flatMap(_ => _.body.CreatePost!))["|>"](
16+
Either.map(_ => _.query!.result!)
17+
)
18+
if (r._tag === "Right") {
19+
const items = latestPosts.value!.items
20+
mutatePosts(() => Promise.resolve({ items: [...items, r.right] }))
21+
}
22+
})
23+
)
1024
</script>
1125

1226
<template>

0 commit comments

Comments
 (0)