# graphql-product

### Best Practices & Standards

**Please** familiarize yourself with our [GraphQL conventions](/docs/graphql.md) for this project before contributing!

### GraphQL Maintainers
We are thrilled by this adoption of GraphQL at The Orchard and want to encourage more of it. Part of that is ensuring that we keep the code base healthy. This project is still young. We've establish some good patterns and practices that we want to spread. We also expect that these will evolve and expand as we learn more. To that end we are introducing a special process for this repo, at least to get us through the adoption phase.

The GraphQL Maintainers group will be responsible for staying up-to-date on the latest practices as defined above and providing quality reviews to make sure those practises are being followed (or changed if they don't work for some new situation).

**PRs to graphql-product require an approval from a GraphQL Maintainer.** Other reviews from non-maintainers are welcome and encouraged, but an R+ is mandatory before merging. Once you have the R+ you are free to merge the PR yourself.

The GraphQL Maintainers are defined in the [graphql-maintainers github group](https://github.com/orgs/theorchard/teams/graphql-maintainers/members). A graphql maintainer will now automatically be added as a reviewer on all PRs via github's [codowner](.github/CODEOWNERS) functionality.

#### How to be added as a GraphQL Maintainer
tbd

### Running locally

1. Make sure that you have `nodejs` installed on your system
2. Install project dependencies

```
$ yarn install
```

3. Copy the `.env.shadow` file to `.env`:

```
$ cp .env.shadow .env
```

**Note**: You will probably want to change the `NODE_ENV` environment variable in your `.env` file
from `dev` to `qa`, as there does not currently appear to be an `ows-search` microservice available
in the development environment.

3. Run local server.
```
$ export Environment=qa && yarn start
``` 
4. Open your web browser [http://localhost:8080/graphql](http://localhost:8080/graphql) and make some queries.

**Important**: You need to provide Grass headers with account type and id. Click "Headers" tab in the UI:

For vendors paste this snippet:
```
{
  "Grass-Account-Type": "vendor",
  "Grass-Account-Id": 15554
}
```

For ArtistProfiles paste this snippet:
```
{
  "apollographql-client-name": <frontend-repo-name>,
  "Orchard-Identity-Id": <auth0-token>,
  "Orchard-Profile-Type": "ArtistProfile",
  "Orchard-Profile-Id": <profile-id>
}
```
For the above
- The ```apollographql-client-name``` valid values can be found in src/constants/applications.js in the APPLICATION_MAP object.
- The ```auth0-token``` and ```profile-id``` can be found by decoding your jwt token.


Example query:
```
{
  allProductsSearch(limit: 5, status: "in_content")
  {
    totalCount
    products {
      productId
      productName
      tracks {
        tuid
        trackName
        primaryArtists {
          artistName
        }
      }
    }
  }
}
```

### Request Logging

To enable request logging, set `TRACING=true` in your `.env` file.

### Tests and Linting

Utilize the following `yarn` task to perform testing and linting:

```
yarn test                   # Run the unit tests and linter
yarn lint:js                # Run the linter
yarn test:unit              # Run the unit tests
yarn test:integration       # Run the integration tests
```
