~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
3 2

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

Details
Message ID
<20220712161329.4882-1-me@adnano.co>
DKIM signature
pass
Download raw message
Patch: +25 -5
---
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

Details
Message ID
<20220712161329.4882-2-me@adnano.co>
In-Reply-To
<20220712161329.4882-1-me@adnano.co> (view parent)
DKIM signature
pass
Download raw message
Patch: +13 -1
---
 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

Details
Message ID
<20220712161329.4882-3-me@adnano.co>
In-Reply-To
<20220712161329.4882-1-me@adnano.co> (view parent)
DKIM signature
pass
Download raw message
Patch: +1 -1
---
 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

Re: [PATCH gqlclient v2 3/3] cmd/gqlintrospect: panic on invalid type

Details
Message ID
<Ooa13L8_59O7WIA70zbviWvOElyslIOAiWCExIkydAWyA6Oc7p83NUg36jsZ0hdVOUv7L1ocKbeEcf2d8xahn9gh6MVlDgb8E6c52gPoh0U=@emersion.fr>
In-Reply-To
<20220712161329.4882-3-me@adnano.co> (view parent)
DKIM signature
pass
Download raw message
Pushed, thanks!
Reply to thread Export thread (mbox)