Undefined IDs for mutation results

I’m getting warnings about “Cache data may be lost”, so I decided to check if there are missing IDs by adding a custom function:

dataIdFromObject(responseObject) {
  const id = defaultDataIdFromObject(responseObject);
  return id;
}

Most responseObjects are shaped like this:

{ 
  "id": "1",
  "__typename": "Event",
  // other fields 
}

Those are correctly assigned IDs. But I noticed some like this:

{
  "event": {
    "id": "1",
    "__typename": "Event",
    // other fields
  }
}

I traced this back to a mutation that looks like this:

mutation DoAThing($id: ID!) {
  event: doAThing(id: $id) {
    id
    // other fields
  }
}

So it’s nesting the result for some reason. I tried removing the alias, but it’s the same shape, just not aliased.

What am I doing wrong? Do I need a custom function to handle this case? Seems like a vanilla case.

Upon closer examination, it seems that dataIdFromObject is being called a second time with the nested object returned from the mutation, so perhaps this is normal behavior.

But now I’m left wondering why I get a warning like:

Cache data may be lost when replacing the assignment field of a Event object.

To address this problem (which is not a bug in Apollo Client), define a custom merge function for the Event.assignment field, so InMemoryCache can safely merge these objects:

existing: [{“__ref”:“Assignment:39”},{“__ref”:“Assignment:38”}]
incoming: [{“__ref”:“Assignment:38”}]

assignments is one of the other fields noted in the example above, returned from the mutation.