Filtering on abstract types #4849
Replies: 3 comments
-
So small example whats the idea for unionresolvers (include filters)... This is not for UseSelection.. This can help you to implement Union loader Current model can work without filters.. You can specify as much loaders as you wanna and run them without writing custom resolver for unions.. You can reuse loaders that you already have.. This is example that include some commented parts for filters that are not implemented... This is example don`t check types of dataloader and use GetType() to get it in run-time.. To be Type-safe it is necessary to get type from data-loader base class.. what is bit not easy..
Than from code you can do this:
Currently im using only generic version of union resolver and i have separate mid. for filtering as you can see filter part is just commented out... The goal is connect UnionResolver with filters.. |
Beta Was this translation helpful? Give feedback.
-
so we have two options here at the moment. input FooBarInputType {
foo: FooFilterInputType
bar: BarFilterInputType
} This approach would also allow to specify different filter cases for foo and bar Second option is to wait for the input union spec I guess it makes sense to wait in any case to see if how ever this turns out could be helpful for us |
Beta Was this translation helpful? Give feedback.
-
Cool that they are working on spc. for this... that make more sense to wait for now and use only custom workaround until something will be published... |
Beta Was this translation helpful? Give feedback.
-
Feature request:
It can be nice if new Filter API provides option to filter Interfaces or Unions by __typename..
Unions implements some interface and Filtering generate filters from props in this interface.. (out of gql type). Idea is to add there option for filter by type and provide string as name for it as filter input...
It can be build in or require to call .AddTypeFilter()..
Currently
You needed to write special middleware or custom resolver for that... this can be in case of connections more difficult or you need to add Type field to your base object and get it from there.
Just example of current what you need to do.. in case you have 20 types it can get more ugly and there is possible way to add filtering based on typename or create smart resolver that take array of dataloaders and generate filters and call them conditionally..
Idea:
Idea is to just specify typefilter and HC will generated this in case of interface for you... Is easy way it will just compare type with inputfilter type of string.
In case of __typename:
In case of smartunionresolver
Advantages: Easy to filter types in unions..
Disadvantages: __typename can differs from base type, sometimes it is better to put it in resolver to avoid filtering after...
Problems with advanced:
Beta Was this translation helpful? Give feedback.
All reactions