Install postgres locally or use Docker. In order to get a local postgres started via Docker just run the following docker-compose command.
docker-compose up -d
# Set database url to point to postgres
export DATABASE_URL='postgresql://postgres:postgres@localhost:5432/emergencias_dev'
# Run the setup
npm run db:reset
- Install dependencies:
npm install
- Setup your local postgres database by running
npm run db:reset
. You will need to have postgress installed locally. - Start dev server:
npm run dev
Whenever graphql schema files are updated, you might need to run graphql codegen to generate the updated types. When that happens, run npm run build
.
directives
: Folder for all apollo directives. See https://www.apollographql.com/docs/apollo-server/schema/creating-directives/ for doc on adding custom directives.generated
: Generated typescript filescomponents
: App componentsdb
: DB related logicconfig
: App configuration and env varsapp
: The GraphQL API itself and related configurationstypes
: Custom TypeScript typeserrors
: Custom errors and error handling for the applogger
: Custom logger for the app
- Objection.js has an typing issue where some find queries (ie
findById
,findOne
) should returnundefined
but TypeScript return type does not contain undefined. This should be considered when writing code right now. There is a fix that is being worked on right now. Vincit/objection.js#1651
If when you run npm run db:reset
you find a message similar to Failed to reset database password authentication failed for user "<YOUR_USER_NAME>
then must be because your docker database is taking basic user configuration from your local postresql setup.
I order to solve this problem we are going to run the following commands:
$ psql
$ ALTER USER <YOUR_USER_NAME> WITH PASSWORD 'postgres';
$ exit;
Then try to run again docker, export and reset command:
docker-compose up -d
export DATABASE_URL='postgresql://postgres:postgres@localhost:5432/emergencias_dev'
npm run db:reset
It is recommended to install n to manage multiple node versions on your machine. You can also use nvm or some other nodejs version managers.
- Install
n
via homebrew or npm.brew install n
- Install
avn
to automatically switch to the node version for your projects. - Install the node version specified in the package.json file.
- Run
npm install
to install all project packages.