# graphql-account

GraphQL Service for Account

## Prerequisites

1. Make sure you have [nvm](https://github.com/nvm-sh/nvm/blob/master/README.md) and [yarn](https://yarnpkg.com/) installed.
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

This service interacts with endpoints that require JWT tokens in Authorization headers.

```bash
# use supported node version 22.20.0
nvm use 22.20.0

# install dependencies
corepack enable pnpm # if you don't have corepack enabled

pnpm i

# create environment configuration
cp .env.shadow .env

# Run awsume prod. AWS credentials are required to get the JWT enabled service list from secrets manager.
awsume prod

# start your server
pnpm start
```

## Available Scripts

In the project directory, you can run:

### `pnpm start`

Runs the app in the development mode.
Open http://localhost:8080/graphql to view the playground in the browser.
The server will reload if you make edits.

**NOTES:**

**Running the project locally requires an active VPN connection.**

**If you are not part of the `user-platform` application family, then you will not be able to start this service locally.
You will need to comment out the openSearch connector in src/connectors/index.ts.**

### `pnpm test:unit --watch`

Runs the jest unit tests in watch mode. In watch mode type `p` to enter a filter.

### `pnpm test:integration`

Runs the jest integration tests against a local instance. **Note** that you need to run `yarn start` in a different process first.

### `pnpm test`

Runs unit and integration tests. Run this before creating a PR.

### `pnpm lint`

Runs the js and graphql schema linter. Run this before creating a PR.

### `yarn build`

Builds the app for production to the `build` folder.<br />

Note that this command is not required to run locally, it is run during the docker build steps.

## Running `Query.accounts` locally

To run `Query.accounts` locally, you must have valid AWS credentials to assume the correct role (`arn:aws:iam::591204808501:role/permissions-platform-role`) that has an Opensearch access policy attached.

In terminal:

-   Run `awsume prod`
-   Run `awsume permissions-platform-qa`

To configure the `permissions-platform-qa` profile, follow the steps in this [notion doc](https://www.notion.so/AWS-Access-f841b9dd815d4443a80e96a86c92cd2f?pvs=4#2796c2b2b6a349d2b193941db9165932).
Then you should be able to run `yarn start` and use the `accounts` query.

## Docker

It is a good idea to run the service in production mode to ensure it behaves as expected when deployed.
To run the `service-deploy` service in production mode, follow these steps:

-   Production Mode : The service builds the project using `yarn build`.
-   JWT Cache Configuration: the `ENABLE_JWT_SERVICE_CACHE` environment variable is set to `true`. This requires valid AWS credentials.
-   Assume the correct AWS role: before starting the service, run the following command to assume the appropriate AWS role: `awsume prod`.
