Skip to content

Commit

Permalink
feat: Hasura configurations for public access (#1865)
Browse files Browse the repository at this point in the history
* This will run metadata sync and update to allow public access
* Updated the README for instructions on how to run as well
  • Loading branch information
ryscheng authored Jul 28, 2024
1 parent 7b0369f commit cf3a451
Show file tree
Hide file tree
Showing 25 changed files with 300 additions and 36 deletions.
55 changes: 43 additions & 12 deletions apps/hasura3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ _Note: This only works for Hasura version 3 (aka DDN)._

## Setup

### Install `ddn`

First install the `ddn` CLI tool from Hasura

```bash
curl -L https://graphql-engine-cdn.hasura.io/ddn/cli/v3/get.sh | bash
```

### Configure environment

Copy `.env.example` to `.env` and set the environment variables as needed.
You can get your Hasura PAT by running

Expand All @@ -19,33 +29,54 @@ In `./oso_subgraph/`, copy `.env.oso_subgraph.example` to `.env.oso_subgraph.clo

In `./oso_subgraph/connector/oso_clickhouse`, copy `.env.example` to `.env.cloud` and `.env.local`. Populate with Clickhouse credentials.

### Build

```bash
pnpm install
pnpm build
```

## Sync schema with Clickhouse

## Configure
First, start a local Hasura instance. This is required to run the Clickhouse connector.

```bash
pnpm start
```

In a separate terminal, pull the latest Clickhouse schema

```bash
pnpm sync
```

You can modify any files to update the Hasura configuration.
## Configure metadata

From here, you can modify any files to update the Hasura configuration.
See the
[Hasura docs](https://hasura.io/docs/3.0/) to learn more.

Note that anything in `./oso_subgraph/metadata/` will be overwritten by the build step.

## Build
We include a script for automatically modifying the metadata
in `./src/cli.ts`. This will currently just make all models
publicly available.

This will idempotently update table configurations for all tables found in the Clickhouse database.
This needs to be run every time the schema changes.
For more information, see `./src/cli.ts`.
To run this script

```bash
pnpm build
pnpm metadata:update
```

## Deploy

To reload the database schemas and apply the metadata configurations, run:
To apply the metadata configurations to Hasura cloud, run:

```bash
pnpm run deploy
```

For more information on how to manage metadata, see the
[Hasura guide](https://hasura.io/docs/latest/migrations-metadata-seeds/manage-metadata/#reload-metadata).
This will output a build ID, which you'll need to apply as default:

```bash
ddn supergraph build apply BUILD_ID
# ddn supergraph build apply 030c5f3ce0
```
2 changes: 1 addition & 1 deletion apps/hasura3/globals/auth-config.cloud.hml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ definition:
mode:
webhook:
url: https://www.opensource.observer/api/v1/auth
method: GET
method: Get
16 changes: 15 additions & 1 deletion apps/hasura3/oso_subgraph/metadata/ArtifactsByProjectV1.hml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ definition:
- projectName
- projectNamespace
- projectSource
- role: anonymous
output:
allowedFields:
- artifactId
- artifactName
- artifactNamespace
- artifactSource
- artifactSourceId
- projectId
- projectName
- projectNamespace
- projectSource

---
kind: ObjectBooleanExpressionType
Expand Down Expand Up @@ -168,4 +180,6 @@ definition:
- role: admin
select:
filter: null

- role: anonymous
select:
filter: null
13 changes: 12 additions & 1 deletion apps/hasura3/oso_subgraph/metadata/ArtifactsV1.hml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ definition:
- artifactSource
- artifactSourceId
- artifactUrl
- role: anonymous
output:
allowedFields:
- artifactId
- artifactName
- artifactNamespace
- artifactSource
- artifactSourceId
- artifactUrl

---
kind: ObjectBooleanExpressionType
Expand Down Expand Up @@ -132,4 +141,6 @@ definition:
- role: admin
select:
filter: null

- role: anonymous
select:
filter: null
28 changes: 27 additions & 1 deletion apps/hasura3/oso_subgraph/metadata/CodeMetricsByProjectV1.hml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,30 @@ definition:
- projectSource
- repositoryCount
- starCount
- role: anonymous
output:
allowedFields:
- activeDeveloperCount6Months
- closedIssueCount6Months
- commitCount6Months
- contributorCount
- contributorCount6Months
- displayName
- eventSource
- firstCommitDate
- forkCount
- fulltimeDeveloperAverage6Months
- lastCommitDate
- mergedPullRequestCount6Months
- newContributorCount6Months
- openedIssueCount6Months
- openedPullRequestCount6Months
- projectId
- projectName
- projectNamespace
- projectSource
- repositoryCount
- starCount

---
kind: ObjectBooleanExpressionType
Expand Down Expand Up @@ -312,4 +336,6 @@ definition:
- role: admin
select:
filter: null

- role: anonymous
select:
filter: null
13 changes: 12 additions & 1 deletion apps/hasura3/oso_subgraph/metadata/CollectionsV1.hml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ definition:
- collectionSource
- description
- displayName
- role: anonymous
output:
allowedFields:
- collectionId
- collectionName
- collectionNamespace
- collectionSource
- description
- displayName

---
kind: ObjectBooleanExpressionType
Expand Down Expand Up @@ -132,4 +141,6 @@ definition:
- role: admin
select:
filter: null

- role: anonymous
select:
filter: null
10 changes: 9 additions & 1 deletion apps/hasura3/oso_subgraph/metadata/ContractsV0.hml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ definition:
- artifactSource
- contractAddress
- rootDeployerAddress
- role: anonymous
output:
allowedFields:
- artifactSource
- contractAddress
- rootDeployerAddress

---
kind: ObjectBooleanExpressionType
Expand Down Expand Up @@ -96,4 +102,6 @@ definition:
- role: admin
select:
filter: null

- role: anonymous
select:
filter: null
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ definition:
- projectName
- projectNamespace
- projectSource
- role: anonymous
output:
allowedFields:
- eventSource
- eventType
- eventfulDayCount
- firstEventDate
- lastEventDate
- projectId
- projectName
- projectNamespace
- projectSource

---
kind: ObjectBooleanExpressionType
Expand Down Expand Up @@ -168,4 +180,6 @@ definition:
- role: admin
select:
filter: null

- role: anonymous
select:
filter: null
8 changes: 7 additions & 1 deletion apps/hasura3/oso_subgraph/metadata/EventTypesV1.hml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ definition:
output:
allowedFields:
- eventType
- role: anonymous
output:
allowedFields:
- eventType

---
kind: ObjectBooleanExpressionType
Expand Down Expand Up @@ -72,4 +76,6 @@ definition:
- role: admin
select:
filter: null

- role: anonymous
select:
filter: null
11 changes: 10 additions & 1 deletion apps/hasura3/oso_subgraph/metadata/EventsDailyToArtifact.hml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ definition:
- artifactId
- bucketDay
- eventType
- role: anonymous
output:
allowedFields:
- amount
- artifactId
- bucketDay
- eventType

---
kind: ObjectBooleanExpressionType
Expand Down Expand Up @@ -108,4 +115,6 @@ definition:
- role: admin
select:
filter: null

- role: anonymous
select:
filter: null
11 changes: 10 additions & 1 deletion apps/hasura3/oso_subgraph/metadata/EventsDailyToCollection.hml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ definition:
- bucketDay
- collectionId
- eventType
- role: anonymous
output:
allowedFields:
- amount
- bucketDay
- collectionId
- eventType

---
kind: ObjectBooleanExpressionType
Expand Down Expand Up @@ -108,4 +115,6 @@ definition:
- role: admin
select:
filter: null

- role: anonymous
select:
filter: null
11 changes: 10 additions & 1 deletion apps/hasura3/oso_subgraph/metadata/EventsDailyToProject.hml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ definition:
- bucketDay
- eventType
- projectId
- role: anonymous
output:
allowedFields:
- amount
- bucketDay
- eventType
- projectId

---
kind: ObjectBooleanExpressionType
Expand Down Expand Up @@ -108,4 +115,6 @@ definition:
- role: admin
select:
filter: null

- role: anonymous
select:
filter: null
11 changes: 10 additions & 1 deletion apps/hasura3/oso_subgraph/metadata/EventsMonthlyToArtifact.hml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ definition:
- artifactId
- bucketMonth
- eventType
- role: anonymous
output:
allowedFields:
- amount
- artifactId
- bucketMonth
- eventType

---
kind: ObjectBooleanExpressionType
Expand Down Expand Up @@ -108,4 +115,6 @@ definition:
- role: admin
select:
filter: null

- role: anonymous
select:
filter: null
11 changes: 10 additions & 1 deletion apps/hasura3/oso_subgraph/metadata/EventsMonthlyToCollection.hml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ definition:
- bucketMonth
- collectionId
- eventType
- role: anonymous
output:
allowedFields:
- amount
- bucketMonth
- collectionId
- eventType

---
kind: ObjectBooleanExpressionType
Expand Down Expand Up @@ -108,4 +115,6 @@ definition:
- role: admin
select:
filter: null

- role: anonymous
select:
filter: null
Loading

0 comments on commit cf3a451

Please sign in to comment.