Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/components/Todos/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ export const Todos: React.VFC<Props> = ({ todos, isLoading, getContent }) => {
console.log(isLoading, new Date())
return (
<Card title="TODO List" style={{ margin: '5%' }}>
<Button onClick={getContent}>データを取る</Button>
<Divider />
{getContent && (
<>
<Button onClick={getContent}>データを取る</Button>
<Divider />
</>
)}
<List
loading={isLoading}
dataSource={todos}
Expand Down
10 changes: 10 additions & 0 deletions src/container/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ export const HomeContainer = () => {
<Typography.Link href={`/${policy}`}>{policy}</Typography.Link>
</li>
))}
<li key="read-query-network-only">
<Typography.Link href="/read-query-network-only">
Read Query after network-only
</Typography.Link>
</li>
<li key="read-query-no-cache">
<Typography.Link href="/read-query-no-cache">
Read Query after no-cache
</Typography.Link>
</li>
</ul>
</Card>
</Wrapper>
Expand Down
15 changes: 15 additions & 0 deletions src/container/Todos/read.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react'
import { WatchQueryFetchPolicy } from '@apollo/client'

import { Todos } from 'components/Todos'
import { useTodosQuery, TodosDocument } from 'graphql/api'
import { client } from 'apolloClient'

export const TodosReadContainer: React.FC<{
fetchPolicy: WatchQueryFetchPolicy
}> = ({ fetchPolicy }) => {
useTodosQuery({ fetchPolicy })
const data = client.readQuery({ query: TodosDocument })

return <Todos todos={data?.todos} />
}
11 changes: 11 additions & 0 deletions src/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,21 @@ import { BrowserRouter, Route, Switch } from 'react-router-dom'
import { HomeContainer } from './container/Home'

import { TodosContainer } from 'container/Todos'
import { TodosReadContainer } from 'container/Todos/read'

export const Routes = () => (
<BrowserRouter>
<Switch>
<Route
component={() => <TodosReadContainer fetchPolicy="network-only" />}
path="/read-query-network-only"
exact
/>
<Route
component={() => <TodosReadContainer fetchPolicy="no-cache" />}
path="/read-query-no-cache"
exact
/>
<Route component={HomeContainer} path="/" exact />
<Route component={() => <TodosContainer />} path="/:fetchPolicy" exact />
</Switch>
Expand Down