# graphql-switchboard

## Prerequisites

It will probably be useful for you to be a member of [the current `application_family`](https://github.com/theorchard/terraform-infra/blob/master/qa/switchboard/variables.tf).

1. Make sure you have [nvm](https://github.com/nvm-sh/nvm/blob/master/README.md).
2. We are using private npm packages from our [monorepo](https://github.com/theorchard/orchard-suite) and packagecloud.io registry.
   That means you need a valid access token for each of them.
   Follow this guide on how to setup NPM access.
   https://www.notion.so/Javascript-Package-Management-Setup-9553d5d491c94835aa787fdf0fc4838d
3. Familiarize yourself with [GraphQL at The Orchard](https://github.com/theorchard/docs/tree/master/graphql) before contributing!


## Setup

```bash
# use supported node version
nvm use node24
npm install -g pnpm@10.33.0

# install dependencies
pnpm install

# create environment configuration
cp .env.shadow .env

# start your server
pnpm run start
```

```shell
AWS_ACCESS_KEY_ID=SET_ME
AWS_SECRET_ACCESS_KEY=SET_ME
AUTH0_CREDENTIALS=SET_ME
```

> [!WARNING]
> For all 3 values you will need to get these from someone on the Switchboard team or the Systems team. FIX

## Testing

```shell
pnpm run test
pnpm run test:integration
```
## Linting

```shell
pnpm run lint
pnpm run lint:fix
```
## Local Development

Set your `Environment=dev` so it ignores the access token check and then run the app using:
```shell
pnpm run dev
```

Open `http://localhost:8080/graphql`, and run one of the example queries from integration tests:

* [`getParticipantByLocalId`](https://github.com/theorchard/graphql-switchboard/blob/7f1794ddc3c8e335e46af6866321bdd3c6ec1dab/integration_tests/project.test.js#L23-L32)
* [`getProjectSearch`](https://github.com/theorchard/graphql-switchboard/blob/7f1794ddc3c8e335e46af6866321bdd3c6ec1dab/integration_tests/project.test.js#L8-L20)
* [`getProjectByLocalId`](https://github.com/theorchard/graphql-switchboard/blob/7f1794ddc3c8e335e46af6866321bdd3c6ec1dab/integration_tests/participant.test.js#L9-L20)

[!WARNING]
put in these HTTP headers if you want to test JWT token access check. Normally with `Environment=dev` you can make graphql requests to localhost without x-token.

> ```json
> {
>   "x-token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.> eyJ1c2VySWQiOjQsInN5c3RlbU5hbWUiOiJTV0lUQ0hCT0FSRCIsInNlY3JldElkIjoiMzQwY2U2YmItODVkMi00OTQzLWFmODktNjNjYWQzODRjMGQxIiwiaWF0IjoxNTYzNzczMzkzLCJleHAiOjE2NjQzNzgxOTN9.Nu4VR_dhpf1Ww5RO4adoUgDWsafVGf1GlcT2uvLWRQQ"
> }
> ```

## Issuing QA JWT tokens

Run [`scripts/token.sh`](scripts/token.sh). This script assumes a role on the GRPS side of things, then exports the `qa-system-jwt-secret` secret from secrets manager. You will need to have `awsume` configured (as found [here](https://www.notion.so/AWS-Access-f841b9dd815d4443a80e96a86c92cd2f?pvs=4#beaec95488ad4473899a26a2b8cf603f)), and install the `jq` dependency:

```shell
brew install jq
```

```shell
./scripts/token.sh
{
    "ARN": "arn:aws:secretsmanager:us-east-1:662302927201:secret:qa-system-jwt-secret-FH9GOn",
    "Name": "qa-system-jwt-secret",
    "SecretString": "SecretSecretSecret",
    "VersionStages": [
        "AWSCURRENT"
    ],
    "CreatedDate": "2019-07-15T05:49:44.729000-04:00"
}
```
