Creates offchain index of mangrove.exchange and provides GraphQL endpoint.
It uses Prisma ORM framework to work with Postgresql. Apollo is used as GraphQL server. GraphQL schema and resolvers are generated with TypeGraphQL and its Prisma Integration
- node.js v16
- yarn
- postgresql instance (can be started with docker-compose)
yarn docker:env
Prisma schema is located at prisma/schema.prisma
.
Manually adjust schema file and run yarn prisma:migrate {migrationname}
create SQL migration and generate client code.
Run yarn prisma:deploy
to apply all migrations to selected database (connection string is taken from DATABASE_URL
env var).
(!) Check out .env.development
and .env.test
file
yarn start:consumer
to start event stream consumeryarn start:server
to start graphql serveryarn test
to run all testsyarn test:integration
to run all integration testsyarn test:unit
to run all unit testsyarn start:test:server
to run Apollo on test database. (useful when debugging tests)yarn debug:integration
to run all integrations tests in debug modeyarn debug:unit
to run all unit tests in debug modeyarn lint
to run linter
Events should not overwrite/delete data, as the data might have to be restored if the event is undone. Instead of overwrites/deletes of entities, the following versioning pattern is applied:
-
prisma.Entity
is the base entity with immutable data (such as id, mangrove id, ...)currentVersionId
is the id of the current version of the entitydeleted = true
means the entity has been deleted
-
prisma.EntityVersion
contains the data that can change when the entity is updatedversionNumber
is an incremental version number, starting at zeroprevVersionId
is the id of an older version that this version replaces, if any
On undo of an event that created a version, that version is deleted and the previous version set as the current. If there was no previous version, the entity itself is deleted (not just marked as deleted, as the undo can never be undone).