Skip to content

garpulon/rescript-relay-sandbox

Repository files navigation

Rescript Relay Sandbox

This repo is a port of the Forum software and schema from https://github.com/graphile/examples

Stack

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.

Prerequisites

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_URL for Postgres connection.

In case any of these tools are not installed, here are some quick setup guides:

For MacOS:

First, if you haven't already, install Homebrew, a package manager for MacOS that makes it easy to install software from the command line.

  1. Node.js: Download and install from Node.js's website.
  2. PostgreSQL: Install with brew install postgresql@15.
  3. VSCode: Download and install from VSCode's website.
  4. Yarn: Install with brew install yarn.
  5. Watchman: Install with brew install watchman.

For Windows:

  1. Node.js: Download and install from Node.js's website.
  2. PostgreSQL: Download and install from PostgreSQL's website.
  3. VSCode: Download and install from VSCode's website.
  4. Yarn: Download and install from Yarn's website.
  5. Watchman: Download and install from Watchman's website.

Additionally, you will want to install the following VSCode extensions:

Setting up the project

After cloning this repository and installing the prerequisites, you can start setting up the project:

  1. Create a PostgreSQL Database. Use pgsql or pgcli to run the following command:

    CREATE DATABASE relayforums;

    Note: The below connection string assumes a Postgres user named drew with password 1234. If you would like to use a different user, you will need to modify the connection string in the .env file and update the 999_data.sql file in the db directory. Either way, ensure that the user has proper privileges on the relayforums database:

    CREATE USER drew WITH PASSWORD '1234';
    ALTER USER drew WITH SUPERUSER;
  2. Run bash commands.. Assuming you start in the root project directory, navigate to the db directory, 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;
  3. Create a .env file.. In the root directory, create a file called .env and add the following:

    DATABASE_URL=postgres://drew:1234@localhost/relayforums # or the Cloud SQL connection string
    GRAPHILE_URL=http://localhost:5000/graphql
  4. 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...

  5. 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:1234 that 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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors