(postId: number)
| 117 | } |
| 118 | |
| 119 | function usePost(postId: number) { |
| 120 | return useQuery({ |
| 121 | queryKey: ['post', postId], |
| 122 | queryFn: async () => { |
| 123 | const { post } = await request<{ post: Post }>( |
| 124 | endpoint, |
| 125 | gql` |
| 126 | query { |
| 127 | post(id: ${postId}) { |
| 128 | id |
| 129 | title |
| 130 | body |
| 131 | } |
| 132 | } |
| 133 | `, |
| 134 | ) |
| 135 | |
| 136 | return post |
| 137 | }, |
| 138 | enabled: !!postId, |
| 139 | }) |
| 140 | } |
| 141 | |
| 142 | function Post({ |
| 143 | postId, |