首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >阿波罗突变“在这个环境中,赋值的源必须是一个对象”

阿波罗突变“在这个环境中,赋值的源必须是一个对象”
EN

Stack Overflow用户
提问于 2018-06-04 17:41:24
回答 1查看 204关注 0票数 2

有人知道如何处理变异过程中的这种错误吗?

发生在以下位置:

代码语言:javascript
复制
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 >);
};

使用

代码语言:javascript
复制
"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

EN

回答 1

Stack Overflow用户

发布于 2018-06-05 16:20:38

问题是使用参数调用解析器。它们已经作为variables提供了,所以(有点混乱),解析器toggleSelectRepository应该在没有任何参数的情况下调用。

对此进行测试,我看到确实提供了variables中指定的参数。

代码语言:javascript
复制
        <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>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50677605

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档