diff --git a/codegen/config/binder.go b/codegen/config/binder.go index 209c1205d19..459114d6fce 100644 --- a/codegen/config/binder.go +++ b/codegen/config/binder.go @@ -212,6 +212,16 @@ func (t *TypeReference) IsPtr() bool { return isPtr } +// fix for https://github.com/golang/go/issues/31103 may make it possible to remove this (may still be useful) +// +func (t *TypeReference) IsPtrToPtr() bool { + if p, isPtr := t.GO.(*types.Pointer); isPtr { + _, isPtr := p.Elem().(*types.Pointer) + return isPtr + } + return false +} + func (t *TypeReference) IsNilable() bool { return IsNilable(t.GO) } diff --git a/codegen/testserver/generated.go b/codegen/testserver/generated.go index c84bd5c6dc2..5ef067fc6bd 100644 --- a/codegen/testserver/generated.go +++ b/codegen/testserver/generated.go @@ -15661,11 +15661,46 @@ func (ec *executionContext) marshalOPtrToPtrInner2ᚖgithubᚗcomᚋ99designsᚋ return ec._PtrToPtrInner(ctx, sel, v) } +func (ec *executionContext) marshalOPtrToPtrInner2ᚖᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐPtrToPtrInner(ctx context.Context, sel ast.SelectionSet, v **PtrToPtrInner) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.marshalOPtrToPtrInner2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐPtrToPtrInner(ctx, sel, *v) +} + +func (ec *executionContext) marshalOPtrToPtrInner2ᚖᚖᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐPtrToPtrInner(ctx context.Context, sel ast.SelectionSet, v ***PtrToPtrInner) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.marshalOPtrToPtrInner2ᚖᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐPtrToPtrInner(ctx, sel, *v) +} + +func (ec *executionContext) marshalOPtrToPtrInner2ᚖᚖᚖᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐPtrToPtrInner(ctx context.Context, sel ast.SelectionSet, v ****PtrToPtrInner) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.marshalOPtrToPtrInner2ᚖᚖᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐPtrToPtrInner(ctx, sel, *v) +} + +func (ec *executionContext) marshalOPtrToPtrInner2ᚖᚖᚖᚖᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐPtrToPtrInner(ctx context.Context, sel ast.SelectionSet, v *****PtrToPtrInner) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.marshalOPtrToPtrInner2ᚖᚖᚖᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐPtrToPtrInner(ctx, sel, *v) +} + +func (ec *executionContext) marshalOPtrToPtrInner2ᚖᚖᚖᚖᚖᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐPtrToPtrInner(ctx context.Context, sel ast.SelectionSet, v ******PtrToPtrInner) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.marshalOPtrToPtrInner2ᚖᚖᚖᚖᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐPtrToPtrInner(ctx, sel, *v) +} + func (ec *executionContext) marshalOPtrToPtrInner2ᚖᚖᚖᚖᚖᚖᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐPtrToPtrInner(ctx context.Context, sel ast.SelectionSet, v *******PtrToPtrInner) graphql.Marshaler { if v == nil { return graphql.Null } - return ec._PtrToPtrInner(ctx, sel, v) + return ec.marshalOPtrToPtrInner2ᚖᚖᚖᚖᚖᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐPtrToPtrInner(ctx, sel, *v) } func (ec *executionContext) unmarshalORecursiveInputSlice2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐRecursiveInputSliceᚄ(ctx context.Context, v interface{}) ([]RecursiveInputSlice, error) { @@ -15906,7 +15941,7 @@ func (ec *executionContext) marshalOTime2ᚖtimeᚐTime(ctx context.Context, sel return graphql.MarshalTime(*v) } -func (ec *executionContext) unmarshalOUpdatePtrToPtrInner2ᚖᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐUpdatePtrToPtrInner(ctx context.Context, v interface{}) (**UpdatePtrToPtrInner, error) { +func (ec *executionContext) unmarshalOUpdatePtrToPtrInner2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐUpdatePtrToPtrInner(ctx context.Context, v interface{}) (*UpdatePtrToPtrInner, error) { if v == nil { return nil, nil } @@ -15914,12 +15949,88 @@ func (ec *executionContext) unmarshalOUpdatePtrToPtrInner2ᚖᚖgithubᚗcomᚋ9 return &res, graphql.ErrorOnPath(ctx, err) } +func (ec *executionContext) unmarshalOUpdatePtrToPtrInner2ᚖᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐUpdatePtrToPtrInner(ctx context.Context, v interface{}) (**UpdatePtrToPtrInner, error) { + var pres *UpdatePtrToPtrInner + if v != nil { + res, err := ec.unmarshalOUpdatePtrToPtrInner2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐUpdatePtrToPtrInner(ctx, v) + if err != nil { + return nil, graphql.ErrorOnPath(ctx, err) + } + pres = res + } + return &pres, nil +} + +func (ec *executionContext) unmarshalOUpdatePtrToPtrInner2ᚖᚖᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐUpdatePtrToPtrInner(ctx context.Context, v interface{}) (***UpdatePtrToPtrInner, error) { + var pres **UpdatePtrToPtrInner + if v != nil { + res, err := ec.unmarshalOUpdatePtrToPtrInner2ᚖᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐUpdatePtrToPtrInner(ctx, v) + if err != nil { + return nil, graphql.ErrorOnPath(ctx, err) + } + pres = res + } + return &pres, nil +} + +func (ec *executionContext) unmarshalOUpdatePtrToPtrInner2ᚖᚖᚖᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐUpdatePtrToPtrInner(ctx context.Context, v interface{}) (****UpdatePtrToPtrInner, error) { + var pres ***UpdatePtrToPtrInner + if v != nil { + res, err := ec.unmarshalOUpdatePtrToPtrInner2ᚖᚖᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐUpdatePtrToPtrInner(ctx, v) + if err != nil { + return nil, graphql.ErrorOnPath(ctx, err) + } + pres = res + } + return &pres, nil +} + +func (ec *executionContext) unmarshalOUpdatePtrToPtrInner2ᚖᚖᚖᚖᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐUpdatePtrToPtrInner(ctx context.Context, v interface{}) (*****UpdatePtrToPtrInner, error) { + var pres ****UpdatePtrToPtrInner + if v != nil { + res, err := ec.unmarshalOUpdatePtrToPtrInner2ᚖᚖᚖᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐUpdatePtrToPtrInner(ctx, v) + if err != nil { + return nil, graphql.ErrorOnPath(ctx, err) + } + pres = res + } + return &pres, nil +} + +func (ec *executionContext) unmarshalOUpdatePtrToPtrInner2ᚖᚖᚖᚖᚖᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐUpdatePtrToPtrInner(ctx context.Context, v interface{}) (******UpdatePtrToPtrInner, error) { + var pres *****UpdatePtrToPtrInner + if v != nil { + res, err := ec.unmarshalOUpdatePtrToPtrInner2ᚖᚖᚖᚖᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐUpdatePtrToPtrInner(ctx, v) + if err != nil { + return nil, graphql.ErrorOnPath(ctx, err) + } + pres = res + } + return &pres, nil +} + +func (ec *executionContext) unmarshalOUpdatePtrToPtrInner2ᚖᚖᚖᚖᚖᚖᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐUpdatePtrToPtrInner(ctx context.Context, v interface{}) (*******UpdatePtrToPtrInner, error) { + var pres ******UpdatePtrToPtrInner + if v != nil { + res, err := ec.unmarshalOUpdatePtrToPtrInner2ᚖᚖᚖᚖᚖᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐUpdatePtrToPtrInner(ctx, v) + if err != nil { + return nil, graphql.ErrorOnPath(ctx, err) + } + pres = res + } + return &pres, nil +} + func (ec *executionContext) unmarshalOUpdatePtrToPtrInner2ᚖᚖᚖᚖᚖᚖᚖᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐUpdatePtrToPtrInner(ctx context.Context, v interface{}) (********UpdatePtrToPtrInner, error) { - if v == nil { - return nil, nil + var pres *******UpdatePtrToPtrInner + if v != nil { + res, err := ec.unmarshalOUpdatePtrToPtrInner2ᚖᚖᚖᚖᚖᚖᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐUpdatePtrToPtrInner(ctx, v) + if err != nil { + return nil, graphql.ErrorOnPath(ctx, err) + } + pres = res } - res, err := ec.unmarshalInputUpdatePtrToPtrInner(ctx, v) - return &res, graphql.ErrorOnPath(ctx, err) + return &pres, nil } func (ec *executionContext) marshalOVOkCaseNil2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋcodegenᚋtestserverᚐVOkCaseNil(ctx context.Context, sel ast.SelectionSet, v *VOkCaseNil) graphql.Marshaler { diff --git a/codegen/type.go b/codegen/type.go index 5a059d70131..20b09dc9755 100644 --- a/codegen/type.go +++ b/codegen/type.go @@ -26,7 +26,7 @@ func processType(ret map[string]*config.TypeReference, ref *config.TypeReference } ret[key] = ref - if ref.IsSlice() || ref.IsPtrToSlice() { + if ref.IsSlice() || ref.IsPtrToSlice() || ref.IsPtrToPtr() { processType(ret, ref.Elem()) } } diff --git a/codegen/type.gotpl b/codegen/type.gotpl index 9c421b02d3d..53fe54283bc 100644 --- a/codegen/type.gotpl +++ b/codegen/type.gotpl @@ -1,7 +1,7 @@ {{- range $type := .ReferencedTypes }} {{ with $type.UnmarshalFunc }} func (ec *executionContext) {{ . }}(ctx context.Context, v interface{}) ({{ $type.GO | ref }}, error) { - {{- if and $type.IsNilable (not $type.GQL.NonNull) }} + {{- if and $type.IsNilable (not $type.GQL.NonNull) (not $type.IsPtrToPtr) }} if v == nil { return nil, nil } {{- end }} {{- if $type.IsPtrToSlice }} @@ -26,6 +26,16 @@ } } return res, nil + {{- else if and $type.IsPtrToPtr (not $type.Unmarshaler) (not $type.IsMarshaler) }} + var pres {{ $type.Elem.GO | ref }} + if v != nil { + res, err := ec.{{ $type.Elem.UnmarshalFunc }}(ctx, v) + if err != nil { + return nil, graphql.ErrorOnPath(ctx, err) + } + pres = res + } + return &pres, nil {{- else }} {{- if $type.Unmarshaler }} {{- if $type.CastType }} @@ -123,6 +133,11 @@ } {{ end }} return ret + {{- else if and $type.IsPtrToPtr (not $type.Unmarshaler) (not $type.IsMarshaler) }} + if v == nil { + return graphql.Null + } + return ec.{{ $type.Elem.MarshalFunc }}(ctx, sel, *v) {{- else }} {{- if $type.IsNilable }} if v == nil {