diff --git a/graphql/bool.go b/graphql/bool.go index b175ca98628..f435e0c0988 100644 --- a/graphql/bool.go +++ b/graphql/bool.go @@ -7,13 +7,10 @@ import ( ) func MarshalBoolean(b bool) Marshaler { - return WriterFunc(func(w io.Writer) { - if b { - w.Write(trueLit) - } else { - w.Write(falseLit) - } - }) + if b { + return WriterFunc(func(w io.Writer) { w.Write(trueLit) }) + } + return WriterFunc(func(w io.Writer) { w.Write(falseLit) }) } func UnmarshalBoolean(v interface{}) (bool, error) { diff --git a/graphql/bool_test.go b/graphql/bool_test.go new file mode 100644 index 00000000000..147237a1d63 --- /dev/null +++ b/graphql/bool_test.go @@ -0,0 +1,19 @@ +package graphql + +import ( + "bytes" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestBoolean(t *testing.T) { + assert.Equal(t, "true", doBooleanMarshal(true)) + assert.Equal(t, "false", doBooleanMarshal(false)) +} + +func doBooleanMarshal(b bool) string { + var buf bytes.Buffer + MarshalBoolean(b).MarshalGQL(&buf) + return buf.String() +}