Structs with fields that reference themselves (or reference other types that eventually reference themselves) result in a stack overflow as the query generator code traverses them.
For example, this is a problematic struct containing fields with its own type:
type Foobar struct {
Children []Foobar
}
This is the relevant part of the stack trace resulting:
Basically, the writeQuery function as currently written is perfectly happy to keep looking up the type of the Foobar struct, looking at the Children field and generating a little more query, then recursing to look up the type of the field, which is of course still Foobar...
It would be nicer if the library detected this cycle and raised an error with a relevant message as soon as possible. A panic still seems reasonable (IMO), because you're pretty much statically doomed from the time you compiled the program and have no hope of handling this; but a stack overflow as that panic is a bit of a bummer.
(Originally mentioned at https://github.com/shurcooL/graphql/issues/9, but filing as a separate issue for clarity of discussion.)
Structs with fields that reference themselves (or reference other types that eventually reference themselves) result in a stack overflow as the query generator code traverses them.
For example, this is a problematic struct containing fields with its own type:
This is the relevant part of the stack trace resulting:
Basically, the
writeQuery
function as currently written is perfectly happy to keep looking up the type of theFoobar
struct, looking at theChildren
field and generating a little more query, then recursing to look up the type of the field, which is of course stillFoobar
...It would be nicer if the library detected this cycle and raised an error with a relevant message as soon as possible. A panic still seems reasonable (IMO), because you're pretty much statically doomed from the time you compiled the program and have no hope of handling this; but a stack overflow as that panic is a bit of a bummer.