Skip to content

[Feature Request?] Option to not expose GraphQL mutation #8099

Closed

Description

@Koenstell

Description
I'm currently building a GraphQL api endpoint that has a number of mutation to create/update/delete entities. Some entities are more complex and have various relations to other entities. For example, entity A has a OneToMany relationship to entity B. Now, to be able to create B entities from entity A, we need to add a 'create' mutation on entity B, otherwise it doesn't work.

Now, this works, but this results in two mutations being exposed:

  • mutation createA()
  • mutation createB()

In our app (which is the only consumer of this API, we only use createA(), so to reduce potential threat surfaces we want to NOT expose the createB() mutation.

Example

#[ApiResource(
    operations: [],
    paginationEnabled: false,
    graphQlOperations: [
        new Mutation(
            normalizationContext: ['groups' => ['read:A']],
            denormalizationContext: ['groups' => ['write:A']],
            name: 'create',
        ),
    ],
)]
class A
{
    // ... 
    #[ORM\OneToMany(mappedBy: 'backToA', targetEntity: B::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
    #[Groups(['read:A', 'write:A'])]
    private Collection $bReferences;
    // ... 
}

#[ApiResource(
    operations: [],
    paginationEnabled: false,
    graphQlOperations: [
        new Mutation(
            normalizationContext: ['groups' => ['read:A']],
            denormalizationContext: ['groups' => ['write:A']],
            name: 'create',
            expose: false, // <-- I was looking for something like this. 
        ),
    ],
)]
class B 
{
    // ... 
}

If this happens to be already possible, I'm eager to learn how, but I don't think it's currently doable.

Activity

  1. added theissue type on May 29, 2026
  2. soyuka commented on Oct 1, 2026

    @soyuka
    Member

    this is already possible, declare graphQlOperations: [] on B: we then add nested-only queries to it, so it can be embedded in createA's input while no createB mutation (nor root query) is exposed in the schema. Added a test covering it in #8629.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions