Files

70 lines
2.9 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# graphql-api-js
Apollo graphql api server for Photowall
This servers runs in two instances on AWS. `graphql.photowall.com` is used for photowall admin. `data.photowall.com` is used by the website (client).
When clients want to use the public `data.photowall.com` they use the `/login` REST endpoint to retreive a BearerToken with restricted cognito scopes. They can then access certain product and designer information with the token.
Third party systems like Unbox (Synergy) will use the `graphql.photowall.com` to read their data like they are doing now. This is to make sure the website wont be affected by larger downloads of data like unbox does. Unbox has their own cognito app client with limited scopes.
## Running queries on staging or production servers
To tests staging or production servers its possible to run the login rest endpoint to get a Bearer access token. Check SSM for the stacks
`${EnvironmentName}/GRAPHQL_WEB_CLIENT_USERNAME` and `${EnvironmentName}/GRAPHQL_WEB_CLIENT_PASSWORD` and use those as Basic auth for the /login route. To get a token from admin go to the route /auth/token. You can then use that token as a Bearer token in apps like Insomnia.
## Running it locally
### .env file
Create an .env file in repo root (see .env.example for what to set). Depending on which resolvers you are going to use different environment variables are needed. Begin by setting DATABASE_URL at least, the rest can be added as needed.
Notes:
COGNITO_LOGIN_CLIENT_ID and COGNITO_LOGIN_CLIENT_SECRET found in cognito `photowall-test-staff` pool. In `photowall-web-test-client` app but are only needed for testing or using the /login route to get proper Bearer authentication.
### Development
This project runs in docker, so when developing start the docker environment and it will restart automatically when .graphql (schema) or .ts files are changed.
Run
```
$ npm install
$ docker compose build
$ docker compose up
```
For testing use a tool like Insomnia or similar. Server is running on http://localhost:4000/ and to
connect you need to use `basic auth` with username and password from "GraphQl Basic Auth" in lastpass.
If you wish the Bearer Token used in prodlike environment also works. See note under ".env file: above.
If you don't have access to photowall shared lastpass please contact any colleague.
If you use Insomnia ask a colleague for the queries that can be exported/imported from Insomnia.
#### Publish feature branch to staging
Run `make publish-to-staging`. Please note that further commits on the same branch will not be updated automatically and the same command must be run again if changes are made.
### Run prod-like container locally
Run
```
$ docker compose -f docker-compose-prodlike.yml build
$ docker compose -f docker-compose-prodlike.yml up
```
To access it you must use the login endpoint to get a Bearer token
## Run tests
Tests
```
npm test
```
### Force update staging
update 5