Replies: 3 comments 2 replies
-
This makes sense! This enables to stick to the SoC principle in terms of development and will keep the core a bit more easier to read and extend. Got one question though, Is this going be optional for anyone extending medusa or developing a plugin ? Since it's a matter of chaining express middleware it alright for it to be an optional way of developing yeah ? Raising this concern, because Medusa is getting a lot traction, and new developers might find it too overwhelming catch everthing. |
Beta Was this translation helpful? Give feedback.
-
This helps decouple the services and the routes in general and seems like a great step forward! Allows for greater code reusability as well as readability. |
Beta Was this translation helpful? Give feedback.
-
I think it's a great idea! I love all the Nestjs patterns |
Beta Was this translation helpful? Give feedback.
-
Hello there, here is the new subject I wanted to write up.
Why now
I have been able to do quite some reviews and walk along the code base for a good time now.
What I have seen so far, is that when create a new endpoint, everything that is related to
Is done by the endpoint itself.
How it can solve the problem
From my point of view, moving the points I cited above to an higher level would allow to decoupled those step from the endpoint itself which will result in the following
Story
From my background with nestjs I've seen how that approach can be powerful when well used and it can solve a lot of problem about code decoupled as well as centralisation of common tasks across the all app endpoints.
That approach is not new and already exists, so there is only the needs to implement it if that makes enough sense
and that's why we would like your feedback and opinions on that matter
Actual schema
Proposal schema
Examples
Let see some example on how that can be translated into code
for the following example lets take the following endpoint (imaginary exndpoint)
GET /admin/files/:file_id
Now let see a guard to check the security on the file
If we wanted now to create a file on
POST /admin/files
let see some pipes to manipulate the data and query
In the end, we can compose a route as follow
All the common middleware that are applied on the same sub routes could be applied on a parent
/admin/files/:file_id
and then all the routes under that path would work as usual and they would already be prepared and validated. in the handler we would already have access to the entity and now that it is validated and sure. also, for path where there is some inter dependance that must be checked, it could be done the same way and in the end in the handler we would know that the relations between inter dependent entity would have been checked already and that we are in a valid context once we are in the handler.for the post routes we would have something like
Conclusion
Hope that it is comprehensible enough, if there is any question or feedback do not hesitate to post it here :)
Example
https://github.com/medusajs/medusa/pull/1396/files
Beta Was this translation helpful? Give feedback.
All reactions