Data Science | AI | DataOps | Engineering
backgroundGrey.png

Blog

Data Science & Data Engineering blogs

The Rise of GraphQL

With a world wide industry market cap of $7.1 trillion and substantial investments totalling $22.3 billion, let’s delve into the basics around GraphQL and why you should be including it in your infrastructure.

Introduction:

2012 was a transformative year with the release of the transformers paper that underpins much of the recent hype behind ‘LLM’. There was another technology created in the depths of Facebook—GraphQL. It was originally designed to describe the capabilities of data models for client-server applications. For the next three years, it stayed internally at Facebook till in 2015 the development of the open standard initiated and then it was licensed in 2017. Two short years later, the GraphQL Foundation formed.

What is it?

GraphQL is a query language for APIs, and a runtime for fulfilling those queries with your existing data. Unlike traditional REST API strategies that require loading from multiple URLs, GraphQL APIs get all the data your app needs in a single request. Apps using GraphQL are fast and stable because they control the data they get, not the server.

At its core, GraphQL enables declarative data fetching where a client can specify exactly what data it needs from an API. Instead of multiple endpoints that return fixed data structures, a GraphQL server only exposes a single endpoint and responds with precisely the data a client asked for.

Example GraphQL Query:

Consider a scenario where you need to fetch specific user information and related posts. A GraphQL query for this might look like:

query {
  User(id: "Chris Durow") {
    name
    bio
    posts {
      title
      content
    }
  }
}

Using this query this is what my response would look like:

{
  "data": {
    "User": {
      "name": "Chris Durow",
      "bio": "AI Consultant with a cool shed.",
      "posts": [
        {
          "title": "The Rise of Graph QL",
          "content": "An intro to what GraphQL is and its possible applications"
        },
        {
          "title": "How GraphQL can supercharge your RAG implementation",
          "content": "A look into integrating GQL into your RAG implementation to surpercharge those respones!
        },
        {
          "title": "Let's talk domain specific LLM'",
          "content": "An introduction to how you can harness open source domain specific LLM' to help with legal tasks"
        }
      ]
    }
  }
}


Why use it?

GraphQL offers several advantages over traditional REST APIs. It allows clients to request exactly the data they need, nothing more and nothing less. This efficiency in data fetching not only speeds up applications but also reduces the bandwidth usage. GraphQL APIs are strongly typed, and the type system ensures that the API only performs operations that are possible, providing a form of built-in documentation.

Here are the four main value propositions of GraphQL:

1.       Efficient and Flexible: GraphQL allows clients to request only the data they need. This can lead to faster network requests and better app performance. Additionally, GraphQL is highly flexible, allowing clients to request data from multiple sources and aggregate it in a single query.

2.       Strong typing and validation: GraphQL schemas provide strong typing and validation of data, ensuring that clients can only request valid data and reducing the risk of runtime errors.

3.       Client-driven development: GraphQL allows clients to drive the development of the API, as clients can specify exactly what data they need and how it should be returned. This can lead to a more collaborative and iterative development process between front-end and back-end teams.

4.       API consolidation: GraphQL provides the ability to combine data from multiple sources in a single query which can make it easier to consolidate multiple APIs into a single GraphQL API, reducing complexity and improving performance.

What Scenarios would I use it in?

1. Single-Page Applications (SPAs): SPAs benefit immensely from GraphQL's ability to aggregate data from multiple sources with a single API call. This reduces the need to maintain multiple endpoints and simplifies development.

2. Microservices Architecture: In a system where different microservices own different pieces of data, GraphQL acts as a unified facade that simplifies client interaction with these services.

3. Real-Time Applications: GraphQL subscriptions support real-time updates to the client, which are essential for applications like live chat, real-time feeds, and collaborative platforms.

Conclusion

GraphQL’s capability to fetch precisely what’s needed and nothing more, its efficient handling of real-time data, and the ease of integrating with modern architectures make it a compelling choice for modern web and mobile applications. As developers seek more efficiency and better performance from their applications, GraphQL is increasingly becoming the go-to technology for API development. Don’t hesitate to get in touch if you want to chat about how LLMs can revolutionise your processes.