Neo4j GraphQL Library
A booming market has created the demand for reducing the time to market of software products to a minimum. The current trend is pushing app development more and more towards versatility and speed to market, which has caused tools like GraphQL to gain prominence and as more and more people get into GraphQL they in turn look for tools that make it easier to use for them. If you’re thinking about working with GraphQL the first thing that comes to mind is obviously the schema and wouldn't you know it, there’s a little something that can help you working on that.
Graph plus graph
Enter Neo4j, a graph database management system. Honestly even going by that, combining GraphQL with a graph database sounds like a no brainer but there’s a bit more to it than that. Since GraphQL treats app data as a graph, a graph backend like Neo4j fits it like a glove. Neo4j is written in Java but is very versatile and translates data from sources written in other languages into Cypher queries which makes it perfect for GraphQL and its SDL (Schema Definition Language) The connection isn't something that happened by chance as Neo4j has been involved with GraphQL for years and has supported the GRAND stack for quite a while as well. Let’s look at the key features of the database itself:
- easy to learn and versatile query language: Cypher is a powerful, declarative query language inspired by SQL which uses ASCII-Art syntax to make querying graph data easy to read, learn and use for everyone.
- ACID compliance: atomicity, consistency, isolation and durability, basically a set of properties which make sure the data is valid despite errors, power cuts, and other problems.
- performance and adjustability: graph databases in general provide great performance especially for more complex queries and a ton of flexibility due to the graph data model being ‘whiteboard-friendly’ and the graph query model being very intuitive and transparent.
Equals Neo4j GraphQL Library
In April Neo4j released the Neo4j GraphQL Library, a tool which makes using the two even easier and more beneficial. It's designed to be a low code library aimed at fully utilising the power of connected data in API development. It basically acts as an intermediary between your GraphQL client and the Neo4j database making sure everything works smoothly between frontend and backend development. In more technical terms because GraphQL uses a schema and type safe SDL the library is written in TypeScript and takes a schema-first approach as well minimizing the amount of backend code needed. Let’s look at what it does for you:
- GraphQL queries are translated into a single Cypher query, this solves the n+1 query problem and makes sure there are no unnecessary database calls.
- Generates Cypher code from GraphQL, GraphQL CRUD API from type definitions, auto-generated resolvers, and allows custom logic with its cypher schema directive.
- Provides strong authorization to secure your GraphQL API, nested mutations and Object-Graph-Mapper
And maybe even add on something else
All in all the library does exactly what it promises and if you’re already using GraphQL that's a good enough reason to check it out. The benefits of using Neo4j are pretty apparent in and of itself and, as mentioned before, it just fits GraphQL perfectly. You can also use it along with some of the popular frameworks like React, Vue, Angular and others to get even more out of it, but we'll take a look at that next time when we check out the GRAND stack.