mirror of
https://github.com/graphql-python/graphene.git
synced 2025-12-10 11:44:33 +03:00
Merge 8c97ce12f0 into 8290326308
This commit is contained in:
commit
2910fda939
|
|
@ -7,12 +7,12 @@ from .utils import yank_fields_from_attrs
|
|||
|
||||
# For static type checking with type checker
|
||||
if TYPE_CHECKING:
|
||||
from typing import Dict, Callable # NOQA
|
||||
from typing import Dict, Callable, Type # NOQA
|
||||
|
||||
|
||||
class InputObjectTypeOptions(BaseOptions):
|
||||
fields = None # type: Dict[str, InputField]
|
||||
container = None # type: InputObjectTypeContainer
|
||||
container = None # type: Type[InputObjectTypeContainer]
|
||||
|
||||
|
||||
# Currently in Graphene, we get a `None` whenever we access an (optional) field that was not set in an InputObjectType
|
||||
|
|
@ -103,8 +103,8 @@ class InputObjectType(UnmountedType, BaseType):
|
|||
else:
|
||||
_meta.fields = fields
|
||||
if container is None:
|
||||
container = type(cls.__name__, (InputObjectTypeContainer, cls), {})
|
||||
_meta.container = container
|
||||
container = InputObjectTypeContainer
|
||||
_meta.container = type(cls.__name__, (container, cls), {}) # type: ignore
|
||||
super(InputObjectType, cls).__init_subclass_with_meta__(_meta=_meta, **options)
|
||||
|
||||
@classmethod
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
from graphql import Undefined
|
||||
import pytest
|
||||
|
||||
from ..argument import Argument
|
||||
from ..field import Field
|
||||
from ..inputfield import InputField
|
||||
from ..inputobjecttype import InputObjectType
|
||||
from ..inputobjecttype import InputObjectType, InputObjectTypeContainer
|
||||
from ..objecttype import ObjectType
|
||||
from ..scalars import Boolean, String
|
||||
from ..schema import Schema
|
||||
|
|
@ -167,3 +168,16 @@ def test_inputobjecttype_default_input_as_undefined(
|
|||
|
||||
assert not result.errors
|
||||
assert result.data == {"undefinedOptionalsWork": True}
|
||||
|
||||
|
||||
def test_inputobjecttype_explicit_container():
|
||||
class MyInputObjectType(InputObjectType):
|
||||
class Meta:
|
||||
container = InputObjectTypeContainer
|
||||
|
||||
first_name = String()
|
||||
last_name = String()
|
||||
|
||||
container = MyInputObjectType._meta.container(first_name="John")
|
||||
assert container.first_name == "John"
|
||||
assert container.last_name is None
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user