Chapter 3. GraphQL Clients

A GraphQL client is software that runs in each client (web browser, native application, etc.) that handles the life cycle of connecting to the GraphQL server, executing queries, and receiving responses.

Technically, any code that allows you to make an HTTP request is a client, from cURL on the command line to any of the thousands of JavaScript libraries that are available. Every programming language, framework, operating system, and so on has the means of making HTTP requests because HTTP-based API calls underpin modern IT.

Note

Even though GraphQL is technically agnostic to the underlying transport protocol, HTTP is the only one you’ll see out in the real world.

Formal GraphQL clients offer basic HTTP request handling plus the following:

  • Low-level networking

  • Batching

  • Authentication

  • Caching

  • Language-specific bindings

  • Frontend framework integration

Let’s explore each one of these in greater depth.

Low-Level Networking

Making an HTTP request sounds simple, but things can go wrong in the long, complicated journey from a client to the GraphQL server and back. The GraphQL server might not respond, the response might be slow, there might be errors calling the underlying datastore, the response size could be very large, and so on. The real world is full of problems. The networking stack of your client can greatly help with these issues by allowing you to configure the following:

  • Retry policies (how many times to retry, how long between ...

Get GraphQL for Modern Commerce now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.