Real-Time Data Updates for Neo4j Using GraphQL Subscriptions

Rate this content
Bookmark
Slides

Join Thomas from the GraphQL Team at Neo4j as he talks about one of the newest features of the Neo4j GraphQL Library: GraphQL Subscriptions. Using this new feature, GraphQL API consumers can listen to data changes in real-time, which happen in Neo4j via the GraphQL Library. Following a high-level overview of the Neo4j GraphQL Library, he will demonstrate the new Subscriptions feature.

FAQ

The Neo4j GraphQL library is an open-source library designed to automatically translate GraphQL queries into Neo4j's Cypher queries. It simplifies building GraphQL APIs by automatically generating queries, mutations, and resolvers, allowing developers to focus on defining type definitions and relationships.

GraphQL subscriptions in Neo4j maintain a permanent connection between the client and the server, typically using WebSockets. When a client subscribes to an event, the server can push real-time updates to the client without further requests. The Neo4j GraphQL library manages these subscriptions, translating and executing database mutations and notifying subscribed clients.

The main benefits include automatic query generation, reducing the need to manually write resolvers or mutations, and solving the N+1 query problem by ensuring that one GraphQL query corresponds to one Cypher query. This efficiency boosts performance and simplifies API maintenance.

Currently, the Neo4j GraphQL API does not detect changes made directly to the database from external sources. However, the development team is aware of this limitation and is working on addressing it in future updates.

The library acts as a mediator that translates GraphQL subscriptions into Cypher queries to monitor events in the database. When a mutation occurs, it notifies all subscribed clients through the established real-time communication channel.

To manage large numbers of subscriptions, the library uses a broker system (like Kafka, Redis, or RabbitMQ) to distribute events to all running instances. This ensures efficient handling of multiple subscriptions and maintains data consistency across different clients and instances.

Advanced features include full support for CRUD operations, automatic resolver generation, relay connection specifications for cursor-based pagination, and the ability to handle complex filtering and aggregation directly within GraphQL queries.

Thomas Wiss
Thomas Wiss
22 min
08 Dec, 2022

Comments

Sign in or register to post your comment.

Video Summary and Transcription

This Talk is about real-time data updates for Neo4j using GraphQL subscriptions. The Neo4j GraphQL library provides automatic schema generation, read queries, mutations, and resolvers. It handles subscriptions using WebSockets and is completely agnostic. The library also has built-in support for events and relationships, allowing for real-time updates and easy scaling. The Talk concludes with details about subscriptions using AMQP and a showcase of Neo4j GraphQL subscriptions in a project called neo place.

1. Introduction to Neo4j and GraphQL Subscriptions

Short description:

I'm Thomas Wiese, a software engineer at Neo4j in the GraphQL team. Today, I'll talk about real-time data updates for Neo4j using GraphQL subscriptions. Neo4j is a heavily scalable database without a schema, based on nodes and relationships forming a graph. The query language for Neo4j is called Cipher, which is easy to learn and has powerful graph pattern matching capabilities. We have built an open source library in TypeScript that integrates Neo4j and GraphQL, allowing clients to send queries that are translated to Cypher and handled automatically in the background.

Hi all, I'm Thomas Wiese, I'm a software engineer at Neo4j in the GraphQL team. And today I'll be talking about real-time data updates for Neo4j using GraphQL subscriptions.

First things first, we have to talk about the database that we use, and it's Neo4j. And Neo4j is also a company, but mostly known for its database, a database that could actually scale very heavily and it doesn't have any schema. All you need is nodes and relationships which form a graph. As you can see one here, a movie graph with relationships and nodes. And the nodes are the bubbles and the relationships are the arrows. And the most important thing to note here is that both nodes and relationships can contain properties. So they're first class citizens.

And of course, if we have a database, we need a way to query that database or a query language. And that's what Neo4j built as well. It's called Cipher. And Cipher got a lot of inspiration from SQL or SQL. But it added some more things on top because we have to query graphs. So we have to do things like graph pattern matching. And one example, a simple example on top is here on the top row where you can see a match where we match a person who acted in a movie. And we have the arrows pointing or indicating a relationship. And this way, we can actually read it quite intuitively. And it's believe me, believe it or not, it's actually very easy to learn. And it has a lot of the power that SQL already has is built in here. So where clauses match, et cetera, et cetera. And we call this ASCII or it's almost ASCII art, what we do here.

