I have a typegraphql query hook that fetchs one user. Among other things that this user object contains, there are "custom data", an array of custom objects, each coming with an id. In my graphql file, the object looks like this :
User {
id
firstName
lastName
(...)
customData {
fieldName
fieldValue
fieldId
id
}
}
But if this user has no value yet for a specific custom data, there's no id neither. In this case, Apollo cache is messing the data. If I receive this from my query :
[
{ fieldName: "fakename1", fieldValue: null, fieldId: "fakeId1", id: null },
{ fieldName: "fakename2", fieldValue: null, fieldId: "fakeId2", id: null },
{ fieldName: "fakename3", fieldValue: null, fieldId: "fakeId3", id: null },
]
My React application will not get these data, but those instead :
[
{ fieldName: "fakename1", fieldValue: null, fieldId: "fakeId1", id: null },
{ fieldName: "fakename3", fieldValue: null, fieldId: "fakeId1", id: null },
{ fieldName: "fakename1", fieldValue: null, fieldId: "fakeId1", id: null },
]
The two things that seem to solve the problem right now :
- set fetch-policy to "no-cache". But I don't want to do that (it creates other bugs)
- send fake ids ("1", "2",...) until there are real ones. But it doesn't sound like a good solution.
Is there a clean way to do this ?