Fork me on GitHub
Overview

GraphQL-IO is an opinionated MIT-licensed GraphQL-based network communication framework for JavaScript. The client-side runs under either Node.js or in the Browser. The server-side runs under Node.js.

While GraphQL is just a formal language specification and GraphQL.js is a reference implementation of a corresponding execution engine, GraphQL-IO is an entire all-in-one GraphQL-based network communication solution for both client and server.

It integrates the necessary third-party libraries, provides a convenient and flexible API and especially supports real-time updates of GraphQL queries (aka GraphQL subscriptions) over a high-performance, framed, and optionally compressed, WebSocket channel.

GraphQL-IO was originally developed for use in the Gemstone technology stack, but can be used fully stand-alone and independent of it.

Technologies

On the client-side, GraphQL-IO it is based on the GraphQL engine GraphQL.js, the GraphQL parser library GraphQL-Tag, the GraphQL client library Apollo Client, its WebSocket network interface Apollo Client WS*, the underlying WebSocket frame library WebSocket-Framed*, and the HTTP client library Axios.

On the server-side, GraphQL-IO it is based on the GraphQL engine GraphQL.js, the GraphQL schema execution library GraphQL-Tools, the GraphQL type definition library GraphQL-Tools-Types*, the GraphQL subscription management library GraphQL-Tools-Subscribe*, the network communication framework HAPI, the WebSocket integration plugin HAPI-Plugin-WebSocket*, the underlying WebSocket frame library WebSocket-Framed* and the GraphiQL integration plugin HAPI-Plugin-GraphiQL*.

For details on how these libraries are itegrated and play together, please see the Architecture page.

* originally developed for GraphQL-IO by same author to fill the gap

Client & Server Sample

A trivial Hello World sample (in ES2017 syntax) for GraphQL-IO Client and GraphQL-IO Server can look like the following. For a more elaborate example, check out the sample code underlying the Test-Drive page.

Hello World Server:

const { Server } = require("graphql-io-server") const server = new Server({ url: "http://127.0.0.1:12345/api" }) server.at("graphql-resolver", () => ({ Root: { hello: [ "hello: String", () => "world" ] } })) await server.start()

Hello World Client:

const { Client } = require("graphql-io-client") const client = new Client({ url: "http://127.0.0.1:12345/api" }) await client.connect() let result = await client.query("{ hello }") await client.disconnect() console.log(result) // -> { data: { hello: "world" } }

Test-Drive Server-Side:

To test-drive a full-featured Sample Server, which uses an underlying ORM and a RDBMS and even supports full GraphQL query subscriptions, follow the following steps:

  • Download and prepare GraphQL-IO Server:
    $ git clone http://github.com/rse/graphql-io-server
    $ cd graphql-io-server
    $ npm install

  • Fire up the Sample Server:
    $ node sample/sample.js

Test-Drive Client-Side:

To test-drive a full-featured Sample Client, which leverages GraphQL query subscriptions to get informed about concurrent data updates, follow the following steps:

  • Download and prepare GraphQL-IO Client:
    $ git clone http://github.com/rse/graphql-io-client
    $ cd graphql-io-client
    $ npm install

  • Fire up the Sample Client:
    $ node sample/sample.js

Architecture

As mentioned on the Overview page, GraphQL-IO is primarily the glue between a dozen GraphQL partial solutions and as such is actually an extensive integration effort. The following diagram shows the Functional View of the GraphQL-IO architecture on both the client and server side.

Application Programming Interface

GraphQL-IO has two Application Programming Interfaces (APIs): GraphQL-IO Client and GraphQL-IO Server. Although GraphQL is written in ES2017, each one is specified as a separate TypeScript definition with describing comments:

To see most of the APIs in practice, check out the source code of the Sample Client and the Sample Server.

NOTICE: GraphQL-IO is
still in BETA stage:
Feature-Complete, but
still NOT Battle-Tested!