简体   繁体   中英

React Apollo GraphQL named mutation options.update not getting called while using optimisticUI

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM