markdown 阿波罗查询打字稿
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 阿波罗查询打字稿相关的知识,希望对你有一定的参考价值。
[official](https://www.apollographql.com/docs/react/recipes/static-typing.html)
official doc has bug about using 'props' function
which can be solved by [this](https://github.com/apollographql/react-apollo/issues/2568)
---
# define type(interface)
used **commonly** on both cases (HOC and Component styles)
```tsx
import { ChildDataProps, graphql, Query } from 'react-apollo'
type Rite = {
...
}
type Response = {
rites: Rite[];
};
type Variables = {
personId: string;
};
```
---
# 1. HOC style
```tsx
type InputProps = {
personId: string,
}
type ChildProps = ChildDataProps<InputProps, Response, Variables>;
const withRitesByPerson = graphql<InputProps, Response, Variables, ChildProps>(RITES_QUERY, {
options: ({ personId }) => ({
variables: { personId },
fetchPolicy: 'cache-and-network'
})
});
const PersonalRitesQuery = withRitesByPerson(({ data: { loading, rites, error } }) => {
if (error) return <div>Error {JSON.stringify(error)}</div>
return (<div>
{loading && <div>Fetching</div>}
{rites && <PersonalRitesTable rites={rites} />}
</div>)
})
```
less readable but easy to use as HOC later?
hard to use 'state'
# 2. Component style
```tsx
class AllPeopleQuery extends Query<Response, Variables> { }
class PersonalRitesQuery extends React.Component<{ personId: string }> {
render() {
const { personId } = this.props
return (
<AllPeopleQuery
query={RITES_QUERY}
variables={{ personId: personId }}
fetchPolicy={'cache-and-network'}
>
{({ loading, error, data, refetch, networkStatus }) => {
if (error) return <div>Error {JSON.stringify(error)}</div>
return (<div>
{loading && <div>Fetching</div>}
{data && data.rites && <PersonalRitesTable rites={data.rites} />}
</div>)
}}
</AllPeopleQuery>
)
}
}
```
more readable
以上是关于markdown 阿波罗查询打字稿的主要内容,如果未能解决你的问题,请参考以下文章
阿波罗联邦打字稿解析器参数
在nestjs应用程序中使用新的阿波罗服务器版本的打字稿错误
markdown 打字稿界面类型
markdown withRouter打字稿
markdown 打字稿tsx
markdown 开玩笑,打字稿