diff --git a/cmd/schema/main.go b/cmd/schema/main.go index 33896672..1a8b6596 100644 --- a/cmd/schema/main.go +++ b/cmd/schema/main.go @@ -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" @@ -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 @@ -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", @@ -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 } @@ -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 @@ -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) diff --git a/go.mod b/go.mod index f2f8b9f1..2257011f 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 diff --git a/go.sum b/go.sum index 2ec0ea08..dd7e7018 100644 --- a/go.sum +++ b/go.sum @@ -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=