~emersion/public-inbox

gqlclient: cmd/gqlintrospect: print deprecations v2 APPLIED

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

 3 files changed, 39 insertions(+), 7 deletions(-)
Pushed, thanks!
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/33812/mbox | git am -3
Learn more about email & git

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

---
v2: quoteString instead of escapeString

 cmd/gqlintrospect/main.go | 30 +++++++++++++++++++++++++-----
 1 file changed, 25 insertions(+), 5 deletions(-)

diff --git a/cmd/gqlintrospect/main.go b/cmd/gqlintrospect/main.go
index c425cca..d8baa71 100644
--- a/cmd/gqlintrospect/main.go
+++ b/cmd/gqlintrospect/main.go
@@ -183,12 +183,17 @@ func typeReference(t Type) string {
	return typeName
}

func quoteString(s string) string {
	s = strings.Replace(s, `\`, `\\`, -1)
	s = strings.Replace(s, `"`, `\"`, -1)
	return fmt.Sprintf(`"%s"`, s)
}

func printDescription(desc string, prefix string) {
	desc = strings.Replace(desc, `\`, `\\`, -1)
	desc = strings.Replace(desc, `"`, `\"`, -1)
	if !strings.Contains(desc, "\n") {
		fmt.Printf("%s\"%s\"\n", prefix, desc)
		fmt.Printf("%s%s\n", prefix, quoteString(desc))
	} else {
		desc = strings.Replace(desc, `"""`, `\"""`, -1)
		fmt.Printf("%s\"\"\"\n", prefix)
		for _, line := range strings.Split(desc, "\n") {
			fmt.Printf("%s%s\n", prefix, line)
@@ -197,6 +202,13 @@ func printDescription(desc string, prefix string) {
	}
}

func printDeprecated(reason *string) {
	fmt.Print(" @deprecated")
	if reason != nil {
		fmt.Printf("(reason: %s)", quoteString(*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 v2 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 d8baa71..44b41b2 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 v2 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 44b41b2..48e2be9 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
Pushed, thanks!