GraphQL Core: GraphQL Client & Implementations #10

A GraphQL client is a client-side implementation of the GraphQL spec & list of client libraries


Since a GraphQL API has more underlying structure than a REST API, there are more powerful clients like Relay which can automatically handle batching, caching, and other features. But you don't need a complex client to call a GraphQL server.
With express-graphql, you can just send an HTTP POST request to the endpoint you mounted your GraphQL server on, passing the GraphQL query as the query field in a JSON payload.
. . .

What is a GraphQL Client?

Working with a GraphQL API on the frontend is a great opportunity to develop new abstractions and help implement common functionality on the client-side. Let’s consider some “infrastructure” features that you probably want to have in your app:
  • send queries and mutations directly without constructing HTTP requests
  • view-layer integration
  • caching
  • validation and optimization of queries based on the schema

Of course, nothing stops you from using plain HTTP to fetch your data and then shifting all the bits yourself until the right information ends up in your UI.

But, GraphQL provides the ability to abstract away a lot of the manual work you’d usually have to do during that process and lets you focus on the real important parts of your app! In the following, we’ll discuss in a bit more detail what these tasks are.
. . .

What GraphQL Client can do for me?


1. Send Queries and Mutations Directly
One major benefit of GraphQL is that it allows you to fetch and update data in a declarative manner. Put differently, we climb up one step higher on the API abstraction ladder and don’t have to deal with low-level networking tasks ourselves anymore.

2. View Layer Integrations & UI updates
Once the server response is received and handled by the GraphQL client, the requested data somehow needs to end up in your UI. Depending on the platforms and frameworks you’re developing with, there will be different approaches to how UI updates are handled in general.

3. Caching Query Results: Concepts and Strategies
In the majority of applications, you’ll want to maintain a cache of the data that was previously fetched from the server. Caching information locally is essential to provide a fluent user experience and also takes the load off your users’ data plans.

4. Build-time Schema Validation & Optimizations
Since the schema contains all information about what a client can potentially do with a GraphQL API, there is a great opportunity to validate and potentially optimize the queries that a client wants to send already at build-time.
. . .

Client Libraries

In addition to the GraphQL reference implementations in JavaScript, client libraries include:

C# / .NET


Clojurescript

  • re-graph: A GraphQL client implemented in Clojurescript with support for websockets.


Elm


Flutter

  • graphql: A GraphQL client implementation in Flutter.


Go

  • graphql: A GraphQL client implementation in Go.


Java / Android

  • Apollo Android: A strongly-typed, caching GraphQL client for Android, written in Java.
  • Nodes: A GraphQL JVM Client designed for constructing queries from standard model definitions. By American Express.


JavaScript

  • Relay (github) (npm): Facebook's framework for building React applications that talk to a GraphQL backend.
  • Apollo Client (github): A powerful JavaScript GraphQL client, designed to work well with React, React Native, Angular 2, or just plain JavaScript.
  • graphql-request: A simple and flexible JavaScript GraphQL client that works in all JavaScript environments (the browser, Node.js, and React Native) - basically a lightweight wrapper around fetch.
  • AWS Amplify: A JavaScript library for application development using cloud services, which supports GraphQL backend and React components for working with GraphQL data.
  • urql (github): A highly customizable and versatile GraphQL client for React.
  • graphqurl (npm): curl for GraphQL with autocomplete, subscriptions and GraphiQL. Also a dead-simple universal javascript GraphQL client.


Julia

  • Diana.jl: A Julia GraphQL server implementation.


Swift / Objective-C iOS

  • Apollo iOS (github): A GraphQL client for iOS that returns results as query-specific Swift types, and integrates with Xcode to show your Swift source and GraphQL side by side, with inline validation errors.
  • GraphQL iOS: An Objective-C GraphQL client for iOS.
  • Graphaello: A Tool for Writing Declarative, Type-Safe and Data-Driven Applications in SwiftUI using GraphQL and Apollo


Python

  • GQL: A GraphQL client in Python.
  • python-graphql-client: Simple GraphQL client for Python 2.7+.
  • sgqlc: A simple Python GraphQL client. Supports generating code generation for types defined in a GraphQL schema.


R

  • ghql: General purpose GraphQL R client.
. . .

In the next tutorial we will look into the advanced GraphQL concepts such as Query validation and Introspection


Snehal Kumar

Jun 24 2019

Write your response...

On a mission to build Next-Gen Community Platform for Developers