-
Hey, I'm currently creating a PoC for our company to provide a GraphQL server based on a Presto Cluster ( https://prestodb.io/ ). I was able to build a code generator which generates the code based on the given table schema. Since this is a custom data source which isn't compatible with Prisma, I had to create my own implementation for filtering, sorting, ordering. Sort and Order is fine for me, but I'm unsure about the filter implementation. I have extracted the relevant part with a working example.
Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Looks interesting, thanks for sharing! One things that jumps out at me is that you need some ts-ignores, what I would instead is have your helper methods return I see you are creating a seperate filter type for each column, this probably is over-kill you can probably just create a single IntFilter, StringFilter, etc and use the same filter type for every column of the same type. If you fix the typing for your scalar filter types, you probably won't need the interfaces for many of your object types. Passing in an interface as a generic is really only required if you have cicular references, so in many cases, you could probably just leave out the interface and define the the input type with |
Beta Was this translation helpful? Give feedback.
-
Hi @hayes, thanks for the feedback.
Yes, that makes sense
For the object types, I agree with you, there I don't need it. Same for Paging and Sorting Inputs. My challenge is/was the filter, since I want to allow Anyway... I think I solved the challenge with the filter. Instead of const FilterInput = builder
.inputRef<FilterInputInterface>('Example3FilterInput')
.implement({ i use now const FilterInput = builder.inputRef('Example3FilterInput').implement({ Since I removed the I also changed some parts in the comparison helper to have it a bit more generic. All changes can be found here: https://github.com/noxify/pothos-filter/pull/1/files I hope I understood everything correctly - If I have missed something, please let me know. Thanks again for all your input ❤️ Btw. If you think this code could be helpful for others ( e.g. in the docs or as example repo ), feel free to copy what you need. |
Beta Was this translation helpful? Give feedback.
Looks interesting, thanks for sharing!
One things that jumps out at me is that you need some ts-ignores, what I would instead is have your helper methods return
InputObjectRef
s of the correct type, that way when you are using them to implement filters objects you don't need that ts-ignoreI see you are creating a seperate filter type for each column, this probably is over-kill you can probably just create a single IntFilter, StringFilter, etc and use the same filter type for every column of the same type.
If you fix the typing for your scalar filter types, you probably won't need the interfaces for many of your object types. Passing in an interface as a generic is really only required if …