Modified response data with Apollo Link not showing after middleware

Hi everyone,

I am currently trying to make use of Apollo link to create some middleware and modify the response data before we access it on the front end, due to needing to add some data into the response and also restructuring some nested data objects.

When I console log the response it seems like the tested modification has worked but when accessed on the front end it still seem’s to show the original query that was used with use the useQuery hook. I attempted to see if adding the no cache option to useQuery would make a difference but it doesn’t seem to.

Any help would be much appreciated :blush:

In your example, you are setting a field in an array but not on an array item.
Did you test modifying your array item itself instead?

Like map the and set your field on each product item?

You might already know, but there is also this: Local-only fields in Apollo Client - Apollo GraphQL Docs

Hi @Kheang_Hok_Chin,

I hope you are well and thank you for helping out :slight_smile:

After trying your suggestion of mapping through the products instead I can see that the fields can be modified now with static data such as that initial testing string that I was working with.

The main implementation/issue that I was hoping to get this working with, as the one posted was a test, was to first get a reference ID from a CMS and then make a further fetch request with that ID to populate the reference data into the response.

I realised afterwards that I wasn’t wrapping the map with the new fetch inside a Promise.all so it wasn’t respecting the await’s that I had added in, in turn resulting in the modified data not showing on the front end.

I really appreciate your help in pointing me in the right direction with this as I was trying to find a solution for a few days :sweat_smile:

1 Like

lol it happens to all of us, glad it worked out!

1 Like

Thanks again and best of luck with all of your work :slightly_smiling_face:

1 Like