This is an example project using the following technologies to provide a GraphQLserver.
The main benefit here is our GraphQL API types come directly from the Database,furthermore in our frontend applications we can automatically generateTypescript Types and Typed requests to interact with our API improvingdevelopment agility and our application's integrity.
This README contains the following sections.
The only hard requirement is that you havedocker
anddocker-compose
installed, although naturally, you could install everything locally.
First, let's copy the.env.example
to.env
. This file used bydocker-compose
will pass these environment variables into designatedcontainers.
docker-compose up database migrations
Write some migrations incurrent.sql
, once you're ready to commit.
Note I like to keep the minimum amount of logic in a specific commit to makeyour schema easier to read in the future, this also keeps your agility up inregards to developing new features.
docker-composeexec migrations yarn graphile-migrate commit -m"my commit message"
If you need to reset the database and rerun committed migrations.
docker-composeexec migrations yarn graphile-migrate reset --erase
Once we have our database up and running with a schema we can go ahead and startthe GraphQL server.
docker-compose up database migrations gql
Or using up without and other parameters would start all availabledocker-compose services
docker-compose up database migrations gql
Note that because GraphQL specifies migrations as a dependency and migrationsspecify database as a dependency we could also start everything up with thefollowing command, although this would only output logs from the gql servicehiding other crucial logs.
docker-compose up database migrations gql
Postgraphile comes with a nifty interface to aid in development called GraphiQL,this allows us to inspect our current GraphQL schema at the following URL.
http://localhost:5000/graphiql