~emersion/public-inbox

gqlclient: cmd/gqlintrospect: print deprecations v1 SUPERSEDED

Adnan Maolood: 3
 cmd/gqlintrospect: print deprecations
 cmd/gqlintrospect: skip built-in scalars
 cmd/gqlintrospect: panic on invalid type

 3 files changed, 38 insertions(+), 6 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~emersion/public-inbox/patches/33809/mbox | git am -3
Learn more about email & git

[PATCH gqlclient 1/3] cmd/gqlintrospect: print deprecations Export this patch

---
 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

[PATCH gqlclient 2/3] cmd/gqlintrospect: skip built-in scalars Export this patch

---
 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

[PATCH gqlclient 3/3] cmd/gqlintrospect: panic on invalid type Export this patch

---
 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