-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Muatation namespace #475
Muatation namespace #475
Conversation
Thanks for this @Lappihuan. Firstly, is there any reason why we're limiting namespaces to mutations and not queries as well? I'm assuming we can also namespace queries? And, in this case, a Regarding the default namespacing name, this is going to be contentious, as everyone is going to have different "controller" class names. For instance, our "controller" namespace is |
@oojacoboo As for the Attribute name, I don't see this being usefull for Queries. And about Types, its just that a Type with fields, you'd be better to nest two types. As for the naming, its just masking I actually forgot to set this as a Draft since there is quite a bit of stuff in the Technical implementation that should be improved. I'm unsure if those fields and Types should be created by a |
Can we add a possibility to specify a namespace as of We use invokable controllers with a single method in every class, so adding attribute over class (operation-related attribute already specified over method) would be a bit uncomfortable :) |
Co-authored-by: Andrii Dembitskyi <andrew.dembitskiy@gmail.com>
@andrew-demb do you have an example of such a invokable Controller? Maybe to clarify, this is not a spec or anything special, its just a convention that should bring some DX to graphqlites way of grouping Root Level Mutations with controllers. |
@Lappihuan
Am I be correct if it will require to make some additional layer of classes with logic for "namespaced mutations"? I think best variant for me will be a possibility to specify |
@Lappihuan makes sense and after reviewing our schema, applying namespaces to mutations is really all that's needed. We already have around 100 mutations and only a portion of our apps are using GraphQL. Luckily we have a decent pattern in place, but it's already becoming more problematic to find mutations.
https://graphql-rules.com/rules/mutation-namespaces This list of rules are great overall. The one on mutation namespaces does a pretty good job explaining the problem namespaces solve for others interested. @andrew-demb makes a good point about defining namespaces on What if we keep #[GQL\MutationNamespace(name: 'User')]
class UserController {
#[GQL\Query]
public function user()...
#[GQL\Mutation]
public function create()...
#[GQL\Mutation]
public function update()...
#[GQL\Mutation]
#[GQL\MutationNamespace(name: ['User', 'Role'])]
public function delete()... |
@oojacoboo @andrew-demb #[GQL\MutationNamespace(name: 'UserMuatations')]
#[GQL\MutationNamespace(name: 'UserQueries')]
#[GQL\MutationNamespace(name: 'Misc')]
class UserController {
#[GQL\Query(for: "UserQueries")]
public function user()...
#[GQL\Query(for: "UserQueries")]
public function userAlt()...
#[GQL\Mutation(for: "UserMuatations")]
public function create()...
#[GQL\Mutation(for: "UserMuatations")]
public function update()...
#[GQL\Mutation(for: ["UserMuatations","Misc"])]
public function delete()...
#[GQL\Mutation(for: "Misc")]
public function computeX()... This gives quite a lot of flexibility and should also integrate with your Invokable Controller pattern as far as i can tell @andrew-demb I'd actually also like to add the ability to define multiple |
@Lappihuan The What |
@oojacoboo yes i'd hope so, but i'm still a bit unsure about the implementation of the whole thing. The output Type annotation https://graphqlite.thecodingmachine.io/docs/annotations-reference#type-annotation |
Misread you on the As for the API design, I love it 🎉 |
Now i'd actually call it |
Mutations and queries are called "operations". So, |
@Lappihuan now that 6.0 is released, it'd be great to get this merged in for 6.1. |
@Lappihuan hope we haven't lost you. What do we need to do to get this one merged in? |
Anyone else interested in helping wrap up this PR? |
I've since learned this should not be done with the current gql spec: MichalLytek/type-graphql#1219 (comment) |
@Lappihuan thanks for the update. I did a little more digging into this topic - interesting and certainly not obvious without a pretty strict interpretation of the spec. Nonetheless, it probably is something we should avoid. Here is a good article that discusses the topic in detail. There is an ongoing proposal to add metadata support to the GraphQL spec. This is probably the ideal way of handling this need. |
This PR adds the ability to turn a
Controller
into a Mutation Namespace as described in #440The specific Implementation adds a
MutationNamespace
Attribute/Annotation which can optionally be added to a Controller to wrap all its mutations into a Mutation Namespace.This would look something like this:
Which turns into:
There is a optional
name
parameter on theMutationNamespace
Attribute to rename automatically generated Namespace.The automatically generated Namespace is the
Classname
-Controller
+Muatations
which turns UserController into UserMutations.All queries in the Controller are completely unaffected.