This repo is a port of the Forum software and schema from https://github.com/graphile/examples
Our stack consists of the following technologies:
- PostgreSQL >=14: Used as our datastore and for backend functions
- Postgraphile CLI: Used to introspect a Postgres schema and serve a GraphQL API
- React + Relay: Frontend libraries for building user interfaces and managing API data (developed by Facebook)
- Rescript: A type-inferred functional programming language that commpiles to JavaScript (again, Facebook tech)
- rescript-relay: An addition to the Relay compiler that emits types, adds a preprocessor (ppx) to your source, and supports a VSCode plugin.
Before you begin, ensure you have the following set up:
- Node.js >=18.6: Used as a runtime environment for executing JavaScript
- PostgreSQL >=14: A recent and running instance, likely on
localhost, which Postgraphile can connect to using a connection string. - VSCode: For coding and utilizing plugins for Rescript, rescript-relay, and Relay.
- Yarn: To manage package dependencies
- Watchman: A file watching service developed by Facebook, which is necessary for Relay.
- Environment Variables:
DATABASE_URLfor Postgres connection.
In case any of these tools are not installed, here are some quick setup guides:
First, if you haven't already, install Homebrew, a package manager for MacOS that makes it easy to install software from the command line.
- Node.js: Download and install from Node.js's website.
- PostgreSQL: Install with
brew install postgresql@15. - VSCode: Download and install from VSCode's website.
- Yarn: Install with
brew install yarn. - Watchman: Install with
brew install watchman.
- Node.js: Download and install from Node.js's website.
- PostgreSQL: Download and install from PostgreSQL's website.
- VSCode: Download and install from VSCode's website.
- Yarn: Download and install from Yarn's website.
- Watchman: Download and install from Watchman's website.
Additionally, you will want to install the following VSCode extensions:
After cloning this repository and installing the prerequisites, you can start setting up the project:
-
Create a PostgreSQL Database. Use
pgsqlorpgclito run the following command:CREATE DATABASE relayforums;
Note: The below connection string assumes a Postgres user named
drewwith password1234. If you would like to use a different user, you will need to modify the connection string in the.envfile and update the999_data.sqlfile in thedbdirectory. Either way, ensure that the user has proper privileges on therelayforumsdatabase:CREATE USER drew WITH PASSWORD '1234'; ALTER USER drew WITH SUPERUSER;
-
Run bash commands.. Assuming you start in the root project directory, navigate to the
dbdirectory, populate the database, return to the root directory, install dependencies, and build the project:cd ./db; psql relayforums < ./reset.sql # or psql -f ./reset.sql -d relayforums cd ../ yarn; mkdir ./src/__generated__; yarn relay:build; yarn re:build;
-
Create a
.envfile.. In the root directory, create a file called.envand add the following:DATABASE_URL=postgres://drew:1234@localhost/relayforums # or the Cloud SQL connection string GRAPHILE_URL=http://localhost:5000/graphql -
Start the Postgraphile server.. In the root directory, run the following. Wait until the server starts up and you can see GraphiQL at the URL it provides:
yarn postgraphile:dev
Keep this server up and running in a terminal. Then, in a separate terminal...
-
Start the Parcel server. In the root directory, run the following command to serve your project as you develop:
yarn parcel:serve;This will start a server at
localhost:1234that will automatically reload when you make changes to your code.
And that's it! You should now be able to see the Forum app running at
localhost:1234 and the GraphiQL interface at localhost:5000/graphiql.