Skip to content

Conversation

Skullsneeze
Copy link
Contributor

@Skullsneeze Skullsneeze commented Jun 30, 2025

This PR adds the ability to add GraphQL mutations via config to statamic.

Reason for this feature

When creating a headless application there are various cases where you might want to work with GraphQL mutations. One example could be form submissions.

How to use it

In your project update graphql.php to add mutations. For example:

'mutations' => [
    SubmitFormMutation::NAME => SubmitFormMutation::class
],

Your mutation can be defined in a class like this:

<?php

namespace App\GraphQL\Mutations;

use GraphQL\Type\Definition\Type;
use Rebing\GraphQL\Support\Mutation;

class SubmitFormMutation extends Mutation
{
    public const NAME = 'submitForm';

    protected $attributes = [
        'name' => self::NAME,
    ];

    public function type(): Type
    {
        return GraphQL::type(SubmitFormResponse::NAME);
    }

    public function args(): array
    {
        return [
            'input' => Type::string(),
        ];
    }

    public function resolve($root, $args)
    {
        return 'Mutations response!';
    }
}

This will then allow you to run a mutation query like this:

mutation SubmitForm($input: String = "") {
  submitForm(input: $input)
  }
}

@Skullsneeze Skullsneeze changed the title Allow adding of GraphQL mutations [5.x] Allow adding of GraphQL mutations Jun 30, 2025
@samalisam-novu
Copy link

would love to have this in main🥲

@duncanmcclean
Copy link
Member

Sorry, we don't have an ETA for reviewing/merging this pull request. We'll get to it when we can.

In the meantime, you can pull this PR into your project with a composer patch.

@samalisam-novu
Copy link

@duncanmcclean alright, thanks for the fast answer.

@ryanmitchell
Copy link
Contributor

@samalisam-novu I'd suggest adding a test to show that the code changes work as expected

@jasonvarga jasonvarga merged commit cc656ce into statamic:5.x Oct 13, 2025
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants