Skip to content

The api / server for Find A Doc, Japan. Check out the board to see the latest effort https://github.com/orgs/ourjapanlife/projects/8

Notifications You must be signed in to change notification settings

ourjapanlife/findadoc-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

All Contributors

Find a Doc, Japan - Server

Back-end Repository

Welcome to the back-end repository for Find a Doc, Japan! We're not currently looking for contributors in this particular repo, but you're free to have a look around. If you want to provide any suggestions or feedback, come have a chat with us in the #backend-team channel on Slack!

How to contribute

We love and welcome contributions to our front-end repository which can be found here!

Contributors

Ann Kilzer キルザー杏
Ann Kilzer キルザー杏

💻
LaShawn Toyoda
LaShawn Toyoda

💻
Philip Ermish
Philip Ermish

💻
Olivier Lechevalier
Olivier Lechevalier

💻
Evan Peterson
Evan Peterson

💻
Anissa Chadouli
Anissa Chadouli

💻

Prerequisites

  • Node
    • We recommend using nvm and running nvm use in this directory to sync with the project's Node version. However, if you wish to install Node your own way and ensure a consistent version with .nvmrc, that's fine too
  • Yarn Berry
  • Docker Desktop

Setup

1. Install dependencies

npm install

2. Set up Husky Hooks 🐕️

This will automatically run linting before commits and reduce common contributor mistakes.

npm run prepare

3. Setting up the Database 🐘

For simplicity, we use firebase!

For security, we run a local database so we don't break production!

(optional) You can point to different database environments simply by changing the firebase url and variables in the .env.dev file.

3.a Setup Firebase CLI

a.1 Install the Firebase CLI if you do not have it installed on your machine:

npm -g i firebase-tools

To be able to run the firestore emulator you need to have Java version 11 or later installed. If not installed, please follow the next step (a.2).

a.2 Install Java

on a mac, we recommend using homebrew

brew install openjdk

on a windows pc, we recommend using chocolatey

choco install openjdk

You might have to restart vs code for step a.2 and a.3 all of these to take effect in the project

a.3 Log into Firebase CLI:

firebase login

3.b Running the database locally

npm run dev:startlocaldb

This will run until you shut down the instance hitting ctrl^+C

(Optional) Connecting to Production database

Setting Up Firebase Service Account

To set up the Firebase Service Account for this project, follow these steps:

  1. Visit Firebase console.
  2. Under "Project Overview", click on "Project Settings".
  3. Navigate to the "Service Accounts" tab.
  4. Click the "Generate new private key" button. Ensure that Node.js is selected.
  5. Download the JSON file and add it to the root directory of this project. Rename the file to firebaseServiceAccountKey.json.
  6. In your .env file, create an environment variable called SERVICE_ACCOUNT_PATH with the value ./firebaseServiceAccountKey.json.

4. Run the API

Before running the following command, make sure that your local database is running

npm run dev

That's it! This command will start the API, seed your database, install dependencies, and generate our GraphQL types.

(Optional) Running in production mode

In production, we use docker to run the app. You can validate your code works in production by running Make sure that you have docker running beforehand.

npm run prod:build
npm run prod

How to Debug your code

This runs locally and can easily be debugged with vscode! Click on the Run and Debug vscode tab, and then choose Javascript Debug Terminal, then run npm run dev in there and the debugger will automatically connect. Then, just add breakpoints by clicking on the line number of your code.

How to Test your code

Testing with Vitest
  1. Start the Docker container:
npm run test:dockerstart
  1. Run the tests:
npm run test
Testing GraphQL
  1. Run npm run generate to generate the types locally

  2. Run npm run dev to start the local server

  3. Open your browser to http://localhost:3001/

  4. Navigate to the Explorer section from the menu in the left pane.

  5. Click query: Query under "Root Types image

  6. Click the + button to see the fields a type has that can be added to the query image

  7. Select the desired fields and they'll automatically get added to the query builder image

  8. If you select a type that requires an ID (such as Facility or HealthcareProfessional) then add the ID in the "Variables" window at the bottom as a string.

image

  1. If you'd like to share the query you built, such as demonstrating how you tested your code, check out Apollo Explorer's sharing features.

Troubleshooting

Firestore Indexing Error: "The query requires an index..."

When you running query using the getSubmissions method that requires ordering by a specific field, if an index hasn't been created for the combination of that field and the order direction, you might receive an error response. This response will typically contain a direct link to create the required index in the Firebase Console. Here's how you can proceed:

  1. Click on the link in the Error Response: This link will redirect you to the Firebase Console, specifically to the Firestore section where you can create indices.

image

  1. In the Firebase Console, you should see a window labeled Create or update indexes. Click the Save button: This will initiate the process of creating the index. Index creation might take a few minutes.

image

  1. Wait for the Index to be ready: Firestore will show the status of the index. Once it changes from Building to Enabled, you can proceed to run your GraphQL query again.

image

  1. Run Your GraphQL Query Again: With the index in place, your query should now execute without any errors related to indexing.