Skip to content
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

inferring input type from (plugin-created) fields breaks with circularity #2420

Closed
jasonphillips opened this issue Oct 11, 2017 · 3 comments
Closed

Comments

@jasonphillips
Copy link
Contributor

When using the plugin API to add new fields to the graphql schema (using setFieldsOnGraphQLNodeType), if the subtree under my added fields contains any circular references (for example, custom field relatedBooks of type RelatedBooks might point to Author and then back to Book -> RelatedBooks type again), I end up with a Maximum call stack size exceeded error that points back to infer-graphql-input-fields-from-fields, where the automated detection of fields is infinitely traversing the tree of self-referential types until memory crashes.

What's the best way to solve this one? In my use case, I can't really avoid some circularity without losing the entire purpose of my plugin. Would it be best to pursue a way for plugins to manually disable the input fields inference (although I don't see any of the other "hook" functions taking top-level options, so not clear how best to structure that without breaking backwards functionality), or would it be better to simply dive deep into that recursive inference function and prevent infinite recursion by tracking types already seen?

The functionality causing the issue was added back in #2075

@jasonphillips
Copy link
Contributor Author

I should add that I've tested hard-disabling the input fields inference function in a local branch of gatsby, and that indeed solved the problem; circularity does not break any other part of gatsby's graphql schema layer, only the input type inference.

@KyleAMathews
Copy link
Contributor

dive deep into that recursive inference function and prevent infinite recursion by tracking types already seen

Yeah, this seems like a good approach. Would you like to put together a PR exploring this option?

@jasonphillips
Copy link
Contributor Author

Solved in #2436 and merged, thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants