Skip to content

Commit 30f51b6

Browse files
authored
chore(docs): cleanup and add JWT instructions to README (#66)
- remove local-supergraph-config.yaml as this file changes often locally - add local-supergraph-config.sample.yaml as a starting point for local dev
1 parent 4ec1844 commit 30f51b6

4 files changed

+120
-65
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ dist
33
.evn
44
.idea
55
.vscode/
6-
local-supergraph.graphql
6+
local-supergraph.graphql
7+
local-supergraph-config.yaml

README.md

+74-38
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,114 @@
11
# Admin API
22

3-
To get the federated schema for this service from the [Apollo Studio](https://studio.apollographql.com/), you need an API key.
4-
You can Obtain an API key from https://engine.apollographql.com/user-settings.
3+
The Admin API is a federated (read: combined) graph dedicated to powering internal Pocket tools - meaning any applications that are internal to pocket and not client/user facing. These applications may include admin tools, machine learning/data processes, and analytics processes.
54

6-
Create an environment variable named `APOLLO_KEY` and assign your API key to it before starting this service
5+
As of March 2022, the Admin API federates the following:
6+
7+
- All of [Prospect API](https://github.com/Pocket/prospect-api), as there are no public endpoints.
8+
- The admin graph of [Curated Corpus API](https://github.com/Pocket/curated-corpus-api).
9+
- The admin graph of [Collection API](https://github.com/Pocket/collection-api/).
10+
11+
Due to continued dependence on our Parser service, the Admin API also federates the `parser-graphql-wrapper`. (Yes, `parser-graphql-wrapper` is a part of both our public Client API and this private Admin API. Neat!)
712

813
## <a name="starting"></a> Starting the service
14+
15+
Note - after starting the service, you will still need to configure JWT authentication prior to being able to execute any operations through the GraphQL playground. JWT authentication is covered in the next section.
16+
17+
### Initial setup - Running against dev subgraphs
18+
919
- Install [docker](https://www.docker.com/) and [rover cli](https://www.apollographql.com/docs/rover/getting-started) if not already configured.
10-
- Run `npm ci` to install the project dependencies
20+
- Copy `./local-supergraph-config.sample.yaml` to `./local-supergraph-config.yaml` if you haven't already. By default this will connect you to the dev subgraphs.
21+
- Run `npm ci` to install the project dependencies.
1122
- Run `docker-compose up` to start the memcache container. Add the `-d` option to run the container in the background
12-
- Run `npm run start:dev` to start the application
23+
- Connect to Pocket VPN Dev
24+
- Run `npm run start:dev` to start the application.
25+
26+
### Running against local subgraphs
27+
28+
Eventually, you'll likely want to test against at least one local subgraph. To do so, get the subgraph(s) in question running locally (this is different for each subgraph - check those READMEs for more info). Once the subgraph is running locally, update `./local-supergraph-config.yaml` to point to the local URL of the subgraph(s) in question - local endpoints should already exist in comments in `./local-supergraph-config.sample.yaml`. (It's fine to have a mix of dev and local subgraph endpoints.) Re-start the service and you should be good to go.
29+
30+
If you are using _only_ local subgraphs, you do not need to be connected to Pocket VPN Dev.
31+
32+
### Running against prod subgraphs
33+
34+
It's not recommended to use production subgraphs, but if you have to, you can change the subgraph endpoints in `./local-supergraph-config.yaml` to point to production. You'll need to be on Pocket VPN Prod, and cannot use a mix of dev and prod subgraph endpoints.
35+
36+
## Authentication
37+
38+
All requests to the gateway require a valid JWT provided by our Cognito authentication service. You must pass this JWT as a header.
1339

14-
**Note**: To use the production subgraphs locally, you must be logged into the Pocket VPN.
40+
### Retrieving your JWT
1541

16-
## Working with subgraphs (federated services) locally
17-
- (Optional) Clone the repository of the subgraph(s) you intend to work with if you haven't already
18-
- Start the subgraph service(s) locally, ensure that the services are fully up and running at an endpoint
19-
- Grab the subgraph(s) endpoint(s) and update the `local-supergraph-config.yaml` file. Example:
20-
```yaml
21-
subgraphs:
22-
parser:
23-
routing_url: http://localhost:4001
24-
schema:
25-
subgraph_url: http://localhost:4001
26-
```
27-
- Start this service using the same steps from [Starting the service](#starting) above
42+
To retrieve your current JWT:
2843

29-
All requests through this gateway will now resolve to the local subgraph services.
44+
1. Access the curation tools dev site: https://curation-admin-tools.getpocket.dev/
45+
2. Complete the SSO login flow if asked
46+
3. Once you are able to select a tool (e.g. Collections, Curated Corpus), open up the browser dev tools (cmd+option+i) and select the "Storage" tab
47+
4. Expand Local Storage and find the entry for https://curation-admin-tools.getpocket.dev/
48+
5. Select the `auth` key and find the `id_token` value - this is the JWT you need
49+
50+
### Passing your JWT as a header
51+
52+
Once you've retrieved your JWT, open up the GraphQL playground for this servce at http://localhost:4027/. At the bottom of the left-hand panel where you write queries/mutations, click on **HTTP HEADERS** and enter the following:
53+
54+
```
55+
{
56+
"authorization": "Bearer YourVeryLongJWTGoesHere"
57+
}
58+
```
59+
60+
You should now be able to execute operations with the permissions granted to your Cognito user via Mozillian Groups. For more information on these groups, see our [Shared Data document](https://getpocket.atlassian.net/wiki/spaces/PE/pages/2584150049/Pocket+Shared+Data#Authentication-%26-Authorization).
3061

3162
## Gotchas
63+
3264
- This service uses memcache to cache query and mutation responses. If you are getting the same results when you expect something else, there's a good chance that the response is cached.
3365
- The easiest way to get around this is to flush the cache with `echo 'flush_all' | nc localhost 11211`
3466
- Restarting the memcache container also works to flush the cache
3567

3668
## Admin API Schema/Naming Conventions
3769

3870
The general principles guiding these are:
39-
* What are GraphQl's own recommendations (Looking at http://spec.graphql.org/)
40-
* What are the industry standards or standards used by the tools we use (Such as Apollo's recommendations: https://www.apollographql.com/docs/apollo-server/schema/schema/#naming-conventions)
41-
* What will have the best compatibility with naming conventions in languages that our primary consumers of the API (apps) will use, to reduce likelihood of them having to rename or adapt them.
71+
72+
- What are GraphQl's own recommendations (Looking at http://spec.graphql.org/)
73+
- What are the industry standards or standards used by the tools we use (Such as Apollo's recommendations: https://www.apollographql.com/docs/apollo-server/schema/schema/#naming-conventions)
74+
- What will have the best compatibility with naming conventions in languages that our primary consumers of the API (apps) will use, to reduce likelihood of them having to rename or adapt them.
4275

4376
### Casing
4477

4578
Use `PascalCase` for:
46-
* Definition names. Such as the names of types, enums, scalars, unions etc. (except directives, see below)
79+
80+
- Definition names. Such as the names of types, enums, scalars, unions etc. (except directives, see below)
4781

4882
Use `camelCase` for:
49-
* Field names
50-
* Argument names
51-
* Query and Mutation names
52-
* Directive names
83+
84+
- Field names
85+
- Argument names
86+
- Query and Mutation names
87+
- Directive names
5388

5489
Use `ALL_CAPS` for:
55-
* Enum options
5690

91+
- Enum options
5792

5893
### Acronyms & Abbreviations
5994

60-
For words like URL, HTTP, HTML, etc, do not uppercase all letters, just follow casing rules above.
95+
For words like URL, HTTP, HTML, etc, do not uppercase all letters, just follow casing rules above.
6196

6297
Some examples:
6398

6499
For types:
65-
* URL would be `Url`
66-
* HTML would be `Html`
67-
* ArticleHTML would be `ArticleHtml`
100+
101+
- URL would be `Url`
102+
- HTML would be `Html`
103+
- ArticleHTML would be `ArticleHtml`
68104

69105
For fields:
70-
* URL would be `url`
71-
* articleURL would be `articleUrl`
72-
* itemID would be `itemId`
73106

74-
For enums however, everything is already capitalized:
75-
* URL would be `URL`
76-
* articleURL would be `ARTICLE_URL`
107+
- URL would be `url`
108+
- articleURL would be `articleUrl`
109+
- itemID would be `itemId`
77110

111+
For enums however, everything is already capitalized:
78112

113+
- URL would be `URL`
114+
- articleURL would be `ARTICLE_URL`

local-supergraph-config.sample.yaml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# See https://www.apollographql.com/docs/federation/quickstart/#configuration-file
2+
# for more info
3+
subgraphs:
4+
parser-graphql-wrapper:
5+
routing_url: https://parser-graphql-wrapper.getpocket.dev/
6+
# schema defines the introspection endpoint - usually the same, but it could be different
7+
schema:
8+
subgraph_url: https://parser-graphql-wrapper.getpocket.dev/
9+
10+
# connect to collection api dev, or...
11+
collection-api:
12+
routing_url: https://collection-api.getpocket.dev/admin
13+
schema:
14+
subgraph_url: https://collection-api.getpocket.dev/admin
15+
16+
# ...see local setup instructions at https://github.com/Pocket/collection-api
17+
#collection-api:
18+
# routing_url: http://localhost:4004/admin
19+
# schema:
20+
# subgraph_url: http://localhost:4004/admin
21+
22+
# connect to prospect api on dev, or...
23+
prospect-api:
24+
routing_url: https://prospect-api.getpocket.dev/
25+
schema:
26+
subgraph_url: https://prospect-api.getpocket.dev/
27+
28+
# ...see local setup instructions at https://github.com/Pocket/prospect-api
29+
#prospect-api:
30+
# routing_url: http://localhost:4026/
31+
# schema:
32+
# subgraph_url: http://localhost:4026/
33+
34+
# connect to curated corpus api on dev, or...
35+
curated-corpus-api:
36+
routing_url: https://curated-corpus-api.getpocket.dev/admin
37+
schema:
38+
subgraph_url: https://curated-corpus-api.getpocket.dev/admin
39+
40+
# ...see local setup instructions at https://github.com/Pocket/curated-corpus-api/
41+
#curated-corpus-api:
42+
# routing_url: http://localhost:4025/admin
43+
# schema:
44+
# subgraph_url: http://localhost:4025/admin

local-supergraph-config.yaml

-26
This file was deleted.

0 commit comments

Comments
 (0)