So that we have, now we have a database, a really amazing database. And of course the topic of this conference, GrowthQL. And wouldn't it be great if we could just get those two together, right? Could we do something like this here? Yeah, of course, we can do that. Actually, we already built it for you. And we started two years ago building an open source library written in TypeScript for your convenience and all the library DOS or the centerpiece of the libraries, as you can see here in the image. It provides an API or it's the base for an API for a GrowthQL API, where the GrowthQL clients can send their GrowthQL queries to the API. Then the library in the background translates on the fly this query to a Cypher query, and sends that to the database and the response back to the API and then back to the client. And that's all handled for you automatically in the background.

2. Automatic Schema Generation

Short description:

You don't have to do anything here, but we need an API, right? We have to define the API somehow. Usually, you would create your types, write read queries, mutations, and resolvers. But that's painful. I want automatic schema generation.

You don't have to do anything here, but we need an API, right? We have to define the API somehow. And usually you would go along with this or something like this, right? You create your types, your type movie here with a field title. And then you have to do this cumbersome stuff here. You have to write read queries. You have to write all these mutations. They add, change, remove, et cetera, et cetera. You even have to write the resolvers for all of that. I mean, how painful is that? No way. I'm not going to do that.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

From GraphQL Zero to GraphQL Hero with RedwoodJS
GraphQL Galaxy 2021GraphQL Galaxy 2021
32 min
From GraphQL Zero to GraphQL Hero with RedwoodJS
Top Content
We all love GraphQL, but it can be daunting to get a server up and running and keep your code organized, maintainable, and testable over the long term. No more! Come watch as I go from an empty directory to a fully fledged GraphQL API in minutes flat. Plus, see how easy it is to use and create directives to clean up your code even more. You're gonna love GraphQL even more once you make things Redwood Easy!
Local State and Server Cache: Finding a Balance
Vue.js London Live 2021Vue.js London Live 2021
24 min
Local State and Server Cache: Finding a Balance
Top Content
How many times did you implement the same flow in your application: check, if data is already fetched from the server, if yes - render the data, if not - fetch this data and then render it? I think I've done it more than ten times myself and I've seen the question about this flow more than fifty times. Unfortunately, our go-to state management library, Vuex, doesn't provide any solution for this.For GraphQL-based application, there was an alternative to use Apollo client that provided tools for working with the cache. But what if you use REST? Luckily, now we have a Vue alternative to a react-query library that provides a nice solution for working with server cache. In this talk, I will explain the distinction between local application state and local server cache and do some live coding to show how to work with the latter.
Batteries Included Reimagined - The Revival of GraphQL Yoga
GraphQL Galaxy 2021GraphQL Galaxy 2021
33 min
Batteries Included Reimagined - The Revival of GraphQL Yoga
The Guild has recently released Envelop - a new, modern GraphQL Server Framework and plugin system. In this talk I’ll share a brief overview of Envelop and why you should probably upgrade your existing GraphQL server to it.
Rock Solid React and GraphQL Apps for People in a Hurry
GraphQL Galaxy 2022GraphQL Galaxy 2022
29 min
Rock Solid React and GraphQL Apps for People in a Hurry
In this talk, we'll look at some of the modern options for building a full-stack React and GraphQL app with strong conventions and how this can be of enormous benefit to you and your team. We'll focus specifically on RedwoodJS, a full stack React framework that is often called 'Ruby on Rails for React'.
Step aside resolvers: a new approach to GraphQL execution
GraphQL Galaxy 2022GraphQL Galaxy 2022
16 min
Step aside resolvers: a new approach to GraphQL execution
Though GraphQL is declarative, resolvers operate field-by-field, layer-by-layer, often resulting in unnecessary work for your business logic even when using techniques such as DataLoader. In this talk, Benjie will introduce his vision for a new general-purpose GraphQL execution strategy whose holistic approach could lead to significant efficiency and scalability gains for all GraphQL APIs.

Workshops on related topic

Build with SvelteKit and GraphQL
GraphQL Galaxy 2021GraphQL Galaxy 2021
140 min
Build with SvelteKit and GraphQL
Top Content
Featured WorkshopFree
Scott Spence
Scott Spence
Have you ever thought about building something that doesn't require a lot of boilerplate with a tiny bundle size? In this workshop, Scott Spence will go from hello world to covering routing and using endpoints in SvelteKit. You'll set up a backend GraphQL API then use GraphQL queries with SvelteKit to display the GraphQL API data. You'll build a fast secure project that uses SvelteKit's features, then deploy it as a fully static site. This course is for the Svelte curious who haven't had extensive experience with SvelteKit and want a deeper understanding of how to use it in practical applications.

