diff --git a/codegen/config/binder.go b/codegen/config/binder.go index 41c3efef269..bfd12bbce15 100644 --- a/codegen/config/binder.go +++ b/codegen/config/binder.go @@ -349,7 +349,7 @@ func (b *Binder) TypeReference(schemaType *ast.Type, bindTarget types.Type) (ret } else if hasMethod(obj.Type(), "MarshalGQL") && hasMethod(obj.Type(), "UnmarshalGQL") { ref.GO = obj.Type() ref.IsMarshaler = true - } else if underlying := basicUnderlying(obj.Type()); underlying != nil && underlying.Kind() == types.String { + } else if underlying := basicUnderlying(obj.Type()); def.IsLeafType() && underlying != nil && underlying.Kind() == types.String { // Special case for named types wrapping strings. Used by default enum implementations. ref.GO = obj.Type() diff --git a/codegen/testserver/generated.go b/codegen/testserver/generated.go index 39f45f0aa79..a3f26e4f569 100644 --- a/codegen/testserver/generated.go +++ b/codegen/testserver/generated.go @@ -8216,13 +8216,7 @@ func (ec *executionContext) marshalNPrimitive2ᚕgithubᚗcomᚋ99designsᚋgqlg } func (ec *executionContext) marshalNPrimitiveString2githubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐPrimitiveString(ctx context.Context, sel ast.SelectionSet, v PrimitiveString) graphql.Marshaler { - res := graphql.MarshalString(string(v)) - if res == graphql.Null { - if !ec.HasError(graphql.GetResolverContext(ctx)) { - ec.Errorf(ctx, "must not be null") - } - } - return res + return ec._PrimitiveString(ctx, sel, &v) } func (ec *executionContext) marshalNPrimitiveString2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐPrimitiveString(ctx context.Context, sel ast.SelectionSet, v []PrimitiveString) graphql.Marshaler { diff --git a/codegen/testserver/primitive_objects_test.go b/codegen/testserver/primitive_objects_test.go index f3b46c2bb88..6ceef5c8f7d 100644 --- a/codegen/testserver/primitive_objects_test.go +++ b/codegen/testserver/primitive_objects_test.go @@ -61,7 +61,7 @@ func TestPrimitiveStringObjects(t *testing.T) { PrimitiveStringObject []struct { Value string Doubled string - Len int + Len int } } c.MustPost(`query { primitiveStringObject { value, doubled, len } }`, &resp)