~emersion/public-inbox

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch

[PATCH gqlclient v2] cmd/gqlintrospect: improve output

Details
Message ID
<20220712144034.24276-1-me@adnano.co>
DKIM signature
pass
Download raw message
Patch: +14 -2
Fix union member printing, escape string literals, and show implemented
interfaces.
---
v2: fix interface delimeter (& instead of ,)
 cmd/gqlintrospect/main.go | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/cmd/gqlintrospect/main.go b/cmd/gqlintrospect/main.go
index 724c125..c425cca 100644
--- a/cmd/gqlintrospect/main.go
+++ b/cmd/gqlintrospect/main.go
@@ -184,6 +184,8 @@ func typeReference(t Type) string {
}

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)
	} else {
@@ -204,7 +206,7 @@ func printType(t Type) {
		fmt.Printf("scalar %s\n\n", *t.Name)
	case TypeKindUnion:
		fmt.Printf("union %s = ", *t.Name)
		for idx, i := range t.Interfaces {
		for idx, i := range t.PossibleTypes {
			if idx > 0 {
				fmt.Print(" | ")
			}
@@ -234,7 +236,17 @@ func printType(t Type) {
		}
		fmt.Print("}\n\n")
	case TypeKindObject, TypeKindInterface:
		fmt.Printf("%s %s {\n", typeKeyword(t), *t.Name)
		fmt.Printf("%s %s", typeKeyword(t), *t.Name)
		if len(t.Interfaces) > 0 {
			fmt.Printf(" implements ")
			for idx, i := range t.Interfaces {
				if idx > 0 {
					fmt.Print(" & ")
				}
				fmt.Printf(typeReference(i))
			}
		}
		fmt.Print(" {\n")
		for _, f := range t.Fields {
			if f.Description != nil && *f.Description != "" {
				printDescription(*f.Description, "\t")
-- 
2.37.0
Reply to thread Export thread (mbox)