Thinking of Migrating from REST to GraphQL?

Here’s Why You Should Make the Jump.

Emily Krebs
5 min readFeb 25, 2021
https://davidwalsh.name/getting-started-with-graphql

RESTful APIs… Still the Leading Framework?

The RESTful API framework has been the dominant architecture for designing and building web APIs since its introduction in 2000 — setting the standard for the way in which two servers communicate and exchange data from anywhere in the world. The framework gained early traction due to its uniform interface, statelessness, cacheability, and independence between the client and server, providing more flexibility and increased ease of design to developers.

REST Limitations

Despite its overwhelming popularity, there are a few drawbacks to the overall REST-style, which have become heightened with the emergence of new (and ever-changing) application demands. A common limitation of REST APIs is related to the lack flexibility with data fetching, which may take on on two forms:

  • Overfetching — Meaning the client is retrieving more data than is actually needed at the moment when it’s being fetched. REST APIs are designed such that the only way for a client to retrieve data is by hitting an endpoint that returns a fixed data structure.
  • Underfetching — The opposite of overfetching, meaning that not enough data is included in an API response. This results in the need for waterfall requests, or multiple requests to be made to the server consecutively to extract all of the desired information.
https://www.howtographql.com/basics/1-graphql-is-the-better-rest/

In this example, notice that you need to make 3 requests to different endpoints (waterfall requests) in order to retrieve information regarding a specific user, their posts, and their followers.

Want to read this story later? Save it in Journal.

This example also demonstrates overfetching, as the endpoints return additional information that is not needed (such as follower’s birthdays, address, etc.)

Enter, GraphQL

GraphQL is an open-source data query and manipulation language for APIs, created by developers at Facebook and released in 2015. The framework was designed specifically to cope with the growing need for more efficiency and flexibility with data fetching. In contrast to RESTful APIs, GraphQL provides flexible data retrieval patterns which allow users to ask for exactly what they want in a single query, thus eliminating the overfetching and/or underfetching of data.

https://www.howtographql.com/basics/1-graphql-is-the-better-rest/

Notice in this example how we are able to retrieve the same information regarding the user, posts, and followers from a single query to a single endpoint.

We are also able to specify the exact fields we are looking for.

GraphQL Benefits

There are a number of additional added benefits to implementing the GraphQL framework, including:

  1. Schema & Type System — GraphQL uses a strong type system to define the capabilities of the API, or schema, which serves as the outline for how the client can access data from the server. Once the schema has been defined, the front-end and back-end teams can continue to work entirely independent of one another.
  2. Improved Developer Experience — Data requests from the client are made to a singular endpoint, therefore making it straightforward to add new types and fields to your API without making any changes from the client’s perspective. This model helps keep the API consistent and predictable.
  3. Smaller Payloads (Saving Bandwidth) — The ability for users to request for the exact information they need in a single request significantly improves the app’s performance — saving bandwidth and decreasing the overall load on the server.

This Sounds Great! …But How do I Migrate?

Despite GraphQL’s attractive query flexibility, many companies remain hesitant to migrate from their legacy REST API frameworks to GraphQL as the process is quite time-consuming and can require extensive overhead to execute. To alleviate this stress, our team has created FluxQL, an open-source migration assistance tool that simplifies the tedious process of transitioning from a legacy REST API to a GraphQL framework through introspecting the relationships within your existing relational database.

Getting Started with FluxQL

To begin, FluxQL users may paste in the URI to their PostgresQL database (or select our sample database to get a feel for how the platform works). FluxQL then extracts the table relationships from the database, using them to build out the corresponding GraphQL schema (including types, mutations, and resolvers).

FluxQL Features

  • Users are able to enter their own Postgres URI (encrypted to ensure privacy) or select the sample database to test out.
  • The code for the GraphQL schema is generated based upon your database relationships, including Types and Resolvers. Users are then able to export the code as a zip file with related instructions on how to implement.
  • An interactive graphical representation of your database is shown as reference and advice console is provided that displays a custom sample query and sample mutation, with a high-level overview of how each works.
  • An interactive playground that allows you to test queries for your newly generated schema.

Visit our website at Fluxql.io to learn more! Please note, FluxQL is currently in beta, and the engineering team welcomes feedback, questions, and suggestions about our product. If you like our product, please star us on our GitHub page!

The FluxQL Team

Emily Krebs | LinkedIn | Github
Ross Sarcona | LinkedIn | Github
Heidi Kim | LinkedIn | Github
Tommy Liang | LinkedIn | Github
Daniel Dolich | LinkedIn | Github

📝 Save this story in Journal.

--

--