Installing Offix DataStore
Building your own GraphQL type
Let's use the following sample schema for our app
We have a cli tool that generates DataStore config and Model JSON schema given a GraphQL schema.
To be able to store user tasks in the DataStore, you need to create it's DataStore model.
The DataStore model provides the API to perform CRUD operations on
Task in the DataStore.
The cli tool generates code to configure each model defined in your graphql schema.
Here we will assume that you generated the DataStore config files in
If you are using Typescript and you want your model to have types, you can create an interface:
and instantiate the
TaskModel with the
Task interface in the generated config file.
The DataStore creates a table on the device for each model. When you push a new version of your app with models added, replaced or removed, the tables for the new models won't be created on the client device and the unused tables(for removed models) won't be deleted.
To make the DataStore acknowledge these changes, you need to increment the schema version.
Using our sample app, suppose we add a
SubTask model, we need to increment
the schema version to trigger the creation of the "user_SubTask" table on the client device.
DataStore constructor takes a schema version parameter (defaults to 1).