Skip to content

Commit c5f04de

Browse files
committed
fix recursion
1 parent 29ae911 commit c5f04de

File tree

2 files changed

+177
-164
lines changed

2 files changed

+177
-164
lines changed

clientgen/source_generator.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,30 @@ func (r *SourceGenerator) NewResponseFieldsByDefinition(definition *ast.Definiti
9595

9696
var typ types.Type
9797
if field.Type.Name() == "Query" || field.Type.Name() == "Mutation" {
98+
var baseType types.Type
9899
baseType, err := r.binder.FindType(r.client.Pkg().Path(), field.Type.Name())
99100
if err != nil {
100-
return nil, xerrors.Errorf("not found type: %w", err)
101+
if !strings.Contains(err.Error(), "unable to find type") {
102+
return nil, xerrors.Errorf("not found type: %w", err)
103+
}
104+
105+
// create new type
106+
baseType = types.NewPointer(types.NewNamed(
107+
types.NewTypeName(0, r.client.Pkg(), templates.ToGo(field.Type.Name()), nil),
108+
nil,
109+
nil,
110+
))
101111
}
112+
102113
// for recursive struct field in go
103114
typ = types.NewPointer(baseType)
115+
104116
} else {
105117
baseType, err := r.binder.FindTypeFromName(r.cfg.Models[field.Type.Name()].Model[0])
106118
if err != nil {
107119
return nil, xerrors.Errorf("not found type: %w", err)
108120
}
121+
109122
typ = r.binder.CopyModifiersFromAst(field.Type, baseType)
110123
}
111124

0 commit comments

Comments
 (0)