remorses / mongoke

https://mongoke.now.sh/docs/
216 stars 12 forks source link

Does mongoke supports mutations? #6

Open jmorakuebler opened 4 years ago

jmorakuebler commented 4 years ago

Hello @remorses, this project is awesome, very easy set up and deploy. But I have one question, does mongoke supports mutations? I'm planning on creating a database from scratch for insertion and query. Many thanks in advance.

remorses commented 4 years ago

Currently no, I created mongoke as a way to query your database from the frontend client, implementing mutations this way is an anti pattern, you would add a lot of complex logic in the client side, making the bundle size a lot bigger.

Another problem that arises when you implement mutations directly in the client is that usually you don’t mutate a single collection in database, but instead you change many resources (like change a user object and a blogPost object), if you mutate from the client there is the possibility that the database becomes inconsistent if all the mutations don’t end successful and there is no way you can handle the case the client disconnects

A better alternative is to implement mutations in a different api that talks directly to the database, this way you separate the complex logic from the client, making the code base cleaner

To connect the api you can use an Apollo federation gateway to connect the 2 services, check out the federation example in the examples directly

If you think mutations are useful I can maybe implement them and enable them via the configuration file with an option

remorses commented 4 years ago

I am now thinking that mutations would be useful in server side to have a typed client like prisma does, will implement them in the near future

Let me know what would be an ideal api and schema you would like