-
-
Notifications
You must be signed in to change notification settings - Fork 916
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
Restrict list types in GetGraphTypeFromType #3099
Conversation
Unfortunately my patch is required in multiple private libraries - ugh! |
Let's keep it in 5.x.x timeline but with new global option that by default preserves old behavior. This option may be deprecated in v6. |
Co-authored-by: Ivan Maximov <sungam3r@yandex.ru>
…et/graphql-dotnet into restrict_list_types
Codecov Report
@@ Coverage Diff @@
## master #3099 +/- ##
==========================================
- Coverage 84.40% 84.30% -0.10%
==========================================
Files 361 362 +1
Lines 15853 15884 +31
Branches 2578 2580 +2
==========================================
+ Hits 13380 13391 +11
- Misses 1859 1876 +17
- Partials 614 617 +3
Continue to review full report at Codecov.
|
@sungam3r I added more details to the xml comment for the global switch if you want to review it. |
I keep running into this problem in my code:
GetGraphTypeFromType
takes classes that inherit or implement a list or dictionary type and assign it a graph type mapping of theKeyValuePair
rather than the object as a whole.For example:
My workaround is currently as follows:
GetGraphTypeFromType
methodTypeInformation
and overrideConstructGraphType
to use the new methodAutoRegisteringObjectGraphType
and overrideGetTypeInformation
to use the new classAutoRegisteringObjectGraphType
is requested.My suggested fix is to only detect explicit enumerable types that we have already predefined in the
TypeInformation
class:IEnumerable
IEnumerable<>
IList<>
List<>
ICollection<>
IReadOnlyCollection<>
IReadOnlyList<>
HashSet<>
ISet<>
Any derived types from those types will not be detected as a list. This is a breaking change, and if someone is relying on the prior behavior, they will need to cast their custom return type to a detected list type. For example:
My workaround (described above) contains almost 200 lines of code to fix this problem (mostly copied from the main library). I suggest we fix it in the main library. However, it is a breaking change and there may be existing code that relies on the current behavior. As much as I would like to see it in 5.1 for my own needs, I suggest this be a change for 6.0. I can live with my existing workaround.
An alternative option would be to make this a global option. Even though I generally discourage global options, this really seems like a pain point (for me) that we can get rid of rather easily.