Skip to content

Mutation namespaces #440

Description

@ChvilaMartin

Hello, hopefully this is not duplication of existing issue.

Is there support for Mutation namespaces like described there: https://graphql-rules.com/rules/mutation-namespaces?

What I want is to be able to have something like this

UserMutations {
   create(name: String!): String!,
   update(id: String!, name: String!): Boolean!,
   ....
},
PostMutations {
   ...
}

Activity

  1. oojacoboo commented on Feb 11, 2022

    @oojacoboo
    Collaborator

    @ChvilaMartin that's pretty cool. Unfortunately, that's not currently supported. I also don't see any support for this with https://github.com/webonyx/graphql-php. We'd need support there before adding support for that here.

  2. enumag commented on Feb 17, 2022

    @enumag

    @oojacoboo Webonyx supports it just fine. Or rather no additional support on their side is needed to implement it. I'm using it on another webonyx-based project. Here is how it works:

    First I have types like these, representing the mutation namespaces:

    final class UserMutationsType extends ObjectType
    {
        public function __construct()
        {
            parent::__construct([
                'name' => 'UserMutations',
                'fields' => function () {
                    return [
                        'create' => [
                            // definition of the create mutation
                        ],
                    ];
                },
            ]);
        }
    }

    Next the MutationType needs to use these:

    final class MutationType extends ObjectType
    {
        public function __construct(ContainerInterface $typeResolver)
        {
            parent::__construct([
                'name' => 'Mutation',
                'fields' => function () use ($typeResolver) {
                    return [
                        'user' => [
                            'type' => $typeResolver->get('UserMutations'),
                            'resolve' => function ($value, $args, $context, ResolveInfo $info) {
                                return [];
                            },
                        ],
                    ];
                },
            ]);
        }
    }

    Easy enough in my opinion.

  3. oojacoboo commented on Feb 17, 2022

    @oojacoboo
    Collaborator

    @enumag thanks for the clarification here. This seems like a worthwhile improvement if someone wants to add a PR. It might be helpful to discuss implementation proposals prior.

  4. Lappihuan commented on Apr 22, 2022

    @Lappihuan
    Contributor

    I've been thinking about this lately and feel like a Namespace Attribute on Controllers would be the most logical.
    Imagine:

    #[GQL\Namespace]
    class UserController {
        #[GQL\Query]
        public function user()...
    
        #[GQL\Mutation]
        public function create()...
    
        #[GQL\Mutation]
        public function update()...
    
        #[GQL\Mutation]
        public function delete()...

    Which would result in this Schema:

    UserMutations {
       create()...
       update()....
       delete()...
    }
    

    While the user Query is ignored by the Namespace and still directly under the Root Query.

  5. enumag commented on Apr 22, 2022

    @enumag

    It's actually already possible with current graphqlite. No extra features are necessary, just usage of the existing attributes, mainly ExtendType and Field.

  6. Lappihuan commented on Apr 22, 2022

    @Lappihuan
    Contributor

    I mean yes its possible, but but hacky.
    And the goal of graphqlite is great DX, with the Namespace Attribute it can be backwards compatible and easily added to existing projects with very little work.

  7. oojacoboo commented on Apr 22, 2022

    @oojacoboo
    Collaborator

    @Lappihuan I like the namespace attribute idea. This would create a clean API in GraphQLite.

  8. Lappihuan commented on Apr 26, 2022

    @Lappihuan
    Contributor

    @oojacoboo i'd like to base this on the work of #466 should i branch from there or do you see #466 merged soon?

  9. oojacoboo commented on Apr 26, 2022

    @oojacoboo
    Collaborator

    I'd like to get #466 merged into master soon and target a 6.0 release. I haven't had a chance to test any of it yet. Any additional eyes on it would be helpful.

  10. oojacoboo commented on Apr 26, 2022

    @oojacoboo
    Collaborator

    @Lappihuan let's keep it in another branch though. #466 already has way too much in it. I'd really like to keep things separated out. It makes it much easier to focus discussion, reviews and merges. I know it's a bit more work on the PR creation side.

  11. pinned this issue on Jun 12, 2022
  12. oojacoboo commented on Jul 7, 2022

    @oojacoboo
    Collaborator

    The PR attempt for adding mutations was closed and not merged. See the PR for additional details and reasoning.

    There is an ongoing proposal to add metadata support to the GraphQL spec. This is probably the ideal way of handling this need.

    I'm going to leave this ticket open, as the need for some sort of namespace like support still exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    additional info neededAdditional information is needed to proceeddependenciesPull requests that update a dependency fileenhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions