From d02d17ae1d05a2efd3915bff84153feb6497f458 Mon Sep 17 00:00:00 2001 From: creativej Date: Mon, 23 Jul 2018 13:14:07 +1000 Subject: [PATCH] Add method for generating method name from field --- codegen/object.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/codegen/object.go b/codegen/object.go index 1c03c0bae3d..17b1c875d59 100644 --- a/codegen/object.go +++ b/codegen/object.go @@ -68,11 +68,11 @@ func (f *Field) IsConcurrent() bool { return f.IsResolver() && !f.Object.DisableConcurrency } func (f *Field) ShortInvocation() string { - if !f.IsResolver() { + methodName := f.MethodName() + if methodName == "" { return "" } - shortName := strings.ToUpper(f.GQLName[:1]) + f.GQLName[1:] - res := fmt.Sprintf("%s().%s(ctx", f.Object.GQLType, shortName) + res := fmt.Sprintf("%s(ctx", methodName) if !f.Object.Root { res += fmt.Sprintf(", obj") } @@ -82,6 +82,15 @@ func (f *Field) ShortInvocation() string { res += ")" return res } +func (f *Field) MethodName() string { + if !f.IsResolver() { + return "" + } + shortName := strings.ToUpper(f.GQLName[:1]) + f.GQLName[1:] + + return fmt.Sprintf("%s().%s", f.Object.GQLType, shortName) +} + func (f *Field) ShortResolverDeclaration() string { if !f.IsResolver() { return ""