Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/hasura config #23

Merged
merged 15 commits into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build/metadata/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ COPY ./cmd/metadata/mappings ./mappings
COPY ./cmd/metadata/graphql ./graphql
COPY ./build/*.yml ./
COPY ./cmd/metadata/views/*.sql ./views/
COPY ./cmd/metadata/custom_hasura_config ./custom_hasura_config

ENTRYPOINT ["/go/bin/dipdup-metadata"]
1 change: 1 addition & 0 deletions cmd/metadata/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func (c *Config) Substitute() error {
return err
}
}
c.Config.Hasura.SetSourceName()
852Kerfunkle marked this conversation as resolved.
Show resolved Hide resolved
return nil
}

Expand Down
Empty file.
46 changes: 44 additions & 2 deletions cmd/metadata/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ func main() {
return
}

if err := hasura.Create(ctx, cfg.Hasura, cfg.Database, views, new(models.TokenMetadata), new(models.ContractMetadata)); err != nil {
custom_configs, err := readCustomHasuraConfigs(ctx, cfg.Database)
if err != nil {
log.Err(err).Msg("readCustomHasuraConfigs")
return
}

if err := hasura.Create(ctx, cfg.Hasura, cfg.Database, views, custom_configs, new(models.TokenMetadata), new(models.ContractMetadata)); err != nil {
log.Err(err).Msg("hasura.Create")
}
})
Expand Down Expand Up @@ -109,7 +115,13 @@ func main() {
return
}

if err := hasura.Create(ctx, cfg.Hasura, cfg.Database, views, new(models.TokenMetadata), new(models.ContractMetadata)); err != nil {
custom_configs, err := readCustomHasuraConfigs(ctx, cfg.Database)
if err != nil {
log.Err(err).Msg("readCustomHasuraConfigs")
return
}

if err := hasura.Create(ctx, cfg.Hasura, cfg.Database, views, custom_configs, new(models.TokenMetadata), new(models.ContractMetadata)); err != nil {
log.Err(err).Msg("hasura.Create")
}
})
Expand Down Expand Up @@ -212,3 +224,33 @@ func createViews(ctx context.Context, database golibConfig.Database) ([]string,

return views, nil
}

func readCustomHasuraConfigs(ctx context.Context, database golibConfig.Database) ([]hasura.Request, error) {
852Kerfunkle marked this conversation as resolved.
Show resolved Hide resolved
files, err := ioutil.ReadDir("custom_hasura_config")
if err != nil {
return nil, err
}

custom_configs := make([]hasura.Request, 0)
for i := range files {
if files[i].IsDir() || strings.HasPrefix(files[i].Name(), ".") {
continue
}

path := fmt.Sprintf("custom_hasura_config/%s", files[i].Name())
raw, err := ioutil.ReadFile(path)
852Kerfunkle marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return nil, err
}

conf := hasura.Request{}

err = json.Unmarshal([]byte(raw), &conf)
if err != nil {
return nil, err
}
custom_configs = append(custom_configs, conf)
}

return custom_configs, nil
}