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!
We love and welcome contributions to our front-end repository which can be found here!
Ann Kilzer キルザー杏 💻 |
LaShawn Toyoda 💻 |
Philip Ermish 💻 |
Olivier Lechevalier 💻 |
Evan Peterson 💻 |
Anissa Chadouli 💻 |
- 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
- We recommend using nvm and running
- Yarn Berry
- Docker Desktop
npm install
This will automatically run linting before commits and reduce common contributor mistakes.
npm run prepare
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.
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).
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
firebase login
npm run dev:startlocaldb
This will run until you shut down the instance hitting ctrl^+C
To set up the Firebase Service Account for this project, follow these steps:
- Visit Firebase console.
- Under "Project Overview", click on "Project Settings".
- Navigate to the "Service Accounts" tab.
- Click the "Generate new private key" button. Ensure that Node.js is selected.
- Download the JSON file and add it to the root directory of this project. Rename the file to
firebaseServiceAccountKey.json
. - In your
.env
file, create an environment variable calledSERVICE_ACCOUNT_PATH
with the value./firebaseServiceAccountKey.json
.
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.
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
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.
Testing with Vitest
- Start the Docker container:
npm run test:dockerstart
- Run the tests:
npm run test
Testing GraphQL
-
Run
npm run generate
to generate the types locally -
Run
npm run dev
to start the local server -
Open your browser to http://localhost:3001/
-
Navigate to the Explorer section from the menu in the left pane.
-
Click the
+
button to see the fields a type has that can be added to the query -
Select the desired fields and they'll automatically get added to the query builder
-
If you select a type that requires an ID (such as
Facility
orHealthcareProfessional
) then add the ID in the "Variables" window at the bottom as a string.
- 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.
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:
- 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.
- In the Firebase Console, you should see a window labeled
Create or update indexes
. Click theSave
button: This will initiate the process of creating the index. Index creation might take a few minutes.
- Wait for the Index to be ready: Firestore will show the status of the index. Once it changes from
Building
toEnabled
, you can proceed to run your GraphQL query again.
- Run Your GraphQL Query Again: With the index in place, your query should now execute without any errors related to indexing.