New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Recursive schema definition potentially causing an infinite loop #38
Comments
Thanks for the bug report! I'll see if can reproduce this and let you know if I have any questions. |
@joshprice I put together a reproduction as a test and it passes so it looks like things are good. I think the infinite loop is me calling schema, calling schema, calling schema, calling schema in my definitions. If you want the test in here I can make it a PR, otherwise I'll drop the branch. Either way, I think this issue is closable. Sorry if you wasted any time on it! |
Hadn't had a chance to look at it yet, but glad you got to the bottom of it. A PR with that recursion test in would be fantastic thanks! |
Turns out my test wasn't a circular dep, if I went any levels deeper it wouldn't work because elixir isn't mutable and my last reference to fruit in basket doesn't have a basket field. Basically something like this that I would do in node isn't something I can do in elixir. var a = {}
var b = {}
b.a = a
a.b = b
console.log(a.b.a.b.a.b.a.b === b) // true Which in a long story short is to say in the end it's not testing anything you aren't already testing :) Just had a chat about it in |
As reported in Issue graphql-elixir#38, Schemas weren't able to recursively refer to one another. By quoting the offending references and only evaling them during Execution, we can resolve everything on-demand.
So, I saw this Issue just before starting to travel, and ended up coming with a solution ( #39 ) analogous to the js reference implementation of graphql. Where they wrap the |
As reported in Issue graphql-elixir#38, Schemas weren't able to recursively refer to one another. By quoting the offending references and only evaling them during Execution, we can resolve everything on-demand.
Thanks @markolson, really great! |
As reported in Issue graphql-elixir#38, Schemas weren't able to recursively refer to one another. By quoting the offending references and only evaling them during Execution, we can resolve everything on-demand.
I'm using @markolson's fix (#39), however with
I'm not sure whether this is an issue with EDIT: I get the error when starting the server too, so I don't think it's related to |
Thanks for the bug report. Not sure which branch you mean, but please try using the latest GraphQL On Mon, Apr 18, 2016 at 3:19 PM, Ashley Williams notifications@github.com
|
This is using the master branch. I think this is the relevant schema:
Thanks! |
So the Update: this is definitely a schema issue, and I suspect the quoting might be causing this. |
Ah — thanks! Although I think there may still be an issue.
|
The second argument that function looks wrong: So change If that is still broken please open a new issue as this isn't related to the original issue. Or ping me in the GraphQL or Elixir slacks. |
@joshprice You're right, it should just be |
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.
Relations are:
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:
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.
The text was updated successfully, but these errors were encountered: