缺少对象GraphQL + Apollo错误的选择集 [英] Missing selection set for object GraphQL+Apollo error

查看:168
本文介绍了缺少对象GraphQL + Apollo错误的选择集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组突变,它们会触发某些类型的弹出窗口的局部状态.它们通常是这样设置的:

I have a set of mutations that trigger the local state of certain types of popups. They're generally set up like this:

  openDialog: (_, variables, { cache }) => {
    const data = {
      popups: {
        ...popups,
        dialog: {
          id: 'dialog',
          __typename: 'Dialog',
          type: variables.type
        }
      }
    };

    cache.writeData({
      data: data
    });
    return null;
  }

我传入的默认值如下:

const defaults = {
  popups: {
    __typename: TYPENAMES.POPUPS,
    id,
    message: null,
    modal: null,
    menu: null,
    dialog: null
  }
};

在我的React代码中使用它们的方式是使用Mutation包装器组件,如下所示:

The way they're used in my React code is with a Mutation wrapper component, like so:

const OPEN_ALERT_FORM = gql`
  mutation AlertOpenDialog($type: String!) {
    openDialog(type: $type) @client
  }
`;

class Alert extends Component {
  render() {
    return (
      <Mutation mutation={OPEN_ALERT_FORM} variables={{ type: ALERT_FORM }}>
        {openDialog => {
          return (
            <Button
              classes="alert-button"
              onClick={openDialog}
              label="Trigger Alert"
            />
          );
        }}
      </Mutation>
    );
  }
}

对于我的各种弹出窗口(我有3或4个不同的弹出窗口,例如menumodal),打开和关闭它们的突变看起来都一样,只是类型名称和内容不同.但是,对于Dialogs,单击它们时出现此错误:

For my various popups (I have 3 or 4 different ones, like menu and modal), the mutations to open and close them all look the same, just different typenames and content etc. But, for Dialogs, I get this error when I click on them:

网络错误:为查询字段对话框返回的Dialog类型的对象缺少选择集

...,然后触发组件从页面中消失.此外,一旦发生这种情况,当您尝试单击其他所有弹出窗口类型时,它们都会消失,然后重新引发该错误,或​​者说:

...and then the triggering component disappears from the page. Plus, once that happens, all other popup types disappear when you try clicking on them, and either re-throw that error, or say:

未捕获的错误:引发了跨域错误. React无法访问开发中的实际错误对象.

我尝试重新编写对话框以与其他弹出窗口类型匹配,并且也重新编写了组件,但是仍然出现此错误.它似乎确实是dialog + Apollo特有的. 这个问题的根源可能是什么?它不可能是后端的东西,因为这只处理本地的Apollo.我以前从未见过此错误,也不确定从这里去哪里.

I've tried re-writing dialogs to match up with other popup types, and re-writing the components as well, but I'm still getting this error. It does appear to be dialog+Apollo specific. What could be the root of this issue? It can't be a backend thing, because this is only dealing with local Apollo. I haven't seen this error before and I'm not sure where to go from here.

推荐答案

此修复程序通过将dialog字段视为字符串而不是对象来起作用.将函数更改为此可以解决问题,并消除错误:

The fix for this turned out to work by treating the dialog field as a string instead of an object. Changing the function to this did the trick and made the errors go away:

  openDialog: (_, variables, { cache }) => {
    const data = {
      popups: {
        ...popups,
        dialog: variables.type
      }
    };

    cache.writeData({
      data: data
    });
    return null;
  }

这篇关于缺少对象GraphQL + Apollo错误的选择集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