PricingBlog

Branching based on GraphQL mutation response

  • mbirkegaard-1526960355253686312

    mbirkegaard

    6 hours ago

    I have a mutation that returns a response union (basically a couple of differnet types of succes and an error) and I would like to branch based on which member of the union is returned (to show different notifications). What's the best way to go about it? Currently I'm trying to call the mutation in a workflow that then switches on the data member in the response. For the time being I'm manually doing a get on __typename to compare, but is there a better way?
  • mbirkegaard-1526963917882916895

    mbirkegaard

    6 hours ago

    And the branching has to happen in the onSuccess handler, rihgt? It cant come after the call itself in the top-level workflow?
  • max.kayr-1526973940503679047

    Max

    5 hours ago

    Hey! I think that is a reasonable approach. And yes, it has to happen in a callback (onSuccess, onError), not after the call.