任何人都知道在突变期间如何处理这种错误?
在这里发生:
const RepositoryItem = ({ repository, selectedRepositoryIds }: IProps) => {
const isSelected = _.includes(selectedRepositoryIds, repository.id);
return (
<View style={Theme.para}>
<View style={Theme.horizontalTopLeft}>
<Mutation
// @ts-ignore - mappings incorrect for Mutations
mutation={SelectRepository}
variables={{ id: repository.id, isSelected }}>
{(toggleSelectRepository: ((id: string, isSelected: boolean) => void)) =>
(<Switch value={isSelected}
onValueChange={(val) => {
const {id} = repository;
toggleSelectRepository(id, val);
}} />)}
</Mutation>
</View>
</View >);
};
使用
"apollo-cache": "^1.1.9",
"apollo-cache-inmemory": "^1.2.1",
"apollo-client": "^2.3.1",
"apollo-link": "^1.2.2",
"apollo-link-error": "^1.0.9",
"apollo-link-http": "^1.5.4",
"apollo-link-state": "^0.4.1",
"graphql": "^0.13.2",
"graphql-tag": "^2.9.2",
"lodash": "^4.17.5",
"react": "16.3.1",
"react-apollo": "^2.1.4",
"react-native": "~0.55.2"
基于Robin Wieruch教程https://www.robinwieruch.de/react-apollo-link-state-tutorial/#apollo-link-state-mutation
答案 0 :(得分:1)
问题是用参数调用解析器。那些已经作为variables
提供,所以(有点令人困惑),应该在没有任何参数的情况下调用解析器toggleSelectRepository
。
测试这个我看到参数确实按照variables
中的规定提供。
<Mutation
// @ts-ignore - mappings incorrect for Mutations
mutation={SelectRepository}
variables={{ id: repository.id, isSelected }}>
{(toggleSelectRepository, { loading, error }: GenericResponse) => {
if (error) {
return <FormValidationMessage>{error.message}</FormValidationMessage>;
}
if (loading) {
return <BusyIndicator isBusy message='One sec..' />;
}
return (<Switch
value={isSelected}
onValueChange={() => toggleSelectRepository()} />);
}}
</Mutation>