阿波罗突变“在这种环境中,分配的来源必须是一个对象”
Posted
技术标签:
【中文标题】阿波罗突变“在这种环境中,分配的来源必须是一个对象”【英文标题】:Apollo mutation "In this environment the sources for assign MUST be an object" 【发布时间】:2018-11-13 14:43:13 【问题描述】:有人知道在突变期间如何处理这种错误吗?
在这里发生:
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
【问题讨论】:
你能分享你的问题吗?或者具体来说,toggleSelectRepository
是你的变异函数的名称吗?
谢谢@MohsenZareZardeyni - 然而问题是我的解析器参数。查看答案
【参考方案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>
【讨论】:
以上是关于阿波罗突变“在这种环境中,分配的来源必须是一个对象”的主要内容,如果未能解决你的问题,请参考以下文章