【问题标题】:React Apollo GraphQL named mutation options.update not getting called while using optimisticUIReact Apollo GraphQL 命名为 mutation options.update 在使用optimisticUI 时没有被调用
【发布时间】:2018-05-12 20:09:56
【问题描述】:

我正在使用 React Apollo GraphQL 命名突变来调用具有特定名称的突变,只是因为我在同一个组件中有多个突变。当我使用 options.update 更新缓存时,不会调用更新。

我的多重变异代码是这样的:

导出默认值

作曲(

graphql(

 SaveRuleMutation,

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

), 图ql( 更新规则变异, { 名称:'更新规则', } ) )(面板);

下面是我的突变调用:

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

【问题讨论】:

  • 您解决了这个问题吗?现在面临同样的问题。所有文档都已更改,因此我只能找到基于组件的示例。

标签: reactjs graphql react-apollo


【解决方案1】:

我认为您的optimisticResponse 格式不正确。应该是:

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

【讨论】:

  • 我刚刚更正了我的optimisticResponse,但它仍然无法正常工作,在这两种情况下,应该调用更新但它不是。
猜你喜欢
  • 2017-03-08
  • 2020-12-01
  • 2021-05-30
  • 2020-01-15
  • 2021-03-21
  • 2019-10-18
  • 2019-06-12
  • 2018-07-15
  • 2018-08-26
相关资源
最近更新 更多