Skip to content

Commit

Permalink
Leverage graph
Browse files Browse the repository at this point in the history
  • Loading branch information
patroza committed Feb 11, 2023
1 parent 4be1551 commit de3a23e
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 de3a23e

Please sign in to comment.