S
S
sharkdest2019-02-22 12:47:58
JavaScript
sharkdest, 2019-02-22 12:47:58

How to filter requests to Apollo cache?

Hello,
how to filter data in requests to Apollo cache ?
In the official documentation, they do it like this:

const { todo } = client.readQuery({
  query: gql`
    query ReadTodo {
      todo(id: 5) {
        id
        text
        completed
      }
    }
  `,
});

I wrote an identical query:
const { user } = client.readQuery({
    query: gql`
      query ReadUsers {
        users(investmentBankingId: 1) {
          name
        }
      }
    `
  });

this is how my apollo cache looks like:
5c6fc477f150f410421695.png
As a result I get the following error:
Error: Can't find field users({"investmentBankingId":1}) on object {
  "users": [
    {
      "type": "id",
      "generated": true,
      "id": "ROOT_QUERY.users.0",
      "typename": "User"
    },
    {
      "type": "id",
      "generated": true,
      "id": "ROOT_QUERY.users.1",
      "typename": "User"
    },
    {
      "type": "id",
      "generated": true,
      "id": "ROOT_QUERY.users.2",
      "typename": "User"
    }
  ],

Please tell me what am I doing wrong.
Thank you.
PS I want to add that such a request, in the same place, works without errors:
query: gql`
      {
        users {
          name
        }
      }
    `

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question