graphql-php
graphql-php copied to clipboard
Serialization of double-linked-list of tokens breaks recursion limit
The output of \GraphQL\Language\Parser::parse contains a tree in every 'loc' field which appears to branch forever:

Now, it doesn't go forever or it would crash for everyone. But get a schema large enough and it does break the recursion limit (default 4096) in unserialize() when being pulled out of cache (in Drupal).
What purpose do these endless recursive references to 'prev' and 'next' serve? Is it possible they could be limited or removed?
Or perhaps could we come up with a __serialize() member function to \GraphQL\Language\Token to teach the PHP serializer how to handle it?
I am going to categorize this as a bug, as I believe that serialization of AST nodes should be supported with default PHP settings.
A quick fix for you would be to use the parser option noLocation and bypass this issue. If you do not need the location, this is more efficient.
What purpose do these endless recursive references to 'prev' and 'next' serve? Is it possible they could be limited or removed?
They are neither endless, nor recursive. The tokens form a double-linked-list. I think this data structure was probably copied from the reference implementation graphql-js. It may be possible to optimize this by using something more well suited for PHP.
Or perhaps could we come up with a __serialize() member function to \GraphQL\Language\Token to teach the PHP serializer how to handle it?
I could see this working too, sure. Traversing the double-linked-list can most certainly be transformed into an iterative algorithm.
Thanks for the explanation :)
I'm afraid this pattern is very new to me (obviously) so I probably won't be able to help very much but I will if I can.