mirror of
https://github.com/graphql-python/graphene.git
synced 2025-07-18 03:52:24 +03:00
Merge a8cb8ca4c2
into 57cbef6666
This commit is contained in:
commit
11e6ac9686
|
@ -14,6 +14,14 @@ class InputObjectTypeOptions(BaseOptions):
|
||||||
container = None # type: InputObjectTypeContainer
|
container = None # type: InputObjectTypeContainer
|
||||||
|
|
||||||
|
|
||||||
|
_INPUT_OBJECT_TYPE_DEFAULT_VALUE = None
|
||||||
|
|
||||||
|
|
||||||
|
def set_input_object_type_default_value(default_value):
|
||||||
|
global _INPUT_OBJECT_TYPE_DEFAULT_VALUE
|
||||||
|
_INPUT_OBJECT_TYPE_DEFAULT_VALUE = default_value
|
||||||
|
|
||||||
|
|
||||||
class InputObjectTypeContainer(dict, BaseType): # type: ignore
|
class InputObjectTypeContainer(dict, BaseType): # type: ignore
|
||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
@ -21,7 +29,7 @@ class InputObjectTypeContainer(dict, BaseType): # type: ignore
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
dict.__init__(self, *args, **kwargs)
|
dict.__init__(self, *args, **kwargs)
|
||||||
for key in self._meta.fields:
|
for key in self._meta.fields:
|
||||||
setattr(self, key, self.get(key, None))
|
setattr(self, key, self.get(key, _INPUT_OBJECT_TYPE_DEFAULT_VALUE))
|
||||||
|
|
||||||
def __init_subclass__(cls, *args, **kwargs):
|
def __init_subclass__(cls, *args, **kwargs):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -16,7 +16,7 @@ from ..dynamic import Dynamic
|
||||||
from ..enum import Enum
|
from ..enum import Enum
|
||||||
from ..field import Field
|
from ..field import Field
|
||||||
from ..inputfield import InputField
|
from ..inputfield import InputField
|
||||||
from ..inputobjecttype import InputObjectType
|
from ..inputobjecttype import InputObjectType, set_input_object_type_default_value
|
||||||
from ..interface import Interface
|
from ..interface import Interface
|
||||||
from ..objecttype import ObjectType
|
from ..objecttype import ObjectType
|
||||||
from ..scalars import Int, String
|
from ..scalars import Int, String
|
||||||
|
@ -227,6 +227,20 @@ def test_inputobject():
|
||||||
assert foo_field.description == "Field description"
|
assert foo_field.description == "Field description"
|
||||||
|
|
||||||
|
|
||||||
|
def test_inputobject_undefined():
|
||||||
|
set_input_object_type_default_value(Undefined)
|
||||||
|
|
||||||
|
class OtherObjectType(InputObjectType):
|
||||||
|
optional_field = String()
|
||||||
|
|
||||||
|
type_map = create_type_map([OtherObjectType])
|
||||||
|
assert "OtherObjectType" in type_map
|
||||||
|
graphql_type = type_map["OtherObjectType"]
|
||||||
|
|
||||||
|
container = graphql_type.out_type({})
|
||||||
|
assert container.optional_field is Undefined
|
||||||
|
|
||||||
|
|
||||||
def test_objecttype_camelcase():
|
def test_objecttype_camelcase():
|
||||||
class MyObjectType(ObjectType):
|
class MyObjectType(ObjectType):
|
||||||
"""Description"""
|
"""Description"""
|
||||||
|
|
|
@ -30,7 +30,7 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
# backwards compatibility for v3.6
|
# backwards compatibility for v3.6
|
||||||
from typing import Pattern
|
from typing import Pattern
|
||||||
from typing import Callable, Dict, List, Optional, Union
|
from typing import Callable, Dict, List, Optional, Union, Tuple
|
||||||
|
|
||||||
from graphql import GraphQLError
|
from graphql import GraphQLError
|
||||||
from graphql.validation import ValidationContext, ValidationRule
|
from graphql.validation import ValidationContext, ValidationRule
|
||||||
|
@ -82,7 +82,7 @@ def depth_limit_validator(
|
||||||
|
|
||||||
|
|
||||||
def get_fragments(
|
def get_fragments(
|
||||||
definitions: List[DefinitionNode],
|
definitions: Tuple[DefinitionNode, ...],
|
||||||
) -> Dict[str, FragmentDefinitionNode]:
|
) -> Dict[str, FragmentDefinitionNode]:
|
||||||
fragments = {}
|
fragments = {}
|
||||||
for definition in definitions:
|
for definition in definitions:
|
||||||
|
@ -94,7 +94,7 @@ def get_fragments(
|
||||||
# This will actually get both queries and mutations.
|
# This will actually get both queries and mutations.
|
||||||
# We can basically treat those the same
|
# We can basically treat those the same
|
||||||
def get_queries_and_mutations(
|
def get_queries_and_mutations(
|
||||||
definitions: List[DefinitionNode],
|
definitions: Tuple[DefinitionNode, ...],
|
||||||
) -> Dict[str, OperationDefinitionNode]:
|
) -> Dict[str, OperationDefinitionNode]:
|
||||||
operations = {}
|
operations = {}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user