---
cmd/gqlintrospect/main.go | 28 ++++++++++++++++++++++++----
1 file changed, 24 insertions(+), 4 deletions(-)
diff --git a/cmd/gqlintrospect/main.go b/cmd/gqlintrospect/main.go
index c425cca..3777c12 100644
--- a/cmd/gqlintrospect/main.go
+++ b/cmd/gqlintrospect/main.go
@@ -183,9 +183,14 @@ func typeReference(t Type) string {
return typeName
}
+func escapeString(s string) string {
+ s = strings.Replace(s, `\`, `\\`, -1)
+ s = strings.Replace(s, `"`, `\"`, -1)
+ return s
+}
+
func printDescription(desc string, prefix string) {
- desc = strings.Replace(desc, `\`, `\\`, -1)
- desc = strings.Replace(desc, `"`, `\"`, -1)
+ desc = escapeString(desc)
if !strings.Contains(desc, "\n") {
fmt.Printf("%s\"%s\"\n", prefix, desc)
} else {
@@ -197,6 +202,13 @@ func printDescription(desc string, prefix string) {
}
}
+func printDeprecated(reason *string) {
+ fmt.Print(" @deprecated")
+ if reason != nil {
+ fmt.Printf("(reason: \"%s\")", escapeString(*reason))
+ }
+}
+
func printType(t Type) {
if t.Description != nil && *t.Description != "" {
printDescription(*t.Description, "")
@@ -219,7 +231,11 @@ func printType(t Type) {
if e.Description != nil && *e.Description != "" {
printDescription(*e.Description, "\t")
}
- fmt.Printf(" %s\n", e.Name)
+ fmt.Printf(" %s", e.Name)
+ if e.IsDeprecated {
+ printDeprecated(e.DeprecationReason)
+ }
+ fmt.Println()
}
fmt.Print("}\n\n")
case TypeKindInputObject:
@@ -265,7 +281,11 @@ func printType(t Type) {
}
fmt.Print(")")
}
- fmt.Printf(": %s\n", typeReference(*f.Type))
+ fmt.Printf(": %s", typeReference(*f.Type))
+ if f.IsDeprecated {
+ printDeprecated(f.DeprecationReason)
+ }
+ fmt.Println()
}
fmt.Print("}\n\n")
}
--
2.37.0
---
cmd/gqlintrospect/main.go | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/cmd/gqlintrospect/main.go b/cmd/gqlintrospect/main.go
index 3777c12..06c4bb3 100644
--- a/cmd/gqlintrospect/main.go
+++ b/cmd/gqlintrospect/main.go
@@ -291,6 +291,18 @@ func printType(t Type) {
}
}
+var builtInScalars = map[string]bool{
+ "Int": true,
+ "Float": true,
+ "String": true,
+ "Boolean": true,
+ "ID": true,
+}
+
+func isBuiltInType(t Type) bool {
+ return strings.HasPrefix(*t.Name, "__") || builtInScalars[*t.Name]
+}
+
func main() {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
@@ -329,7 +341,7 @@ func main() {
}
for _, t := range data.Schema.Types {
- if t.Name != nil && strings.HasPrefix(*t.Name, "__") {
+ if isBuiltInType(t) {
continue
}
printType(t)
--
2.37.0
---
cmd/gqlintrospect/main.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/cmd/gqlintrospect/main.go b/cmd/gqlintrospect/main.go
index 06c4bb3..1dbb814 100644
--- a/cmd/gqlintrospect/main.go
+++ b/cmd/gqlintrospect/main.go
@@ -167,7 +167,7 @@ func typeReference(t Type) string {
}
if ofType.Name == nil {
- return "<invalid>"
+ panic("invalid type")
}
typeName := *ofType.Name
if len(modifiers) > 0 {
--
2.37.0