Graphback uses graphql-migrations to automatically create and update tables from a GraphQL schema.
- PostgreSQL (create and update database)
- SQLite (create database only)
migrateDB method creates and updates your tables and columns to match your GraphQL schema.
All the database operations are wrapped in a single transaction, so your database will be fully rolled back to its initial state if an error occurs.
config: database configuration options.
schemaText: GraphQL schema text.
updateComments: overwrite comments on table and columns.
scalarMap: Custom scalar mapping. Default:
mapListToJson: Map scalar lists to JSON column type by default.
debug: display debugging information and SQL queries.
removeDirectivesFromSchema: Strips all directives from schema before processing.
operationFilter: Filter out database operations that we don't want, e.g. prevent table deletion.
- All other options are not currently supported by Graphback.
Defining your data model
Each type must have a primary key. The primary key field must be
id and the type must be
This creates a relationship via a
userId column in the
profile table. You can customize the key tracking the relationship with the
profile.user_id in the database.
This creates a relationship between
Comment.note and maps to
comment.noteId in the database. If
Comment.note does not exist it will be generated for you.
key annotation you can customise the database column to map to.
This maps to
comment.note_id in the database.
To create a many-to-many relationship, add a model for your join table and use two one-to-many relationship mappings to create the relationship.
Default field value
You can specify a default value using the
@default field annotation as shown below.
Custom column type
Changing column names in Graphback
When working with database migration library it is possible to change individual database columns. Using custom column will require manual mapping in resolver or database layer.
When using custom name in database we need to map it directly inside resolver or db layer.
NOTE: To be able to fully use Graphback, it is recommended that your data models objects to have
id: ID!field or a primary key field specified with the