Map GraphQL types to database tables
mainTo implement a database-backed model, you must map your GraphQL schema to database tables. Grackle provides integrations for doobie (JDBC) and Skunk (native PostgreSQL).
Implementation Steps:
- Define Columns: For each database column, provide its name and a doobie codec of type
Meta. Specify if the value is nullable. - Define Root Fields: Define top-level GraphQL fields as
SqlObjectmappings. - Define Type Mappings: Map each GraphQL type to its corresponding database columns.
- Handle Nested Types with Joins: For nested GraphQL types, use
Join(columnA, columnB)to translate the relationship into a SQL join. For example,Join(country.code, city.countrycode)joins the country and city tables where the country code matches the city's country code.