9 Advanced GraphQL considerations

 

This chapter covers

  • Using abstract types of unions and interfaces for their benefits
  • Paginating query results, using offsets and cursors
  • Working with relationship properties, using Relay connection types

So far, we haven’t leveraged one of the most powerful and important features of GraphQL’s type system—abstract types—which allow us to represent multiple concrete types in a single GraphQL field. Similarly, we also haven’t really made use of an important feature of the property graph model—relationship properties—which allow us to associate attributes with the relationships that connect nodes rather than just nodes themselves. In this chapter, we will see how to leverage the abstract union and interface types supported by GraphQL. We will also make use of relationship properties and, along the way, introduce GraphQL Connection objects and pagination methods. We will move away from our business review application and simplify our data model, focusing instead on an API for a simple online store that sells two types of products: books and videos.

9.1 GraphQL abstract types

9.1.1 Interface types

9.1.2 Union types

9.1.3 Using abstract types with the Neo4j GraphQL library

9.2 Pagination with GraphQL

9.2.1 Offset pagination

9.2.2 Cursor pagination

9.3 Relationship properties

9.3.1 Interfaces and the @relationship GraphQL schema directive

9.3.2 Creating relationship properties

9.4 Wrapping up Full Stack GraphQL

9.5 Exercises

Summary