Apollo cache modify doesn't delete the cached item field when DELETE sentinel object is returned

Viewed 35

I'm trying to delete a field in the cached item by using the cache.modify method like it's described in the official documentation.
Based on the API docs I should return the DELETE sentinel object from the resolver function that reflects the type field I want to delete.

I'm doing it but the required field still exists in the cached item after the execution.
How it's possible? Have I just missed something?

Here is the code example:

I have this item in the cache

{
  __typename:"Module"
  id:"l_14"
  length:223
  title: "Chris Hadfield"
}

and I want to delete the title field so I tried to use the cache.modify as described in the docs. Here is how it looks:

  client.cache.modify({
    id: 'Module:l_14',
    fields: {
      title(data, { DELETE }) {
        return DELETE;
      },
    },
  });

But after the execution, the appropriate Module item in the cache didn't change. The title field hadn't been deleted. It looks exactly like it was before the execution:

{
  __typename:"Module"
  id:"l_14"
  length:223
  title: "Chris Hadfield"
}

So why the title field hadn't been deleted even when I replicated all the steps from the documentation example?

P.S. I'm not sure if it's relevant, probably not, but just in case: this Item doesn't have a direct mutation etc. in the BE schema. It's just a nested object of the parent one. The schema looks like this:

  type Track {
    id: ID!
    title: String!
    author: Author!
    thumbnail: String
    length: Int
    modulesCount: Int
    description: String
    numberOfViews: Int
    modules: [Module!]!
  }

  type Module {
    id: ID!
    title: String!
    length: Int  
   }

Thanks for any help!

0 Answers
Related