It proved to be enormously difficult to aggregate GraphQL results across multiple endpoints and date ranges (due to limitations with Graph Protocol pagination). The code in this monorepo seeks to address that.
The monorepo contains two components:
- apps/
- server/
- Code to configure and deploy a Wundergraph API server that aggregates and transforms GraphQL results
- Offers a number of 'operations' (in Wundergraph terminology):
- Earliest: the earliest record from each blockchain
- earliest/metrics
- earliest/tokenRecords
- earliest/tokenSupplies
- Latest: the latest record from each blockchain
- latest/metrics
- latest/tokenRecords
- latest/tokenSupplies
- Paginated: records from the
startDate
input variable until the present. Aggregates all blockchains and handles pagination. SpecifycrossChainDataComplete
to restrict results up to the latest date with cross-chain data. SpecifyincludeRecords
to include records used to calculate each metric (large response size).- paginated/metrics
- paginated/tokenRecords
- paginated/tokenSupplies
- Earliest: the earliest record from each blockchain
- client/
- Generates a React-compatible client that can be used in olympus-frontend
- Publishes the client to NPM
- server/
The API server is currently hosted on Google Cloud Run, with Firebase Hosting to provide a static domain name.
HTTP-layer caching is provided by Google Cloud Run. An attempt was made to utilise caching in Redis (on Upstash), but it performed slower than the OOTB HTTP-layer caching. It can be enabled through the CACHE_ENABLED
environment variable.
The repo is setup using turbo to make handling tasks easier.
- Run
yarn
in the root directory. - Copy
.env.sample
to.env
and replace any required values
During local development, you can trigger a build with yarn build:local
. This requires the setup tasks to have been completed.
yarn build
requires an environment variable to be set, and is used in the Wundergraph Cloud deploy process.
During local development, you can run an API endpoint locally with yarn server:start
.
This requires environment variables to be set, so follow the instructions in setup.
Run yarn test:local
.
This requires environment variables to be set, so follow the instructions in setup.
Running the frontend against a different API endpoint requires jumping through some (small) hoops:
- Run the API endpoint locally. See Running.
- Pass the API endpoint to the frontend:
VITE_WG_PUBLIC_NODE_URL=http://localhost:9991 yarn start
Orchestration is performed using Pulumi. To deploy, follow these steps:
- Change to the
apps/server
directory. - Authenticate with Pulumi, using
pulumi login
- Run
pulumi up --stack <dev | prod>
NOTE: the Upstash credentials in the production project and environment should be different to that of all other projects/environments, so that the production cache is not polluted.
-
Set the required values in
.env.prod
-
Authenticate with the NPM package registry:
npm login
-
Update the
version
inapps/client/package.json
-
Update the changelog
-
Run the following command:
yarn publish-package
- Prefix the command with
YARN_OTP=<OTP VALUE>
- Prefix the command with
NOTE: You must be a member of the @olympusdao
org in NPM in order to publish.
- When testing/developing new subgraph versions, it would be nice to be able to provide a URL parameter with the subgraph deployment ID and have the Typescript operation use that deployment ID instead of the configured data source.