Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: read query container #706

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
@@ -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}
10 changes: 10 additions & 0 deletions src/container/Home/index.tsx
Original file line number Diff line number Diff line change
@@ -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>
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
@@ -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>