mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-18 04:51:35 +03:00
b875d95a75
Co-authored-by: Aravind K P <8335904+scriptonist@users.noreply.github.com> GitOrigin-RevId: 8f6791d5fd51d011623361ac2f5994c8badb50bf
52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
package tables
|
|
|
|
import (
|
|
"path/filepath"
|
|
|
|
"github.com/hasura/graphql-engine/cli"
|
|
|
|
"gopkg.in/yaml.v2"
|
|
)
|
|
|
|
type V3MetadataTableConfig struct {
|
|
*TableConfig
|
|
}
|
|
|
|
func NewV3MetadataTableConfig(ec *cli.ExecutionContext, baseDir string) *V3MetadataTableConfig {
|
|
return &V3MetadataTableConfig{
|
|
&TableConfig{
|
|
MetadataDir: baseDir,
|
|
logger: ec.Logger,
|
|
},
|
|
}
|
|
}
|
|
func (t *V3MetadataTableConfig) Export(md yaml.MapSlice) (map[string][]byte, error) {
|
|
metadataBytes, err := yaml.Marshal(md)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var metadata struct {
|
|
Sources []struct {
|
|
Name string `yaml:"name"'`
|
|
Tables []yaml.MapSlice `yaml:"tables"`
|
|
} `yaml:"sources"`
|
|
}
|
|
var tables interface{}
|
|
if err := yaml.Unmarshal(metadataBytes, &metadata); err != nil {
|
|
return nil, err
|
|
}
|
|
if len(metadata.Sources) > 0 {
|
|
tables = metadata.Sources[0].Tables
|
|
}
|
|
if tables == nil {
|
|
tables = make([]interface{}, 0)
|
|
}
|
|
data, err := yaml.Marshal(tables)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return map[string][]byte{
|
|
filepath.Join(t.MetadataDir, MetadataFilename): data,
|
|
}, nil
|
|
}
|