-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix flow type generation for recursive input types
Summary: This is proposed as an alternative to D6770669 This is proposed as an alternative to #2142. Credit goes to benjaminogles for his original work in PR #2142 to fix this issue which ultimately led to this commit. === Motivation Previously, if your GraphQL schema defined recursive input types, e.g.: ``` input InputA { field1: Int, fieldB: InputB, } input InputB { field1: String, fieldA: InputA, } ``` The relay compiler would crash with a stack overflow error. === Solution This was originally fixed in #2142 by determining recursive type definitions ahead of time and imposing a recursion limit on those fields. This commit fixes the problem by generating separate flow types for input object types and referencing them recursively. This works because recursive types are allowed in flow. The above example would produce the following flow type output: ``` export type InputA { field1: number, fieldB: InputBInputT, } export type InputB { field1: string, fieldA: InputAInputT, } ``` Other types like `<>Variables` types that we generate also reference these new types. == Caveats - This is a bit wasteful because it will generate and export the same flow types in different generated flow definition files. I /think/ this isn't a major concern given that flow types don't affect runtime in any way. To prevent confusion about the duplicate types, we could consider not exporting them and just generating them as private types in the module. - I /believe/ this shouldn't cause name conflicts given that these types are scoped by generated file. Reviewed By: kassens Differential Revision: D7022100 fbshipit-source-id: 10bfb80ca3e58ae8f98ed82ae6e87e7ba6a52b87
- Loading branch information
1 parent
c78e2b6
commit 6d49a52
Showing
4 changed files
with
76 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters