graphql mutation in context hooks code example
Example: apollo graphql mutation hook
const UPDATE_TODO = gql`
mutation UpdateTodo($id: String!, $type: String!) {
updateTodo(id: $id, type: $type) {
id
type
}
}
`;
function Todos() {
const { loading, error, data } = useQuery(GET_TODOS);
const [updateTodo] = useMutation(UPDATE_TODO);
if (loading) return Loading...
;
if (error) return Error :(
;
return data.todos.map(({ id, type }) => {
let input;
return (
{type}
);
});
}