When useQuery parsing the JSON data, boolean data gets wrong

I am a front developer developing in the react environment. In the current project, data is queried from the graphql server through the useQuery hook of the apollo client library. At this time, there are cases where the data in the actual DB and the data parsed by useQuery are different. This case only occurs when the data is of type boolean. Below is my simple code from my project.

const { data } = useQuery(QUERY);
if(data) console. log(data);

The data received in the above method and the data in the actual DB did not match, so I checked the response JSON data actually delivered to the browser, and it was confirmed that the JSON data was delivered successfully. However, after parsing by the useQuery hook, I confirmed that the data was distorted. The issue occurs only for boolean data. What could be the cause?

Can you give a little bit more context here? What does the query look like? What is the response?

Thanks for reply. Here it is!
const GET_SEGMENTLOG_FROM_HISTORY = gql query { segmentHistory (){ nodes { timestamp segment { id forbidFull disabled } } } } ;

const { data: data5 } = useQuery(GET_SEGMENTLOG_FROM_HISTORY, {variables: { segmentKey, maxFrom, maxTo }});
if(data5) console.log(data5);

[Response JSON Data]

[Parsing Data from useQuery (it means data5)]

I’m a bit irritated that the return JSON does not have __typename in it - is that really the response the browser receives from the network tab?

Yes. The data is quite long, so I just fetched the front part.
Here’s the full Response.

[Full query]
const GET_SEGMENTLOG_FROM_HISTORY = gql query { segmentHistory (){ pageInfo { hasNextPage hasPreviousPage endCursor startCursor } nodes { timestamp segment { id forbidFull disabled speedRatio startNodeId endNodeId length } } } } ;

[Full Response JSON]

[Full Parsing Data from useQuery]

I see your problem. Your JSON contains these two values:




Both of these have the __typename: "Segment" and id: 177, so they will both be identified as Segment:177 inside the Apollo Cache - and overwrite each other.

If those are different objects, you have to make sure to give them different unique identifiers (id).

Oh! Thank you!
Those are log data. so when Object’s value has changed, log would be written in same object Id. I don’t think that I can fix that data because that is not our server and db. Is there any method that prevent the overwrite in client side? I just want exactly same data from DB.

You would disable normalization by defining a typePolicy for the Segment type and set keyFields to false.

Oh It works!! Thank you so much!

Great :slight_smile: You’re welcome!