From 27ca2fc92df8425c6c159f494d8340e69982d1f3 Mon Sep 17 00:00:00 2001 From: Hemanth Bollamreddi Date: Mon, 18 Dec 2023 14:47:13 +0530 Subject: [PATCH] Return null if invalid enum is encountered --- plugin/modelgen/models.gotpl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugin/modelgen/models.gotpl b/plugin/modelgen/models.gotpl index b11146939b..4fba157e47 100644 --- a/plugin/modelgen/models.gotpl +++ b/plugin/modelgen/models.gotpl @@ -98,7 +98,12 @@ } func (e {{ goModelName .Name }}) MarshalGQL(w io.Writer) { - fmt.Fprint(w, strconv.Quote(e.String())) + switch e.IsValid() { + case true: + fmt.Fprint(w, strconv.Quote(e.String())) + case false: + graphql.Null.MarshalGQL(w) + } } {{- end }}