Missing selection set for object GraphQL+Apollo error

南楼画角 提交于 2019-12-03 13:07:06

Had the same problem error message. Seems like this is the only question in stackoverflow so far with this same error message in the question.

I will just note down my side of things

In my case, I have a query that is not querying the fields of the object. Anagolous to this case, the query that i have looks like this

{
  popups @client {
    id
    dialog
  }
}

It should be

{
  popups @client {
    id
    dialog {
      id
    }
  }
}

Answer to the actual problem seems lay in the query. Initially Apollo client was not validating types for @client queries/mutations so your mutation could look like you wrote it in the question:

mutation AlertOpenDialog($type: String!) {
  openDialog(type: $type) @client
}

the correct way of writing above is to specify (select) all the simple type (scalar) fields you wanna get in a response. So in regard to the @Vic answer the mutation should look more like:

mutation AlertOpenDialog($type: String!) {
  openDialog(type: $type) @client {
    dialog {
      id
    }
  }
}

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;
  }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!