Skip to content

DjangoModelFormMutation getting "an invalid keyword argument for Mutation" error instead of model form errors #922

Closed
@Aljabri-Salman

Description

@Aljabri-Salman

When using DjangoModelFormMutation and getting a modelform error the mutation shows an invalid keyword argument for Mutation as shown below. I am supposed to get errors for the field name showing "This name has already been registered." However I am getting graphql.error.located_error.GraphQLLocatedError: 'name' is an invalid keyword argument for CategoryMutation

# model
class Category(models.Model):
    name = models.CharField(max_length=10, unique=True,
                 error_messages={'unique':"This name has already been registered."})

    def __str__(self):
        return self.name

#model form
class CategoryForm(ModelForm):
    class Meta:
        model = Category
        exclude = []

# create category mutation
class CategoryMutation(DjangoModelFormMutation):
    category = graphene.Field(CategoryType)
    class Meta:
        form_class = CategoryForm

mutation:

mutation {
  categoryCreate(input: {name: "spices"}) {
    errors {
      field,
      messages
    }
  }
}

results when the name is not unique:

{
  "errors": [
    {
      "message": "'name' is an invalid keyword argument for CategoryMutation",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "categoryCreate"
      ]
    }
  ],
  "data": {
    "categoryCreate": null
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions