Skip to content

Commit

Permalink
fix up cmd args to work with jsonschemagraph changes
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewpeterkort committed Dec 11, 2024
1 parent 146c50e commit b772ede
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
25 changes: 23 additions & 2 deletions cmd/schema/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/bmeg/grip/util/rpc"
"github.com/bmeg/jsonschemagraph/schconv"
"github.com/spf13/cobra"
goyaml "gopkg.in/yaml.v3"
)

var host = "localhost:8202"
Expand All @@ -21,6 +22,7 @@ var graphName string
var writeSchema bool = false
var jsonSchemaFile string
var yamlSchemaDir string
var configPath string
var sampleCount uint32 = 50
var excludeLabels []string

Expand Down Expand Up @@ -64,6 +66,10 @@ var getCmd = &cobra.Command{
},
}

type Config struct {
DependencyOrder []string `yaml:"dependency_order"`
}

var loadGqlSchemafromJsonSchema = &cobra.Command{
Use: "graphql",
Short: "Load graph schemas",
Expand All @@ -79,9 +85,23 @@ var loadGqlSchemafromJsonSchema = &cobra.Command{
return err
}

config := Config{DependencyOrder: []string{}}
if configPath != "" {
data, err := ioutil.ReadFile(configPath)
if err != nil {
log.Errorf("Failed to read YAML file: %v", err)
}
err = goyaml.Unmarshal(data, &config)
if err != nil {
log.Errorf("Failed to parse YAML file: %v", err)
}
} else {
fmt.Printf("Warning: No config file was provided, all vertices will be rendered has queries")
}

if jsonSchemaFile != "" && graphName != "" {
log.Infof("Loading Json Schema file: %s", jsonSchemaFile)
graphs, err := schconv.ParseGraphFile(jsonSchemaFile, "jsonSchema", graphName)
graphs, err := schconv.ParseGraphFile(jsonSchemaFile, "jsonSchema", graphName, config.DependencyOrder, false)
if err != nil {
return err
}
Expand All @@ -95,7 +115,7 @@ var loadGqlSchemafromJsonSchema = &cobra.Command{
}
if yamlSchemaDir != "" && graphName != "" {
log.Infof("Loading Yaml Schema dir: %s", yamlSchemaDir)
graphs, err := schconv.ParseGraphFile(yamlSchemaDir, "yamlSchema", graphName)
graphs, err := schconv.ParseGraphFile(yamlSchemaDir, "yamlSchema", graphName, config.DependencyOrder, false)
if err != nil {
log.Info("HELLO ERROR HERE: ", err)
return err
Expand Down Expand Up @@ -212,6 +232,7 @@ func init() {
gqlflags.StringVar(&jsonSchemaFile, "jsonSchema", "", "Json Schema")
gqlflags.StringVar(&yamlSchemaDir, "yamlSchemaDir", "", "Name of YAML schemas dir")
gqlflags.StringVar(&graphName, "graphName", "", "Name of schemaGraph")
gqlflags.StringVar(&configPath, "configPath", "", "Path of Config file for determining the subset of ")

Cmd.AddCommand(loadGqlSchemafromJsonSchema)
Cmd.AddCommand(getCmd)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
github.com/antlr/antlr4/runtime/Go/antlr v1.4.10
github.com/bmeg/jsonpath v0.0.0-20210207014051-cca5355553ad
github.com/bmeg/jsonschema/v5 v5.3.4-0.20241111204732-55db82022a92
github.com/bmeg/jsonschemagraph v0.0.3-0.20241211000114-7493b10aa2fe
github.com/boltdb/bolt v1.3.1
github.com/casbin/casbin/v2 v2.97.0
github.com/cockroachdb/pebble v1.1.1
Expand Down Expand Up @@ -59,6 +58,7 @@ require (
github.com/alevinval/sse v1.0.2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bmeg/golib v0.0.0-20200725232156-e799a31439fc // indirect
github.com/bmeg/jsonschemagraph v0.0.3-0.20241211234837-ff91c296d0a8 // indirect
github.com/casbin/govaluate v1.2.0 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ github.com/bmeg/jsonschemagraph v0.0.3-0.20241210221941-3e919ec517cc h1:L2KBzHO3
github.com/bmeg/jsonschemagraph v0.0.3-0.20241210221941-3e919ec517cc/go.mod h1:uVS5AJySmP/VVuZF5Ux/tVyPWNi9IWP5ZRf3il70F7k=
github.com/bmeg/jsonschemagraph v0.0.3-0.20241211000114-7493b10aa2fe h1:emW8sMq9MWg5aisapvXtA12MBthjnGdJ6nGnm12eoDo=
github.com/bmeg/jsonschemagraph v0.0.3-0.20241211000114-7493b10aa2fe/go.mod h1:uVS5AJySmP/VVuZF5Ux/tVyPWNi9IWP5ZRf3il70F7k=
github.com/bmeg/jsonschemagraph v0.0.3-0.20241211234837-ff91c296d0a8 h1:tBnMKyTnGckEt9uM8NUaiaSi6eFRhdJncWsgfez2kQg=
github.com/bmeg/jsonschemagraph v0.0.3-0.20241211234837-ff91c296d0a8/go.mod h1:wRzh5mRmHUv0zaqHCjFzHk+JivZRoxhuIAJyEjzq5hw=
github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4=
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
Expand Down

0 comments on commit b772ede

Please sign in to comment.