cosva-api v2.3.0
Cosva-api
A full-fledged Apollo Server with Apollo Client starter project with React and Express. Read more about it in this tutorial to build it yourself.
Family of universal fullstack repositories:
Server Applications:
Client Applications:
Features of Client + Server
- React (create-react-app) with Apollo Client
- Queries, Mutations, Subscriptions
- Node.js with Express and Apollo Server
- cursor-based Pagination
- PostgreSQL Database with Sequelize
- Entities:
- users
- user_photos
- messages
- comments
- farms
- farm_users
- farm_photos
- categories
- farm_categories
- category_groups
- farm_category_groups
- permissions
- roles
- role_permissions
- user_roles
- user_role_permissions
- bovines
- bovine_extra_data
- bovine_purpose_types
- bovine_purpose_type_genders
- bovine_purposes
- animal_genders
- milk_production_dates
- bovine_milk_productivities
- bovine_reproductive_controls
- bovine_reproductive_states
- animal_breeds
- animal_breed_tags
- animal_development_stages
- token_reset_passwords
- bovine_reproductive_state_configuration_defaults
- bovine_reproductive_state_configurations
- bovine_genealogies
- Entities:
- Authentication
- powered by JWT and local storage
- Sign Up, Sign In, Sign Out
- Authorization
- protected endpoint (e.g. verify valid session)
- protected resolvers (e.g. e.g. session-based, role-based)
- protected routes (e.g. session-based, role-based)
- performance optimizations
- example of using Facebook's dataloader
- E2E testing
Installation
git clone git@github.com:EduardMcfly/cosva-api.git
cd cosva-api
touch .env
npm install
- fill out .env file (see below)
- Start your PostgreSQL database by running the appropriate command or by using
docker compose up -d
if you have a Docker configuration. npx prisma generate
npx prisma db push
npx prisma db seed
npm run dev
- visit
http://localhost:8000
for GraphQL playground
.env file
Since this boilerplate project is using PostgreSQL, you have to install it for your machine and get a database up and running. You find everything for the set up over here: Setup PostgreSQL with Sequelize in Express Tutorial. After you have created a database and a database user, you can fill out the environment variables in the .env file.
SECRET_KEY=asdlplplfwfwefwekwself.2342.dawasdq
FILES_URL_API = files.cosva.app
APP_NAME = 'Cosva'
APP_URL = 'https://cosva.app'
MAIL_HOST = -------
MAIL_USERNAME = -------
MAIL_PASSWORD = -------
The SECRET_KEY
is just a random string for your authentication. Keep all these information secure by adding the .env file to your .gitignore file. No third-party should have access to this information.
Testing
- adjust
test:run-server
npm script withTEST_DATABASE
environment variable in package.json to match your testing database name- to match it from package.json:
createdb mytestdatabase
with psql
- to match it from package.json:
- one terminal: npm run test:run-server
- second terminal: npm run test:execute-test
Want to learn more about React + GraphQL + Apollo?
- Don't miss upcoming Tutorials and Courses
- Check out current React Courses
Run migrations in production
Is important to have the ssh tunnel open to run the migrations
ssh -N -L 4200:$db:5432 ec2-user@$ec2 -i prisma.pem -v
The file .env must have the following variables
DATABASE_URL = postgresql://$user:$password@localhost:4200/$DB
npm run ssh:connect
npx prisma db seed
3 months ago