Modern bug: Missing type for interface in optimisticResponse
- Dominant language
- Rust
- Stars
- 19k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
For following mutation
```
const mutation = graphql`
mutation UpdatePricesMutation($input: updatePricesInput!) {
updatePrices(input: $input) {
prices {
id
prices {
amount
total
saved
}
}
}
}
`;
export default ({ pricesObject, prices }) => {
const variables = {
input: {
pricesId: pricesObject.id,
prices: prices.map(price => ({
total: price.total,
amount: price.amount
})),
clientMutationId: ''
}
};
const res = commitMutation(
environment,
{
mutation,
variables,
optimisticResponse: () => {
return {
updatePrices: {
prices: {
id: pricesObject.id,
prices: prices.map(price => ({
total: price.total,
amount: price.amount,
}))
}
}
}
}
}
);
};
```
I am getting error:
```
Uncaught Error: RelayResponseNormalizer(): Expected a typename for record `{
"id": "BP-15",
"prices": [
{
"total": "5.00",
"amount": 10
},
{
"total": "30.00",
"amount": 50
},
{
"total": "60.00",
"amount": 100
}
]
}`.
at invariant (invariant.js:44)
at RelayResponseNormalizer._getRecordType (RelayResponseNormalizer.js:80)
at RelayResponseNormalizer._normalizeLink (RelayResponseNormalizer.js:157)
at RelayResponseNormalizer._normalizeField (RelayResponseNormalizer.js:144)
at RelayResponseNormalizer.js:89
at Array.forEach ()
at RelayResponseNormalizer._traverseSelections (RelayResponseNormalizer.js:87)
at RelayResponseNormalizer._normalizeLink (RelayResponseNormalizer.js:163)
at RelayResponseNormalizer._normalizeField (RelayResponseNormalizer.js:144)
at
```
I have been investigating why it happens, because I used optimisticResponse with relay modern and worked fine.
And the tricky part is that the `prices` is graphql `interface`. So this node does not have concreteType, therefore it fails to derive the type. Any hint for work around would be super helpful. I also could spend some time on PR if you would push me to the right direction how to address it.
`prices` node looks like:
```
{
"kind": "LinkedField",
"alias": null,
"args": null,
"concreteType": null,
"name": "prices",
"plural": false,
"selections": [
...
],
"storageKey": null
}
Contributor guide
Assessment
This issue has not been assessed yet.