# When useQuery parsing the JSON data, boolean data gets wrong

**URL:** <https://community.apollographql.com/t/when-usequery-parsing-the-json-data-boolean-data-gets-wrong/6372>\
**Category:** Client SDKs\
**Tags:** client, web\
**Created:** [June 16, 2023, 8:27am UTC](https://community.apollographql.com/t/when-usequery-parsing-the-json-data-boolean-data-gets-wrong/6372 "2023-06-16T08:27:01Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![eslee850](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/eslee850/32/4353_2.png) [@eslee850](https://community.apollographql.com/u/eslee850)\
**Post date:** [June 16, 2023, 8:27am UTC](https://community.apollographql.com/t/when-usequery-parsing-the-json-data-boolean-data-gets-wrong/6372/1 "2023-06-16T08:27:01Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![lenz](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/lenz/32/4007_2.png) [@lenz](https://community.apollographql.com/u/lenz)\
**Post date:** [June 16, 2023, 8:30am UTC](https://community.apollographql.com/t/when-usequery-parsing-the-json-data-boolean-data-gets-wrong/6372/2 "2023-06-16T08:30:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![eslee850](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/eslee850/32/4353_2.png) [@eslee850](https://community.apollographql.com/u/eslee850)\
**Post date:** [June 16, 2023, 8:55am UTC](https://community.apollographql.com/t/when-usequery-parsing-the-json-data-boolean-data-gets-wrong/6372/3 "2023-06-16T08:55:40Z")

</div>

Thanks for reply. Here it is!  
[Query]  
const GET\_SEGMENTLOG\_FROM\_HISTORY = gql` query { segmentHistory (){ nodes { timestamp segment { id forbidFull disabled } } } } `;

[useQuery]  
const { data: data5 } = useQuery(GET\_SEGMENTLOG\_FROM\_HISTORY, {variables: { segmentKey, maxFrom, maxTo }});  
if(data5) console.log(data5);

[Response JSON Data]  
{“data”:{“segmentHistory”:{“nodes”:[{“timestamp”:“2023-06-16T05:13:49.344Z”,“segment”:{“id”:177,“forbidFull”:false,“disabled”:true}},{“timestamp”:“2023-06-16T05:13:51.590Z”,“segment”:{“id”:177,“forbidFull”:false,“disabled”:false}}]}}}

[Parsing Data from useQuery (it means data5)]

 ![캡처_2023_06_16_17_54_39_626](https://us1.discourse-cdn.com/flex019/uploads/apollographql/original/2X/9/9e482e7faa3e2da18c1997fb0b6afcefb718a6a0.png)

---

<div class="post-metadata">

**Author:** ![lenz](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/lenz/32/4007_2.png) [@lenz](https://community.apollographql.com/u/lenz)\
**Post date:** [June 16, 2023, 9:01am UTC](https://community.apollographql.com/t/when-usequery-parsing-the-json-data-boolean-data-gets-wrong/6372/4 "2023-06-16T09:01:34Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![eslee850](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/eslee850/32/4353_2.png) [@eslee850](https://community.apollographql.com/u/eslee850)\
**Post date:** [June 16, 2023, 9:10am UTC](https://community.apollographql.com/t/when-usequery-parsing-the-json-data-boolean-data-gets-wrong/6372/5 "2023-06-16T09:10:05Z")

</div>

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]**  
{“data”:{“segmentHistory”:{“pageInfo”:{“hasNextPage”:false,“hasPreviousPage”:false,“endCursor”:“FgAAAAdfaWQAZIvwlxWNEXsP6IqDAA==”,“startCursor”:“FgAAAAdfaWQAZIvvjRWNEXsP6ICoAA==”,“\_\_typename”:“PageInfo”},“nodes”:[{“timestamp”:“2023-06-16T05:13:49.344Z”,“segment”:{“id”:177,“forbidFull”:false,“disabled”:true,“speedRatio”:1,“startNodeId”:“37”,“endNodeId”:“38”,“length”:5500,“\_\_typename”:“Segment”},“\_\_typename”:“SegmentHistory”},{“timestamp”:“2023-06-16T05:13:51.590Z”,“segment”:{“id”:177,“forbidFull”:false,“disabled”:false,“speedRatio”:1,“startNodeId”:“37”,“endNodeId”:“38”,“length”:5500,“\_\_typename”:“Segment”},“\_\_typename”:“SegmentHistory”},{“timestamp”:“2023-06-16T05:14:59.930Z”,“segment”:{“id”:177,“forbidFull”:true,“disabled”:false,“speedRatio”:1,“startNodeId”:“37”,“endNodeId”:“38”,“length”:5500,“\_\_typename”:“Segment”},“\_\_typename”:“SegmentHistory”},{“timestamp”:“2023-06-16T05:17:31.512Z”,“segment”:{“id”:177,“forbidFull”:true,“disabled”:true,“speedRatio”:1,“startNodeId”:“37”,“endNodeId”:“38”,“length”:5500,“\_\_typename”:“Segment”},“\_\_typename”:“SegmentHistory”},{“timestamp”:“2023-06-16T05:18:15.630Z”,“segment”:{“id”:177,“forbidFull”:true,“disabled”:false,“speedRatio”:1,“startNodeId”:“37”,“endNodeId”:“38”,“length”:5500,“\_\_typename”:“Segment”},“\_\_typename”:“SegmentHistory”}],“\_\_typename”:“SegmentHistoryConnection”}}}

**[Full Parsing Data from useQuery]**

 ![캡처_2023_06_16_18_08_32_282](https://us1.discourse-cdn.com/flex019/uploads/apollographql/original/2X/7/73d8895defea4fcd0c38acee8560f71e67aa92e7.png)

---

<div class="post-metadata">

**Author:** ![lenz](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/lenz/32/4007_2.png) [@lenz](https://community.apollographql.com/u/lenz)\
**Post date:** [June 16, 2023, 9:18am UTC](https://community.apollographql.com/t/when-usequery-parsing-the-json-data-boolean-data-gets-wrong/6372/6 "2023-06-16T09:18:58Z")

</div>

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

```auto
{“id”:177,“forbidFull”:true,“disabled”:false,“speedRatio”:1,“startNodeId”:“37”,“endNodeId”:“38”,“length”:5500,“ __typename”:“Segment”},“__ typename”:“SegmentHistory”},

```

and

```auto
{“id”:177,“forbidFull”:false,“disabled”:false,“speedRatio”:1,“startNodeId”:“37”,“endNodeId”:“38”,“length”:5500,“ __typename”:“Segment”},“__ typename”:“SegmentHistory”},

```

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`).

---

<div class="post-metadata">

**Author:** ![eslee850](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/eslee850/32/4353_2.png) [@eslee850](https://community.apollographql.com/u/eslee850)\
**Post date:** [June 16, 2023, 9:35am UTC](https://community.apollographql.com/t/when-usequery-parsing-the-json-data-boolean-data-gets-wrong/6372/7 "2023-06-16T09:35:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lenz](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/lenz/32/4007_2.png) [@lenz](https://community.apollographql.com/u/lenz)\
**Post date:** [June 16, 2023, 9:41am UTC](https://community.apollographql.com/t/when-usequery-parsing-the-json-data-boolean-data-gets-wrong/6372/8 "2023-06-16T09:41:39Z")

</div>

You would [disable normalization](https://www.apollographql.com/docs/react/caching/cache-configuration/#disabling-normalization) by defining a `typePolicy` for the `Segment` type and set `keyFields` to `false`.

---

<div class="post-metadata">

**Author:** ![eslee850](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/eslee850/32/4353_2.png) [@eslee850](https://community.apollographql.com/u/eslee850)\
**Post date:** [June 16, 2023, 9:51am UTC](https://community.apollographql.com/t/when-usequery-parsing-the-json-data-boolean-data-gets-wrong/6372/9 "2023-06-16T09:51:06Z")

</div>

Oh It works!! Thank you so much!

---

<div class="post-metadata">

**Author:** ![lenz](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/lenz/32/4007_2.png) [@lenz](https://community.apollographql.com/u/lenz)\
**Post date:** [June 16, 2023, 10:00am UTC](https://community.apollographql.com/t/when-usequery-parsing-the-json-data-boolean-data-gets-wrong/6372/10 "2023-06-16T10:00:07Z")

</div>

Great 🙂 You’re welcome!

---

<div class="post-metadata">

**Author:** ![Justin\_Gonzalez](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/justin_gonzalez/32/5359_2.png) [@Justin\_Gonzalez](https://community.apollographql.com/u/Justin_Gonzalez)\
**Post date:** [February 6, 2025, 8:48pm UTC](https://community.apollographql.com/t/when-usequery-parsing-the-json-data-boolean-data-gets-wrong/6372/11 "2025-02-06T20:48:46Z")

</div>


