Use this template to quickly build and deploy a Federated demo environment.
Use the included setup tool (make setup
) whenever possible as it saves
your information and can be re-run multiple times to update .env
files
and cloudbuild.yaml
files.
- Check out this repository (forking is disabled, sorry)
- Install Docker for Mac
- Install Homebrew & Python 3: https://docs.python-guide.org/starting/install3/osx/
- Install NVM for Mac: https://tecadmin.net/install-nvm-macos-with-homebrew/
- Install NodeJS v16.13.1 using NVM:
nvm install v16.13.1
- Use NodeJS v16.13.1:
nvm use v16.13.1
- Install the Apollo CLI: https://www.apollographql.com/docs/devtools/cli/
- Install the Rover CLI: https://www.apollographql.com/docs/rover/
- Log into Studio and create a Deployed Graph, get an API Key and note your Graph ID and Variant ID
- Run
make install-deps
to install npm packages for each subgraph and to rename dot_env to .env and cloudbuild.yaml.tmpl to cloudbuild.yaml (this will overwrite current files butmake setup
will restore them) - Edit the .env file in ./gateway, ./subgraph1, ./subgraph2, ./subgraph3 to fill in the appropriate variables OR use the setup tool by typing
make setup
make run-local-unmanaged
- Publish your schemas to Apollo
- Edit the
ROUTING_URL
in each of the subgraph directories.env
file: ./subgraph1, ./subgraph2, ./subgraph3 OR runmake setup
again to set them (recommended). - Publish your graph with
make publish
- Edit the
- Deploy locally:
make run-local-managed
- Install the Google Cloud CLI: https://cloud.google.com/sdk/docs/quickstart
- Login to the Google Cloud Console and create a new project
- Go to https://console.cloud.google.com/
- Find the "Sales Engineering" folder by searching in the drop down and then click "New Project" the "Location" needs to be "Sales Engineering"
- Name your new project
<your-last-name>-demo
- In your new project click on the menu and select "Cloud Run" from the list.
- Click "Enable Cloud Run API"
- In your new project click on the menu and select "Cloud Build" from the list.
- Under the "Settings" area enable the "Cloud Run Admin" Role.
- Authenticate with Google Cloud from a terminal on your Mac using your Apollo email:
gcloud init
(if you ever need to change your default Project ID (this might be different from the project name so always use the ID) use the commandgcloud config set project <project-ID>
) - In the folder ./gateway, ./subgraph1, ./subgraph2, and ./subgraph3 folders edit the
cloudbuild.yaml
file to use your correct project ID (replace the <CHANGE_ME> in each of those) OR use the setup tool by typingmake setup
(recommended)
- Deploy your gateway and subgraphs with
make deploy
- Check the Google Cloud Run Console to see the URLs for each of your services and your gateway.
- Update the
.env
files in ./subgraph1, ./subgraph2, ./subgraph3 to have the rightROUTING_URL
that you got from Cloud Run dashboard OR use the setup tool by typingmake setup
- Run
make publish
(this will runmake publish
in each of your subgraph directories, you can also run those one by one) - Update studio with the right URL for your gateway.
Steps 2, 3, and 5 should only need to be done the first time. After that you can just use make deploy
and make publish
- Enable Cloud Functions by going to that tab in the Google Cloud Console
- Go to Cloud Build->Settings and enable the "Cloud Functions" service account
- Edit the client/client.py file to put in the URL of your gateway (must be deployed, not local)
- Run
make traffic-gen
it may ask you to enable some things like AppEngine, say (y)es - If you need to re-deploy your client for any reason go into the
client
directory and runmake deploy
- Update the
client/client.py
file to have the right URL for your gateway (if you change your schema you will need to update the queries in this file). - Update the
.github/workflows/client_gen.yaml
file to have the correct cron string. - Commit and deploy your code to your forked repo and GitHub Actions will start generating traffic for your site.
- .github/ - configuration for GitHub Actions (CI/CD)
- client/ - a simple client app to send GQL queries to your demo
- gateway/ - the Apollo Gateway for this demo
- subgraph1/ - a subgraph for this demo
- subgraph2/ - a subgraph for this demo
- subgraph3/ - a subgraph for this demo
- .gitignore - files that git should not manage
- local-test-unmanaged.yaml - a config file for Docker Compose to run an unmanaged Federation demo
- local-test.yaml - a config file for Docker Compose to run a managed Federation demo
- Makefile - a collection of command shortcuts
- supergraph.yaml - the config file that Rover uses to create a supergraph offline (ie, without Studio)
Change the schemas for each of the subgraphs and update the data in the database.json
files. In each server.js
make sure you have the right resolvers for the queries and/or mutations on your graph.