Skip to content

Commit 74e6fa1

Browse files
todo
1 parent fe6a449 commit 74e6fa1

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

internal/cli/config_test.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
package cli
22

33
import (
4-
"fmt"
54
"github.com/BurntSushi/toml"
65
"github.com/stretchr/testify/require"
76
"testing"
87
)
98

109
const blob = `
1110
[[type]]
12-
name = "Person"
13-
deny_list = ["foobar"]
11+
name = "PersonInsertInput"
12+
deny_list = ["address"]
1413
1514
[[type]]
16-
name = "Stairway to Heaven"
15+
name = "Person"
16+
deny_list = ["address"]
1717
`
1818

1919
func TestDecode(t *testing.T) {
@@ -22,7 +22,18 @@ func TestDecode(t *testing.T) {
2222
_, err := toml.Decode(blob, &testCfg)
2323
require.NoError(t, err)
2424

25-
for _, s := range testCfg.Types {
26-
fmt.Printf("%s (%v)\n", s.Name, s.DenyList)
25+
expected := config{
26+
Types: []Type{
27+
{
28+
Name: "PersonInsertInput",
29+
DenyList: []string{"address"},
30+
},
31+
{
32+
Name: "Person",
33+
DenyList: []string{"address"},
34+
},
35+
},
2736
}
37+
38+
require.Equal(t, expected, testCfg)
2839
}

internal/cli/graph.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func sanitizeComment(d Describer) string {
2929

3030
func NewVertex(node ast.Node) Vertex {
3131
var name string
32+
3233
switch node.GetKind() {
3334
case kinds.ScalarDefinition:
3435
obj := node.(*ast.ScalarDefinition)
@@ -125,7 +126,9 @@ func buildPrunedGraph(doc *ast.Document) graph.Graph[string, Vertex] {
125126
// Build edges between vertices.
126127
buildEdges(g)
127128

128-
// Prunes any vertices that don't appear in any edges
129+
// Prune our graph:
130+
// 1. We filter out any vertices (GQL types) that we don't explicitly want
131+
// 2. We filter out any fields within those GQL types
129132
return prune(g)
130133
}
131134

@@ -154,6 +157,9 @@ func loadTopLevelDefinitions(g graph.Graph[string, Vertex], doc *ast.Document) {
154157
}
155158
}
156159

160+
// Prune our graph:
161+
// 1. We filter out any vertices (GQL types) that we don't explicitly want
162+
// 2. We filter out any fields within those GQL types
157163
func prune(in graph.Graph[string, Vertex]) graph.Graph[string, Vertex] {
158164
m, err := in.AdjacencyMap()
159165
if err != nil {
@@ -166,9 +172,13 @@ func prune(in graph.Graph[string, Vertex]) graph.Graph[string, Vertex] {
166172
continue
167173
}
168174

175+
// Retrieve the vertex (GraphQL type) by its name
169176
def := must(in.Vertex(defName))
170177

171-
// Add vertex
178+
// TODO clone the type definition and filter out fields
179+
// def = filter(clone(def))
180+
181+
// Add vertex (GraphQL type) to our new, outgoing graph
172182
_ = out.AddVertex(def)
173183

174184
// Add its dependent vertices
@@ -190,6 +200,7 @@ func must(v Vertex, err error) Vertex {
190200
}
191201

192202
func isDesired(definitionName string) bool {
203+
// TODO deprecate in favor of config
193204
for _, d := range desiredDefinitions {
194205
if definitionName == d {
195206
return true
@@ -200,6 +211,7 @@ func isDesired(definitionName string) bool {
200211
}
201212

202213
func isBasicType(t string) bool {
214+
// https://graphql.org/graphql-js/basic-types/
203215
return t == "String" || t == "Float" || t == "Int" || t == "Boolean" || t == "ID"
204216
}
205217

0 commit comments

Comments
 (0)