Recursive schema definition potentially causing an infinite loop #38
Description
Hi. Firstly, thanks for all the work on graphql-elixir and plug-graphql.
I'm having trouble with a circular schema definition. Using plug_graphql in phoenix and the server freezes up no matter the query when the circular definitions are in play.
- Recurring
- Transaction
- Tag
Relations are:
- Tags many to many Recurring
- Tags many to many Transaction
https://github.com/Bockit/budget/tree/master/apps/api-server/web/graphql is the graphql schema I have for this model. The root query provides a singular and list type query for each model. Each model has a resolve tag for its relations.
Before I added the relations to the Tag schema, things were great but once I added the recurrings and transactions relations to the Tag schema all requests freeze up in what appears to be an infinite loop. Even if you don't request any of the relation fields.
If you comment out the tags field on Transaction, and the recurrings field on Tag (breaking the circle) then you can do the following and it works as expected:
$ curl "http://127.0.0.1:4000/api?query=\{recurring(id:11)\{amount,tags\{tag,transactions\{amount\}\}\}\}"
{
"data": {
"recurring": {
"tags": [
{
"transactions": [
{
"amount": 24.53
}
],
"tag": "Utilities"
},
{
"transactions": [
{
"amount": 60.0
}
],
"tag": "Development"
}
],
"amount": 50.0
}
}
}
If this is confusing I can make a simpler, proof-of-concept reproduction tomorrow. If I'm correct and this is causing an infinite loop with a circular reference as described then a simple schema with 2 object types that both refer back to each other should cause the same effect.
Thanks for your time.