2

Anyone know what to do with this kind of error during a mutation?

Occurs here:

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 >);
};

Using

"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"

Based on Robin Wieruch tutorial https://www.robinwieruch.de/react-apollo-link-state-tutorial/#apollo-link-state-mutation

ios Screenshot

Thomas Hagström
  • 4,371
  • 1
  • 21
  • 27

1 Answers1

1

The issue was calling the resolver with parameters. Those are already supplied as variables, so (a bit confusingly), the resolver toggleSelectRepository should be called without any arguments.

Testing this I see parameters are indeed supplied as specified in 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>
Thomas Hagström
  • 4,371
  • 1
  • 21
  • 27