Skip to content

[5.x] Allow adding of GraphQL mutations #11908

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

Open
wants to merge 3 commits into
base: 5.x
Choose a base branch
from

Conversation

Skullsneeze
Copy link

@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
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.

1 participant