4 GraphQL engines


This chapter covers:

  • Reviewing common issues that arise when building GraphQL backends
  • Introducing database integrations for GraphQL that aim to address these common problems, specifically neo4j-graphql.js
  • Building a GraphQL endpoint backed by Neo4j, taking advantage of the features of neo4j-graphql.js: autogenerated Query and Mutation API, filtering, pagination, temporal/spatial data types
  • Extending the functionality of our auto-generated GraphQL API with custom logic
  • Inferring a GraphQL endpoint from an existing Neo4j database

GraphQL backend implementations commonly run into a set of issues that negatively impact performance and developer productivity. We’ve identified some of these problems previously (such as the "n+1 query problem") and in this chapter we take a deeper look at these common issues that arise and discuss how they can be mitigated using database integrations for GraphQL that make it easier to build efficient GraphQL APIs backed by databases.

Specifically, we look at using neo4j-graphql.js, a Node.js library designed to work with JavaScript GraphQL implementations such as Apollo Server for building GraphQL APIs backed by Neo4j. neo4j-graphql.js allows us to generate GraphQL APIs from type definitions, driving the database data model from GraphQL, auto-generate resolvers for data fetching and mutations, including complex filtering, ordering, and pagination. neo4j-graphql.js also enables adding custom logic.

4.1 Common GraphQL Problems

4.1.1 Poor Performance And The N+1 Query Problem

4.1.2 Boilerplate And Developer Productivity

4.2 Introducing GraphQL Database Integrations

4.3 The neo4j-graphql.js library

4.3.1 Project Setup

4.3.2 Generated GraphQL Schema From Type Definitions

4.3.3 Generated Data Fetching

4.3.4 Configuring The Generated API

4.4 Basic Queries

4.5 Ordering and Pagination

4.6 Nested Queries

4.7 Filtering

4.7.1 Filter Argument

4.7.2 Nested Filter

4.7.3 Logical Operators: AND, OR

4.7.4 Filtering In Selections

4.8 Working With Temporal Fields

4.8.1 Using Temporal Fields In Queries

4.8.2 DateTime Filters

4.9 Working With Spatial Data