Latest news about Bitcoin and all cryptocurrencies. Your daily crypto news habit.
In previous stories I shared my thoughts on how to test react components and graphql, now it is Relay’s turn. Relay is a great data-manager from Facebook. You can find some information about it in my previous stories. Let’s start.
Corner cases
The main corner case in using Relay is that any query you are using might be changed over time and you won’t find it out unless you try to compile relay. If you don’t compile and try to run a query which fetches a field and that field no longer exists on the server you will get an error saying that: “Cannot query field \”firstName\” on type \”User\”.”.
I bet you don’t want to have that, so don’t I. That is why I decided to test relay queries. A relay query looks exactly how a graphql query does.
Solution
We need to execute a query against a graphql schema to understand that everything is ok with the query. The only way to check that is to use parseGraphQLText from relay-test-utils library. We need to call that function with a schema and a query text. If an error is thrown it means that query has some issues, otherwise this function just stay silent.
That’s all. Pretty simple and straightforward! If you like this story like and share it :) Piece.
Relay modern: Testing queries. was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.
Disclaimer
The views and opinions expressed in this article are solely those of the authors and do not reflect the views of Bitcoin Insider. Every investment and trading move involves risk - this is especially true for cryptocurrencies given their volatility. We strongly advise our readers to conduct their own research when making a decision.