Skip to content

Commit 30b7d25

Browse files
feat: More extensive configuration
1 parent 7516a68 commit 30b7d25

File tree

13 files changed

+1169
-4
lines changed

13 files changed

+1169
-4
lines changed

.golangci.yml

Lines changed: 1073 additions & 0 deletions
Large diffs are not rendered by default.

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.PHONY: lint
2+
lint:
3+
pkgx golangci-lint@latest run

go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,29 @@ module github.com/kevinmichaelchen/graphql-schema-picker
33
go 1.21.0
44

55
require (
6+
github.com/BurntSushi/toml v1.3.2
67
github.com/charmbracelet/log v0.3.0
78
github.com/dominikbraun/graph v0.23.0
89
github.com/graphql-go/graphql v0.8.1
910
github.com/spf13/cobra v1.7.0
11+
github.com/stretchr/testify v1.8.4
1012
)
1113

1214
require (
1315
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
1416
github.com/charmbracelet/lipgloss v0.9.1 // indirect
17+
github.com/davecgh/go-spew v1.1.1 // indirect
1518
github.com/go-logfmt/logfmt v0.6.0 // indirect
1619
github.com/inconshreveable/mousetrap v1.1.0 // indirect
1720
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
1821
github.com/mattn/go-isatty v0.0.18 // indirect
1922
github.com/mattn/go-runewidth v0.0.15 // indirect
2023
github.com/muesli/reflow v0.3.0 // indirect
2124
github.com/muesli/termenv v0.15.2 // indirect
25+
github.com/pmezard/go-difflib v1.0.0 // indirect
2226
github.com/rivo/uniseg v0.2.0 // indirect
2327
github.com/spf13/pflag v1.0.5 // indirect
2428
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
2529
golang.org/x/sys v0.13.0 // indirect
30+
gopkg.in/yaml.v3 v3.0.1 // indirect
2631
)

go.sum

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
2+
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
13
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
24
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
35
github.com/charmbracelet/lipgloss v0.9.1 h1:PNyd3jvaJbg4jRHKWXnCj1akQm4rh8dbEzN1p/u1KWg=
@@ -43,6 +45,7 @@ golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQz
4345
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
4446
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
4547
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
48+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
4649
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
4750
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
4851
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

internal/cli/ast_print.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package cli
22

33
import (
44
"bufio"
5+
"os"
6+
57
"github.com/charmbracelet/log"
68
"github.com/graphql-go/graphql/language/ast"
79
"github.com/graphql-go/graphql/language/printer"
8-
"os"
910
)
1011

1112
func printSDL(doc *ast.Document) {

internal/cli/cli.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package cli
22

33
import (
4+
"os"
5+
46
"github.com/charmbracelet/log"
57
"github.com/spf13/cobra"
6-
"os"
78
)
89

910
var rootCmd = &cobra.Command{
@@ -16,6 +17,11 @@ var rootCmd = &cobra.Command{
1617
if debug {
1718
log.SetLevel(log.DebugLevel)
1819
}
20+
21+
err := loadConfig()
22+
if err != nil {
23+
log.Fatal("error occurred while loading config", "err", err)
24+
}
1925
},
2026
}
2127

@@ -26,6 +32,7 @@ var (
2632
dryRun bool
2733
desiredDefinitions []string
2834
output string
35+
configPath string
2936
)
3037

3138
// LDFlags contain fields that get linked and compiled into the final binary
@@ -46,6 +53,7 @@ func init() {
4653

4754
pick.Flags().StringSliceVarP(&desiredDefinitions, "definitions", "d", []string{}, "definitions from the SDL you want to pick/keep")
4855
pick.Flags().StringVarP(&output, "output", "o", "", "where the resulting schema/SDL file is written")
56+
pick.Flags().StringVarP(&configPath, "config", "c", "", "path to config file")
4957
}
5058

5159
func Main(ldf LDFlags) {

internal/cli/cli_pick.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package cli
22

33
import (
4+
"os"
5+
46
"github.com/charmbracelet/log"
57
"github.com/dominikbraun/graph/draw"
68
"github.com/spf13/cobra"
7-
"os"
89
)
910

1011
var pick = &cobra.Command{

internal/cli/cli_version.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cli
22

33
import (
44
"fmt"
5+
56
"github.com/spf13/cobra"
67
)
78

internal/cli/config.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package cli
2+
3+
import (
4+
"fmt"
5+
"github.com/BurntSushi/toml"
6+
)
7+
8+
var cfg config
9+
10+
type config struct {
11+
Types []Type `toml:"type"`
12+
}
13+
14+
// Type - A GraphQL type in a GraphQL schema.
15+
type Type struct {
16+
// Name - The name of the GraphQL type you want to keep/pick.
17+
Name string `toml:"name"`
18+
19+
// DenyList - List of fields within that type you want to filter out.
20+
DenyList []string `toml:"deny_list"`
21+
}
22+
23+
func loadConfig() error {
24+
_, err := toml.DecodeFile(configPath, &cfg)
25+
if err != nil {
26+
return fmt.Errorf("unable to decode config: %w", err)
27+
}
28+
29+
return nil
30+
}

internal/cli/config_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package cli
2+
3+
import (
4+
"fmt"
5+
"github.com/BurntSushi/toml"
6+
"github.com/stretchr/testify/require"
7+
"testing"
8+
)
9+
10+
const blob = `
11+
[[type]]
12+
name = "Person"
13+
deny_list = ["foobar"]
14+
15+
[[type]]
16+
name = "Stairway to Heaven"
17+
`
18+
19+
func TestDecode(t *testing.T) {
20+
var testCfg config
21+
22+
_, err := toml.Decode(blob, &testCfg)
23+
require.NoError(t, err)
24+
25+
for _, s := range testCfg.Types {
26+
fmt.Printf("%s (%v)\n", s.Name, s.DenyList)
27+
}
28+
}

0 commit comments

Comments
 (0)