6 Working with database models and relations

 

This chapter covers

  • Creating object types for database models
  • Defining a global context shared among all resolvers
  • Resolving fields from database models and transforming their names and values
  • Resolving one-to-one and one-to-many relations
  • Working with database views and join statements

Now that you’ve learned the core concepts of building a simple “static” schema and how to resolve its fields, it’s time to get real and learn how to resolve fields from databases. It’s time to implement the queries of the AZdev API. We’ll go through them one by one as we designed them in chapter 4 and learn the concepts we need as we use them.

6.1 Running and connecting to databases

The easiest way to get this project’s databases up and running with sample data is to use Docker. Docker uses your OS virtualization to provide software in packaged containers. It’s available on all three major operating systems.

6.2 The taskMainList query

6.2.1 Defining object types

6.2.2 The context object

6.2.3 Transforming field names

6.2.4 Transforming field values

6.2.5 Separating interactions with PostgreSQL

6.3 Error reporting

6.4 Resolving relations

6.4.1 Resolving a one-to-one relation

6.4.2 Resolving a one-to-many relation

Summary