Hello all, I have an Apollo Client Mutation Compon...
# orm-help
s
Hello all, I have an Apollo Client Mutation Component question. Does anyone know if/how it would be possible to use the Mutation component with a conditional gql string? Each string contains a different mutate function name so I’m unsure of how to handle this. Short of not using the mutation component, but I would like to make use of the higher order loading and errors etc. Here is a snippet of what I’m trying to accomplish (currently doesn’t work, the mutationFunc variable is unrecognized when attempting to use at the mutate function name, even tried setting the variable to strings and calling [mutationFunc], same outcome):
Copy code
const MUTATION_STRING = isCancel ? MANAGE_ACCOUNT_MUTATION : DELETE_USER_MUTATION
    const mutationFunc = isCancel ? updateUser : deleteUser // <-- in theory what I'd like to do

    return (
      <Mutation
        mutation={MUTATION_STRING}
      >
        {/* v---  then call that conditional mutate function based on the MUTATION_STRING */}
        {(mutationFunc, { loading, error }) => (...)}
k
Is your
MUTATION_STRING
a simple string or a gql mutation? The
const mutationFunc
part is not required, it'll be passed to the render function automatically (depending on the
MUTATION_STRING
)
👍 1
s
yes sorry its a gql mutation, so the mutate function name doesn’t have to be the same as what is in the gql mutation?
@kratam that did the trick, thanks for your help!