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.

This talk has been presented at GraphQL Galaxy 2022, check out the latest edition of this Tech Conference.

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
Tom Pressenwurter introduces Redwood.js, a full stack app framework for building GraphQL APIs easily and maintainably. He demonstrates a Redwood.js application with a React-based front end and a Node.js API. Redwood.js offers a simplified folder structure and schema for organizing the application. It provides easy data manipulation and CRUD operations through GraphQL functions. Redwood.js allows for easy implementation of new queries and directives, including authentication and limiting access to data. It is a stable and production-ready framework that integrates well with other front-end technologies.
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
This Talk discusses handling local state in software development, particularly when dealing with asynchronous behavior and API requests. It explores the challenges of managing global state and the need for actions when handling server data. The Talk also highlights the issue of fetching data not in Vuex and the challenges of keeping data up-to-date in Vuex. It mentions alternative tools like Apollo Client and React Query for handling local state. The Talk concludes with a discussion on GitLab going public and the celebration that followed.
Batteries Included Reimagined - The Revival of GraphQL Yoga
GraphQL Galaxy 2021GraphQL Galaxy 2021
33 min
Batteries Included Reimagined - The Revival of GraphQL Yoga
Envelope is a powerful GraphQL plugin system that simplifies server development and allows for powerful plugin integration. It provides conformity for large corporations with multiple GraphQL servers and can be used with various frameworks. Envelope acts as the Babel of GraphQL, allowing the use of non-spec features. The Guild offers GraphQL Hive, a service similar to Apollo Studio, and encourages collaboration with other frameworks and languages.
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
The Talk discusses the challenges and advancements in using GraphQL and React together. It introduces RedwoodJS, a framework that simplifies frontend-backend integration and provides features like code generation, scaffolding, and authentication. The Talk demonstrates how to set up a Redwood project, generate layouts and models, and perform CRUD operations. Redwood automates many GraphQL parts and provides an easy way for developers to get started with GraphQL. It also highlights the benefits of Redwood and suggests checking out RedwoodJS.com for more information.
Adopting GraphQL in an Enterprise
GraphQL Galaxy 2021GraphQL Galaxy 2021
32 min
Adopting GraphQL in an Enterprise
Today's Talk is about adopting GraphQL in an enterprise. It discusses the challenges of using REST APIs and the benefits of GraphQL. The Talk explores different approaches to adopting GraphQL, including coexistence with REST APIs. It emphasizes the power of GraphQL and provides tips for successful adoption. Overall, the Talk highlights the advantages of GraphQL in terms of efficiency, collaboration, and control over APIs.
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
GraphQL has made a huge impact in the way we build client applications, websites, and mobile apps. Despite the dominance of resolvers, the GraphQL specification does not mandate their use. Introducing Graphast, a new project that compiles GraphQL operations into execution and output plans, providing advanced optimizations. In GraphFast, instead of resolvers, we have plan resolvers that deal with future data. Graphfast plan resolvers are short and efficient, supporting all features of modern GraphQL.

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
Build Modern Applications Using GraphQL and Javascript
Node Congress 2024Node Congress 2024
152 min
Build Modern Applications Using GraphQL and Javascript
Featured Workshop
Emanuel Scirlet
Miguel Henriques
2 authors
Come and learn how you can supercharge your modern and secure applications using GraphQL and Javascript. In this workshop we will build a GraphQL API and we will demonstrate the benefits of the query language for APIs and what use cases that are fit for it. Basic Javascript knowledge required.
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