All Projects → n1ru4l → Graphql Live Query

n1ru4l / Graphql Live Query

Licence: mit
Realtime GraphQL Live Queries with JavaScript

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Graphql Live Query

Parse Server
API server module for Node/Express
Stars: ✭ 19,165 (+17011.61%)
Mutual labels:  graphql, relay, hacktoberfest
Hackatalk
TalkTalk renewal. Open source chat app built-in expo managed work flow
Stars: ✭ 123 (+9.82%)
Mutual labels:  graphql, relay, hacktoberfest
Graphql Config
One configuration for all your GraphQL tools (supported by most tools, editors & IDEs)
Stars: ✭ 883 (+688.39%)
Mutual labels:  graphql, relay, graphql-schema
Graphbrainz
A fully-featured GraphQL interface for the MusicBrainz API.
Stars: ✭ 130 (+16.07%)
Mutual labels:  graphql, relay, graphql-schema
Get Graphql Schema
Fetch and print the GraphQL schema from a GraphQL HTTP endpoint. (Can be used for Relay Modern.)
Stars: ✭ 443 (+295.54%)
Mutual labels:  graphql, relay, graphql-schema
Strawberry
A new GraphQL library for Python 🍓
Stars: ✭ 891 (+695.54%)
Mutual labels:  graphql, hacktoberfest, graphql-schema
Sql To Graphql Schema Generator
⚛️ Generate GraphQL Scheme Online From SQL Query - https://sql-to-graphql.now.sh/
Stars: ✭ 32 (-71.43%)
Mutual labels:  graphql, hacktoberfest, graphql-schema
Graphql Doctrine
Automatic GraphQL types from Doctrine entities
Stars: ✭ 81 (-27.68%)
Mutual labels:  graphql, hacktoberfest
Tkframework
react + relay + redux + saga + graphql + webpack
Stars: ✭ 83 (-25.89%)
Mutual labels:  graphql, relay
Graphql Log
Add logging to your GraphQL resolvers so you know what's going on in your app.
Stars: ✭ 94 (-16.07%)
Mutual labels:  graphql, graphql-schema
Socket.io Redux
Redux middleware to emit action via socket.io
Stars: ✭ 103 (-8.04%)
Mutual labels:  socket, socket-io
Graphql Schema Language Cheat Sheet
GraphQL Shorthand Notation Cheat Sheet
Stars: ✭ 1,181 (+954.46%)
Mutual labels:  graphql, graphql-schema
Snowflaqe
A dotnet CLI tool to work with GraphQL queries: static query verification, type checking and code generating type-safe clients for F# and Fable.
Stars: ✭ 69 (-38.39%)
Mutual labels:  graphql, graphql-schema
Graphql Transform Schema
Transform, filter & alias resolvers of a GraphQL schema
Stars: ✭ 84 (-25%)
Mutual labels:  graphql, graphql-schema
Socket.io Rpc
Extend your promises across a network with socket.io
Stars: ✭ 67 (-40.18%)
Mutual labels:  socket, socket-io
React Transmit
Relay-inspired library based on Promises instead of GraphQL.
Stars: ✭ 1,335 (+1091.96%)
Mutual labels:  graphql, relay
Graphql Typescript
Define and build GraphQL Schemas using typed classes
Stars: ✭ 67 (-40.18%)
Mutual labels:  graphql, graphql-schema
Graphql Relay Js
A library to help construct a graphql-js server supporting react-relay.
Stars: ✭ 1,331 (+1088.39%)
Mutual labels:  graphql, relay
Relay Northwind App
A complex React, Relay, GraphQL demo app. Online demo:
Stars: ✭ 104 (-7.14%)
Mutual labels:  graphql, relay
Strapi
🚀 Open source Node.js Headless CMS to easily build customisable APIs
Stars: ✭ 41,786 (+37208.93%)
Mutual labels:  graphql, hacktoberfest

GraphQL Live Query

Real-Time with GraphQL for any GraphQL schema or transport.

Read the blog post - Learn how operations are tracked



Packages in this Repository

