Mon. Jul 15th, 2024

Explorer Series 2.0: Your Introductory Guide to GraphQL

By Arteculate Sep 15, 2021 #Gapstars #Sponsored

From using Google Maps for navigation to ordering food online, APIs are at the core of technology, and thereby – human lives. In case you’re lost, most applications and websites we rely on a daily basis run with the help of Application Programming Interfaces (APIs). Defined simply, an API acts as a bridge of communication between two applications. Their use has been known to increase productivity, save costs, improve connectivity and collaboration, and much more when it comes to the development of a digital solution. 

However, the way APIs work under the hood to retrieve objects has largely remained unchanged for years. That is until now with the arrival of GraphQL. As part of the second episode of the Explorer Series by Gapstars, Dinisha Tennakoon, Technical Lead at Gapstars, and Hasitha Liyanage, the Vice President of Different Engineering Private Limited shared their experience in “Adopting a GraphQL Mindset”. 

The session broke down the basics of Scalability and Bootstrapping of GraphQL – with emphasis on performance, stability, and architecture for the long run. Here’s a quick rundown of everything that was discussed. 

What is GraphQL?

GraphQL is a “pick and choose” data query language where developers can specifically request what is needed from multiple objects that may be available in an API. It was first developed by Facebook in 2012, with the first open-source version made available in 2015. Hasitha expresses that GraphQL is something the world of programming longed for back in the day, as it provides an incomparable developer experience. 

However, he firstly advises anyone starting on how not to approach a solution with GraphQL. In his words, “Do not try to learn the code from Google or Stack Overflow. Rather, use the first principles of the technology, design your own solutions, and then check online if people have done similar solutions.”

Bootstrapping with GraphQL

“As with any programming concept, GraphQL takes a bit of getting used to. However, once this is done it is quite simple to use and GraphQL has made your life easier by posting snippets of the code needed for the technology you wish to use on its website,” states Dinisha. In addition to this, he states the GraphQL has its own playground for anyone to access and try out the technology. 

Once the snippet is obtained, the first step would be to create a schema object to define the API. This is done with the use of the ‘Function build’ schema available on GraphQL. After this, the desired queries and mutations are created and exported. The final part of the bootstrapping process will be to create the Resolvers needed for the execution of the query. Highlighting a common mistake, Dinisha adds, “Do not forget to enable the graphics, by giving the Boolean a TRUE value in the Resolver.”

How can scalability be optimized?

The scalability of a query consists of the optimization of its performance, stability, and security. Breaking them down, Hasitha explains that the performance of a query relies largely on its desk/network, the CPU in play, and the memory used. “Basics such as optimizing data structures and algorithms, cashing relatively stable data, and minimizing data loads can help you go along in creating a better performing query,” he elaborates.

 As for the stability of the query, it is vital that a large number of client and server errors are alpha tested and ironed out, while also maintaining a comprehensive log for monitoring and alert purposes. Authorization tokens and authenticity checks may be deployed as some of the remedies for heightening security during the exchange of data when a query is run. 

Implementing GraphQL: Is it for me?

The implementation of GraphQL does not come without its own challenges. Hasitha states that “One of the most common challenges beginners face is not being used to organize their code accordingly in GraphQL.” In addition to this, the use of GraphQL requires a good error handling protocol as debugging happens in the front end. This may prove to be a tiresome task if the error is not communicated properly. Moreover, Hasitha points out that there is always an over-fetching of data in the backend that cannot be overcome with the use of this technology.

Furthermore, he instructs developers to use a piecemeal approach converting a few read-only nodes at first and migrating gradually instead of using a ‘big bang’ implementation. “Start with the front end, identify the places with minimum impact in the code and begin introducing your GraphQL” adds Dinisha. 

From his experience, he further expresses that at times the complete transfer of code may not be possible even with the best programmers. Projects that have been in development for over two years are likely to be subject to this problem and tend to use a combination of traditional NEST technology with GraphQL.“Experimenting with GraphQL is a must, but be careful when it comes to using it for products. Since it is relatively new, a bug-free process is not guaranteed,” Hasitha adds as a bottom line in the conclusion of the episode. 

By Arteculate

Arteculate is your guide to the Asian tech industry. We give you unparalleled insights, accurate, local tech news, thoughtful features and sometimes scathing opinions on where things are headed. Stay tuned for the best of Asia!

Related Post