Design for MongoDB generic resolver #3743
Unanswered
BaptisteGi
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello!
I have a setup with Hot-chocolate and MongoDB. This is a sample of my database schema:
Basically every entity is stored as a separate document. Reference to "parent" entity is directly stored in the document (e.g. in contact document there is a "accountID" field containing the linked account identifier).
Here I can run this kind of GraphQL query:
On server side I have a "AccountResolvers" class that resolves orders and contacts relationships:
The concern I have so far is that I'm introducing a lot of boilerplate code (only types are different).
That being said, I tried to create a generic resolver:
Then tried to attach it to fields using "ObjectFieldDescriptorAttribute" (I kinda like the "annotation-based" approach).
At the end the syntax is not the most elegant I've ever seen (might probably be improved) but it would allow me to define everything at model level and then get rid of all the boilerplate resolver code. It was without counting on the fact that C# is not supporting generic attributes and it seems that it won't change anytime soon... C# compiler roadmap
I'm a bit in a dead end with my design here. I'm currently having a look on how default resolver works with hot-chocolate (maybe find a way to make it fits with my setup), also having a look on projection... I have two constraints: first is that I can't really change database structure, second is that I would like to keep schema changes (adding new entity, new field) as simple as possible (just some lines in the model would be the best) to have something which is more a configuration task rather than some development.
Would like to check with you if there is any viable workaround to this C# limitation? If some of you found a different answer to this generic resolver question? Suggestions are welcome!
Thanks! ✌️
Beta Was this translation helpful? Give feedback.
All reactions