Package Description Stats
@n1ru4l/in-memory-live-query-store Live query implementation. npm version npm downloads
@n1ru4l/graphql-live-query Utilities for live query implementations. npm version npm downloads
@n1ru4l/graphql-live-query-patch Reduce live query payload size with JSON patches npm version npm downloads
todo-example-app Todo App with state sync across clients.
@n1ru4l/socket-io-graphql-server GraphQL over Socket.io - Server Middleware npm version npm downloads
@n1ru4l/socket-io-graphql-client GraphQL over Socket.io - Client npm version npm downloads
todo-example-app Todo App with state sync across clients. -

Motivation

There ia no mature live query implementation that is not tied to any specific database or SaaS product. This implementation should serve as an example how live queries can be added to any schema with (almost) any GraphQL transport.

GraphQL already has a solution for real-time: Subscriptions. Those are the right tool for responding to events. E.g. triggering a sound or showing a toast message because someone poked you on Facebook. Subscriptions are also often used for updating existing query results on a client that consumes a data from a GraphQL API. Depending on the complexity of that data, cache update code can eventually become pretty bloated. Often it is more straight-forward to simply refetch the query once a subscription event is received.

In contrast to manual cache updates using subscriptions, live queries should feel magically and update the UI with the latest data from the server without having to write any cache update wizardry code on the client.

Concept

A live query is a query operation that is annotated with a @live directive.

query users @live {
  users(first: 10) {
    id
    login
  }
}

A live query is sent to the server (via a transport that supports delivering partial execution results) and registered. The client receives a immediate execution result and furthermore receives additional (partial) execution results once the live query operation was invalidated and therefore the client data became stale.

The client can inform the server that it is no longer interested in the query (unsubscribe the live query operation).

On the server we have a live query invalidation mechanism that is used for determining which queries have become stale, and thus need to be rescheduled for execution. In the future we might event be able to only re-execute partial subtrees of a query operation.

How does the server know the underlying data of a query operation has changed?

The reference InMemoryLiveQueryStore implementation uses an ad hoc resource tracker, where an operation subscribes to the specific topics computed out of the query and resolved resources during the latest query execution.

A resource (in terms of the reference implementation) is described by a root query field schema coordinate (such as Query.viewer or Query.users), , a root query field with id argument (Query.user(id:"1")) or a resource identifier (such as User:1). The latter is by default composed out of the resource typename and the non nullable id field of the given GraphQL type.

For the following type:

type User {
  id: ID!
  name: String!
}

Legitimate resource identifiers could be User:1, User:2, User:dfsg12. Where the string after the first colon describes the id of the resource.

In case a resource has become stale it can be invalidated using the InMemoryLiveQueryStore.invalidate method, which results in all operations that select a given resource to be scheduled for re-execution.

Practical example:

// somewhere inside a userChangeLogin mutation resolver
user.login = "n1ru4l"
liveQueryStore.invalidate([
  // Invalidate all operations whose latest execution result contains the given user
  `User:${newUser.id}`,
  // Invalidate query operations that select the Query,user field with the id argument
  `Query.user(id:"${newUser.id}")`,
  // invalidate a list of all users (redundant with previous invalidations)
  `Quer.users`
]);

Those invalidation calls could be done manually in the mutation resolvers or on more global reactive level e.g. as a listener on a database write log. The possibilities are infinite. 🤔

For scaling horizontally the independent InMemoryLiveQueryStore instances could be wired together via a PubSub system such as Redis.

How are the updates sent/applied to the client

The transport layer can be any transport that allows sending partial execution results to the client.

Most GraphQL clients (including GraphiQL) have support for Observable or async iterable data structures which are perfect for describing both Subscription and Live Queries. Ideally a GraphQL Live Query implementation uses a AsyncIterable or Observable for pushing the latest query data to the client framework that consumes the data.

List of compatible transports/servers

List of known and tested compatible transports/servers. The order is alphabetical.

Package Transport Version Downloads
@n1ru4l/socket-io-graphql-server GraphQL over Socket.io (WebSocket/HTTP Long Polling) npm version npm downloads
graphql-helix GraphQL over HTTP (IncrementalDelivery/SSE) npm version npm downloads
graphql-ws GraphQL over WebSocket npm version npm downloads
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].