Graphback uses graphql-migrations to automatically create and update tables from a GraphQL schema.
- PostgreSQL (create and update database)
- SQLite (create database only)
To create or update your database from the CLI, run:
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.
Default field value
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: database migration logic require objects to have
id: ID!field defined. Renaming
idfield to anything else will break Graphback data resolution logic