2021-08-07 19:56:39 +07:00
|
|
|
import React from 'react';
|
2021-08-08 19:08:10 +07:00
|
|
|
import './App.less';
|
2021-08-07 19:56:39 +07:00
|
|
|
import {gql, useQuery, useSubscription} from "@apollo/client";
|
2021-08-08 19:48:50 +07:00
|
|
|
import { Table } from 'antd';
|
2021-08-07 19:56:39 +07:00
|
|
|
|
|
|
|
interface User {
|
|
|
|
id: number
|
|
|
|
code: string
|
|
|
|
name: string
|
|
|
|
}
|
|
|
|
|
|
|
|
interface Account {
|
|
|
|
id: number
|
|
|
|
code: string
|
|
|
|
balance: number
|
|
|
|
user: User
|
|
|
|
}
|
|
|
|
|
|
|
|
interface AccountResult {
|
|
|
|
fetchAccounts: Array<Account>
|
|
|
|
}
|
|
|
|
|
|
|
|
const ACCOUNTS = gql`
|
|
|
|
{
|
|
|
|
fetchAccounts {
|
|
|
|
id
|
|
|
|
code
|
|
|
|
balance
|
|
|
|
user {
|
|
|
|
code
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
2021-08-08 19:48:50 +07:00
|
|
|
const SUB_ACCOUNTS = gql`
|
|
|
|
subscription {
|
|
|
|
fetchAccounts {
|
|
|
|
id
|
|
|
|
code
|
|
|
|
balance
|
|
|
|
user {
|
|
|
|
code
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
2021-08-07 19:56:39 +07:00
|
|
|
const HELLO = gql`
|
|
|
|
subscription {
|
|
|
|
hello
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
2021-08-08 19:48:50 +07:00
|
|
|
const accountColumns = [
|
|
|
|
{
|
|
|
|
title: "Account ID",
|
|
|
|
dataIndex: "id",
|
|
|
|
key: "id",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "Account Code",
|
|
|
|
dataIndex: "code",
|
|
|
|
key: "code",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "User",
|
|
|
|
dataIndex: ["user", "name"],
|
|
|
|
key: "user.name",
|
|
|
|
}
|
|
|
|
]
|
2021-08-07 19:56:39 +07:00
|
|
|
function App() {
|
2021-08-08 19:48:50 +07:00
|
|
|
// const {error, loading, data} = useQuery<AccountResult>(ACCOUNTS)
|
|
|
|
const {error, loading, data} = useSubscription<AccountResult>(SUB_ACCOUNTS)
|
2021-08-08 18:55:52 +07:00
|
|
|
// const {error, loading, data} = useSubscription(HELLO)
|
2021-08-08 11:00:39 +07:00
|
|
|
console.log(data)
|
2021-08-07 19:56:39 +07:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<h1>Accounts</h1>
|
|
|
|
{
|
|
|
|
loading || !data ? <p>Loading...</p> :
|
2021-08-08 19:48:50 +07:00
|
|
|
// data.fetchAccounts.map(account => (
|
|
|
|
// <>
|
|
|
|
// <div>Account ID: {account.id}</div>
|
|
|
|
// <div>Account Code: {account.code}</div>
|
|
|
|
// <div>Account User: {account.user.name}</div>
|
|
|
|
// </>
|
|
|
|
// )
|
|
|
|
// )
|
|
|
|
<Table dataSource={data.fetchAccounts} columns={accountColumns}/>
|
2021-08-08 18:55:52 +07:00
|
|
|
// <p>{`${data.hello}`}</p>
|
2021-08-07 19:56:39 +07:00
|
|
|
}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default App;
|