Skip to content

Instantly share code, notes, and snippets.

@luandevpro
Created June 21, 2019 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luandevpro/808437cefc196f3c528e2ce53b92da1f to your computer and use it in GitHub Desktop.
Save luandevpro/808437cefc196f3c528e2ce53b92da1f to your computer and use it in GitHub Desktop.
import React from 'react';
import gql from 'graphql-tag';
import { useQuery } from 'react-apollo-hooks';
import withAuth from '../lib/withAuth';
const getPosts = gql`
query getPosts($user_id: String!) {
post(where: { user_id: { _eq: $user_id } }) {
id
title
description
created_at
user {
id
displayName
email
}
}
}
`;
function Post({ token }) {
const { data, loading } = useQuery(getPosts, {
variables: {
user_id: token && token['https://hasura.io/jwt/claims']['x-hasura-user-id'],
},
});
if (!token) return <div>Loading ...</div>;
if (loading) {
return <div>Loading...</div>;
}
console.log(token);
console.log({ data });
return (
<ul>
{data.post.map(post => (
<div key={post.created_at}>
<h1>{post.title}</h1>
<p>{post.description}</p>
</div>
))}
</ul>
);
}
export default withAuth(Post);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment