# graphql-user

**Please familiarize yourself with [GraphQL at The Orchard](https://github.com/theorchard/docs/tree/master/graphql) before contributing!**

## Running

- Use the correct version of node via nvm: `nvm use`
- Install dependencies: `yarn install --frozen-lockfile`
- Copy the `.env.shadow` file to `.env` and fill in your information:
  `cp .env.shadow .env`. Add your Neo4j QA credentials to the `.env` file.
- If you are using local split, create a default split file on your home directory:
  `touch ~/.split`
- Run the server: `yarn start`
- Open your browser at [http://localhost:8080/graphql](http://localhost:8080/graphql)

### AWS Credentials and JWT Configuration

It is recommended to run `awsume prod` before starting the server. This provides AWS credentials needed for JWT validation and integration tests that require generating authorization headers (JWTs).

Set `ENABLE_JWT_SERVICE_CACHE=true` in your `.env` file to enable JWT caching. This is required for:

- Running integration tests that need to generate authorization headers
- Running the service-deploy docker compose setup

### Running with Docker Compose (service-deploy)

To run the service in a configuration that reflects the actual deployed service in QA, use the service-deploy docker compose setup. This requires `ENABLE_JWT_SERVICE_CACHE=true` to be set in your `.env` file and valid AWS credentials (via `awsume prod`).

## Running graphql-service with frontend service

1. This service uses jwt-service-handler private package. The package defaults to use QA auth0 creds for jwt token validation on local graphql setup. Make sure to use qa auth0 creds in your frontend service local setups so that they generate QA jwt and pass on in graphql calls.

## Testing

Run unit tests:
`yarn test:unit`

Run integration tests:

- you must have a running `graphql-user` service to run integration tests. Follow the **Running **instructions above before using the below command.
  `yarn test:integration`

### Running Permissions Platform integration tests

Tests that interact with [ows-pdp](https://github.com/theorchard/ows-pdp) must have a valid bearer token. Complete the following steps to run those tests locally.

**In Terminal 1**

- Update the following values in `.env`

```
ENABLE_JWT_SERVICE_CACHE=true
ENV=qa
```

- Run `awsume prod`

- Run the server using `yarn start`. Verify the startup logs include:

```
Cached JWT enabled list on server start: ...
```

**In Terminal 2**

- Run `awsume prod`
- Run `yarn test:integration -t "Add user identity mutation"` or `yarn test:integration -t "Edit User Identity mutation"`.
