1
votes

I am using React Apollo GraphQL named mutation to invoke the mutation with the specific name just because I have multiple mutations in the same component. When I am using options.update to update the cache, the update isn't invoked.

My multiple mutation code goes like this:

export default

compose(

graphql(

 SaveRuleMutation,

 {
     name: 'SaveRule',
     options: {
        update: (proxy, data) => {
           //Not getting invoked
        }
     }
 }

), graphql( UpdateRuleMutation, { name: 'UpdateRule', } ) )(Panel);

Below is my mutation call:

        SaveRule({
            variables: { 
                name: values.name,
                panelId: panelId,
                where: values.where,
                sort: values.sort
            },
            optimisticResponse: {
               panelView:{
                  __typename: 'PanelViewMutation',
               }
               __typename: 'PanelView',
               create: {                       
                   id: -1,
                   name: values.name,
                   panelId: panelId,
                   where: values.where,
                   sort: values.sort
              },
           },
        })
        .then(function(ruleObj){
            console.log('ruleObj', ruleObj)
        })
        .catch(function(error){
            console.log('error', error)
        })
1
Did you manage to resolve this? Facing the same issue now. All the docs have changed so I can only find the component based examples.Chris Edwards

1 Answers

0
votes

I believe your optimisticResponse is not properly formatted. It should be:

        optimisticResponse: {
          __typename: 'PanelViewMutation',
          create: {                       
            __typename: 'PanelView',
            id: -1,
            name: values.name,
            panelId: panelId,
            where: values.where,
            sort: values.sort
          }
        }