From fd45ff6f74080d8b55cc0917fb923eb8ae163327 Mon Sep 17 00:00:00 2001 From: Ricardo Dahis Date: Mon, 30 Mar 2026 12:38:49 +1100 Subject: [PATCH 1/2] add m2m mutation to GraphQL --- backend/custom/graphql_auto.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/backend/custom/graphql_auto.py b/backend/custom/graphql_auto.py index 48462b43..6d3bd312 100644 --- a/backend/custom/graphql_auto.py +++ b/backend/custom/graphql_auto.py @@ -429,6 +429,13 @@ def __init_subclass_with_meta__( _meta=_meta, input_fields=input_fields, **options ) + @classmethod + def perform_mutate(cls, form, info): + obj = form.save() + if hasattr(form, "save_m2m"): + form.save_m2m() + return cls(errors=[], **{cls._meta.return_field_name: obj}) + @classmethod def get_form_kwargs(cls, root, info, **input): # Get file data From 5dc9c0a045fbcc66bb95b8d57ffdddf9e1a74338 Mon Sep 17 00:00:00 2001 From: Ricardo Dahis Date: Mon, 30 Mar 2026 16:29:13 +1100 Subject: [PATCH 2/2] fix(graphql): use commit=False + save_m2m() to ensure M2M fields are saved in mutations --- backend/custom/graphql_auto.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/custom/graphql_auto.py b/backend/custom/graphql_auto.py index 6d3bd312..7b021d4d 100644 --- a/backend/custom/graphql_auto.py +++ b/backend/custom/graphql_auto.py @@ -431,9 +431,9 @@ def __init_subclass_with_meta__( @classmethod def perform_mutate(cls, form, info): - obj = form.save() - if hasattr(form, "save_m2m"): - form.save_m2m() + obj = form.save(commit=False) + obj.save() + form.save_m2m() return cls(errors=[], **{cls._meta.return_field_name: obj}) @classmethod