Created
April 30, 2020 20:30
-
-
Save a7v8x/cc284acb829487ba10fbf58c1b7018df to your computer and use it in GitHub Desktop.
TypeScript Apollo component with codegen https://atheros.ai/blog/generate-javascript-static-types-from-graphql-typescript-and-flow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mport React from 'react'; | |
import get from 'lodash.get'; | |
import uuid from 'uuid/v1'; | |
import { useQuery } from '@apollo/react-hooks'; | |
import SUBSCRIPTIONS_QUERY from './SUBSCRIPTIONS.graphql'; | |
import { SubscriptionsQuery, SubscriptionsQueryVariables } from '../../../__generated__/typescript-operations'; | |
import s from './SubscriptionsTable.scss'; | |
const SubscriptionsTable: React.FunctionComponent = () => { | |
const { data, loading, error } = useQuery<SubscriptionsQuery, | |
SubscriptionsQueryVariables>(SUBSCRIPTIONS_QUERY); | |
if (loading) return <>Loading...</>; | |
if (error) return <>{`Error! ${error.message}`}</>; | |
return ( | |
<div className={s.SubscriptionTable}> | |
<table> | |
<thead> | |
<tr> | |
<th>Email</th> | |
<th>Source</th> | |
</tr> | |
</thead> | |
<tbody> | |
{data && data.subscriptions && data.subscriptions.map((subscription) => ( | |
<tr key={get(subscription, 'id', uuid())}> | |
<td> | |
{get(subscription, 'email')} | |
</td> | |
<td> | |
{get(subscription, 'source')} | |
</td> | |
</tr> | |
))} | |
</tbody> | |
</table> | |
</div> | |
); | |
}; | |
export default SubscriptionsTable; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment