Skip to content

Commit

Permalink
Leverage graph
Browse files Browse the repository at this point in the history
  • Loading branch information
patroza committed Feb 7, 2023
1 parent 12cf05f commit 9953376
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions _project/frontend-nuxt/pages/blog/index.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
<script setup lang="ts">
import { BlogRsc } from "@effect-app-boilerplate/resources"
import { BlogRsc, GraphRsc } from "@effect-app-boilerplate/resources"
const blogClient = clientFor(BlogRsc)
const graphClient = clientFor(GraphRsc)
const [, createPost_] = useMutation(blogClient.createPost)
const [, latestPosts, reloadPosts] = useSafeQuery(blogClient.getPosts)
const [, mutate] = useMutation(graphClient.mutation)
const [, latestPosts, reloadPosts, { mutate: mutatePosts }] = useSafeQuery(
blogClient.getPosts
)
const createPost = flow(createPost_, _ => _.then(_ => reloadPosts()))
const createPost = (input: BlogRsc.CreatePost.CreatePostRequest) =>
pipe(mutate({ CreatePost: { input, query: { result: true } } }), _ =>
_.then(_ => {
const r = _["|>"](Either.flatMap(_ => _.body.CreatePost!))["|>"](
Either.map(_ => _.query!.result!)
)
if (r._tag === "Right") {
const items = latestPosts.value!.items
mutatePosts(() => Promise.resolve({ items: [...items, r.right] }))
}
})
)
</script>

<template>
Expand Down

0 comments on commit 9953376

Please sign in to comment.