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

Presentation

The following is an off-site recording of a 50-minute presentation from EnterJS 2018, showing you the difference between REST, GraphQL and GraphQL-IO at the coding-level. It also shows you GraphQL-IO's query subscriptions and allows you to get an impression how GraphQL-IO feels like in real applications.

Sample

A trivial Hello World sample (in ES2017 syntax) for GraphQL-IO Client and GraphQL-IO Server can look like the following. For more elaborate examples, check out the GraphQL-IO Samples and the Units and Persons (UnP) sample application from the Hierarchical User Interface Component Architecture (HUICA) dissertation.

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" } }

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 API functionality in practice, check out the GraphQL-IO Samples.