Table of contents:
- Kick-off and Svelte introduction
- Initialise frontend project
- Tour of the SvelteKit skeleton project
- Configure backend project
- Query Data with GraphQL
- Fetching data to the frontend with GraphQL
- Styling
- Svelte directives
- Routing in SvelteKit
- Endpoints in SvelteKit
- Deploying to Netlify
- Navigation
- Mutations in GraphCMS
- Sending GraphQL Mutations via SvelteKit
- Q&A
End-To-End Type Safety with React, GraphQL & Prisma
React Advanced Conference 2022React Advanced Conference 2022
95 min
End-To-End Type Safety with React, GraphQL & Prisma
Featured WorkshopFree
Sabin Adams
Sabin Adams
In this workshop, you will get a first-hand look at what end-to-end type safety is and why it is important. To accomplish this, you’ll be building a GraphQL API using modern, relevant tools which will be consumed by a React client.
Prerequisites: - Node.js installed on your machine (12.2.X / 14.X)- It is recommended (but not required) to use VS Code for the practical tasks- An IDE installed (VSCode recommended)- (Good to have)*A basic understanding of Node.js, React, and TypeScript
GraphQL for React Developers
GraphQL Galaxy 2022GraphQL Galaxy 2022
112 min
GraphQL for React Developers
Featured Workshop
Roy Derks
Roy Derks
There are many advantages to using GraphQL as a datasource for frontend development, compared to REST APIs. We developers in example need to write a lot of imperative code to retrieve data to display in our applications and handle state. With GraphQL you cannot only decrease the amount of code needed around data fetching and state-management you'll also get increased flexibility, better performance and most of all an improved developer experience. In this workshop you'll learn how GraphQL can improve your work as a frontend developer and how to handle GraphQL in your frontend React application.
Build a Headless WordPress App with Next.js and WPGraphQL
React Summit 2022React Summit 2022
173 min
Build a Headless WordPress App with Next.js and WPGraphQL
Top Content
WorkshopFree
Kellen Mace
Kellen Mace
In this workshop, you’ll learn how to build a Next.js app that uses Apollo Client to fetch data from a headless WordPress backend and use it to render the pages of your app. You’ll learn when you should consider a headless WordPress architecture, how to turn a WordPress backend into a GraphQL server, how to compose queries using the GraphiQL IDE, how to colocate GraphQL fragments with your components, and more.
Relational Database Modeling for GraphQL
GraphQL Galaxy 2020GraphQL Galaxy 2020
106 min
Relational Database Modeling for GraphQL
Top Content
WorkshopFree
Adron Hall
Adron Hall
In this workshop we'll dig deeper into data modeling. We'll start with a discussion about various database types and how they map to GraphQL. Once that groundwork is laid out, the focus will shift to specific types of databases and how to build data models that work best for GraphQL within various scenarios.
Table of contentsPart 1 - Hour 1      a. Relational Database Data Modeling      b. Comparing Relational and NoSQL Databases      c. GraphQL with the Database in mindPart 2 - Hour 2      a. Designing Relational Data Models      b. Relationship, Building MultijoinsTables      c. GraphQL & Relational Data Modeling Query Complexities
Prerequisites      a. Data modeling tool. The trainer will be using dbdiagram      b. Postgres, albeit no need to install this locally, as I'll be using a Postgres Dicker image, from Docker Hub for all examples      c. Hasura
Building GraphQL APIs on top of Ethereum with The Graph
GraphQL Galaxy 2021GraphQL Galaxy 2021
48 min
Building GraphQL APIs on top of Ethereum with The Graph
WorkshopFree
Nader Dabit
Nader Dabit
The Graph is an indexing protocol for querying networks like Ethereum, IPFS, and other blockchains. Anyone can build and publish open APIs, called subgraphs, making data easily accessible.

In this workshop you’ll learn how to build a subgraph that indexes NFT blockchain data from the Foundation smart contract. We’ll deploy the API, and learn how to perform queries to retrieve data using various types of data access patterns, implementing filters and sorting.

By the end of the workshop, you should understand how to build and deploy performant APIs to The Graph to index data from any smart contract deployed to Ethereum.