facebook / facebook/relay

Relay cache seems to be ignoring nodeInterfaceIdField for caching if "id" field is fetched

Open
#4,199 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
19k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

We like to use `nodeId` as a cache key and `id` as routing/identifiers in our API.

we have the following config:

```
"schemaConfig": {
"nodeInterfaceIdField": "nodeId"
}
```

`nodeId` here is a base64 encoded object of the table id and table name in postgres.

In a query like:

```
query {
records {
nodes {
id
}
}
}
```

the response normalizer will log

```
Warning: RelayResponseNormalizer: Invalid record `9`. Expected __typename to be consistent, but the record was assigned conflicting types `Account` and `Company`. The GraphQL server likely violated the globally unique id requirement by returning the same id for different objects.
```

we currently get around this by doing:
```
new Environment({
getDataID: (fieldValue) => fieldValue.nodeId,
})
```

but that isn't documented and probably breaks other things. one of note is it seems that routine updates don't reflect in the cache and have to be manually updated via `updater` or we have to bust the entire cache and refetch.

Things work fine if we don't fetch `id`, but that doesn't work because of how our mutations are laid out.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.