-
Notifications
You must be signed in to change notification settings - Fork 5
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
Warn when a factory would lead to an infinite loop #59
Comments
Is
|
aw the schema should be like this: type ProductCategory {
parent_category: ProductCategory!
} i would like to talk about the case if the field is non-nullable :p |
That's an interesting use case, not sure what would be best here as the schema defines an infinite recursion. So it's impossible to satisfy the type definition, unless perhaps through a circular dependency but that would not make much sense. How where you intending to test this code @japboy? Having a better understanding of your expectations could help here. What do you think @ertrzyiks? Perhaps we should raise an error/warning or offer an option to trick TypeScript (for example through some |
From a quick search I see people advice against it as you can't write a query that fetches all the levels of nesting. People who actually need non-nullable recursive seem to have some limits in mind on how many levels of nesting they need. @zhouzi It would be possible to limit the depth of the resolution in the context of operation, but not in the context of the type itself which is infinitely recursive indeed. I'm also curious what @japboy expects the function to return in this case. I think it would be nice to tell people that this is not supported with some error or warning indeed. Like
but we should be able to generate the shape that fulfils a query/mutation expected response shape where the level of nesting is known and fixed. |
@zhouzi @ertrzyiks thanks for your feedback! well my use case is actually sort of exceptional. there is a schema which has nullable fields only and i need to generate non-nullable mock functions for the fields. so i wrote a patch with and i feel like this comment is intuitive for me: perhaps i can add another option like
agreed. limitation is maybe passed by variables and its not expressed with types... |
I think that would be a great solution as it's not possible to create an object with infinite depth. You would still be able to create nested objects in your code:
With that being said, I agree with @ertrzyiks that this plugin should better inform users in this case. I think ideally it would raise an error when generating the mocks (build time as opposed to runtime). Let's add that 👍 |
Let's say I have a GraphQL schema like below:
And this generates mock function like below:
And this cause
Maximum call stack size exceeded
error. Do I just need to change the parent type different name? Any thoughts? Thanks.The text was updated successfully, but these errors were encountered: