Skip to content

Commit

Permalink
The return field name should be in snake case in python
Browse files Browse the repository at this point in the history
  • Loading branch information
bellini666 committed Nov 22, 2021
1 parent cca6305 commit a2f93ae
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 22 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
author = "Zerosoft Tecnologia LTDA"

# The full version, including alpha/beta/rc tags
release = "4.2"
release = "4.3"


# -- General configuration ---------------------------------------------------
Expand Down
32 changes: 25 additions & 7 deletions graphene_django_plus/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@
import collections
import collections.abc
import itertools
from typing import Any, ClassVar, Dict, Generic, List, Optional, Type, TypeVar, cast
from typing import (
TYPE_CHECKING,
Any,
Dict,
Generic,
List,
Optional,
Type,
TypeVar,
cast,
)

from django.core.exceptions import NON_FIELD_ERRORS, ImproperlyConfigured
from django.core.exceptions import PermissionDenied as DJPermissionDenied
Expand All @@ -17,7 +27,7 @@
from graphene.types.mutation import MutationOptions
from graphene.types.objecttype import ObjectType
from graphene.types.utils import yank_fields_from_attrs
from graphene.utils.str_converters import to_camel_case
from graphene.utils.str_converters import to_camel_case, to_snake_case
from graphene_django.converter import convert_django_field_with_choices
from graphene_django.registry import Registry, get_global_registry
from graphql.error import GraphQLError
Expand All @@ -43,7 +53,7 @@

def _get_model_name(model):
model_name = model.__name__
return model_name[:1].lower() + model_name[1:]
return to_snake_case(model_name[:1].lower() + model_name[1:])


def _get_output_fields(model, return_field_name, registry):
Expand Down Expand Up @@ -198,8 +208,12 @@ class BaseMutation(ClientIDMutation):
class Meta:
abstract = True

#: Meta options for the mutation
_meta: ClassVar[BaseMutationOptions]
if TYPE_CHECKING:

@classmethod
@property
def _meta(cls) -> BaseMutationOptions:
...

#: A list of errors that happened during the mutation
errors = graphene.List(
Expand Down Expand Up @@ -372,8 +386,12 @@ class BaseModelMutation(BaseMutation, Generic[_T]):
class Meta:
abstract = True

#: Meta options for the mutation
_meta: ClassVar[ModelMutationOptions[_T]]
if TYPE_CHECKING:

@classmethod
@property
def _meta(cls) -> ModelMutationOptions[_T]:
...

@classmethod
def __init_subclass_with_meta__(
Expand Down
20 changes: 7 additions & 13 deletions graphene_django_plus/types.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
import datetime
import decimal
from typing import (
TYPE_CHECKING,
Any,
ClassVar,
Generic,
List,
Optional,
Type,
TypeVar,
Union,
)
from typing import TYPE_CHECKING, Any, Generic, List, Optional, Type, TypeVar, Union

from django.contrib.auth.models import AbstractUser, AnonymousUser
from django.core.exceptions import ImproperlyConfigured
Expand Down Expand Up @@ -309,8 +299,12 @@ class ModelType(_BaseDjangoObjectType, Generic[_T]):
class Meta:
abstract = True

#: Meta options for the mutation
_meta: ClassVar[ModelTypeOptions[_T]]
if TYPE_CHECKING:

@classmethod
@property
def _meta(cls) -> ModelTypeOptions[_T]:
...

@classmethod
def __class_getitem__(cls, *args, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "graphene-django-plus"
version = "4.2"
version = "4.3"
description = "Tools to easily create permissioned CRUD endpoints in graphene."
authors = ["Thiago Bellini Ribeiro <thiago@bellini.dev>"]
license = "MIT"
Expand Down

0 comments on commit a2f93ae

Please sign in to comment.