Spending Weekend with GraphQL

Have you ever experienced an itch you just can’t scratch? If yes, then you will feel my pain. A few days back, everything was fine, I was happily writing code(!) and doing standup meetings regularly. Just before the weekend, my boss called me and shared this problem with me.

We were creating a page upon form submission. Then update the cache in the client-side with that newly created page and redirecting to that page. Everything was going well. But after the first page is created and the cache is updated, the Query was returning an empty {}. No errors, nothing, just an empty object.

At first, I thought this was just a simple problem with a state management issue. I spent the next two days trying to identify the underlying problem. During that time, I have re-written that entire component from scratch (blaming the component is always the first task :p ), passed different callbacks methods to different child components of that parent component, and some voodoo stuff. Nothing seems to work. Always the same {} empty object.

I was pulling my hair off and at times I was considering quitting my job. But I couldn’t get it out of my head.

What an irony of fate, just after my weekend was over and I was preparing for bed, I thought, okay let’s try 30 more minutes in the problem. After some digging, through pure serendipity, I found this link. The problem was that, if you try to fetch partial data from graphql API using apollo-graphql and try to updates the cache with that partial data, the query will fail silently without throwing any errors. That is why I hate failing silently. Failing should be done with flying colors in my opinion.

At last, I found out that, we have added some new fields in different PR and it was merged in our dev branch. As usual, I pulled that branch into my current branch and was unaware of the new field in the query. That little(!!!) difference F****D my whole weekend :(. But man, the moment I realized the issue, that eureka moment, it was awesome. I think we all love this job because of these eureka moments. I was happier than ever. I almost forgot that I lost 2 days of break and have to start working from tomorrow. With the massive dopamine rush in my brain, I started writing this article without sleeping. 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *