Skip to content

Commit 2bab94d

Browse files
committed
Added InputObjectType and InputObjectField
1 parent ea5207d commit 2bab94d

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

graphene/core/fields.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
GraphQLID,
1212
GraphQLArgument,
1313
GraphQLFloat,
14+
GraphQLInputObjectField,
1415
)
1516
from graphene.utils import to_camel_case
16-
from graphene.core.types import BaseObjectType
17+
from graphene.core.types import BaseObjectType, InputObjectType
1718
from graphene.core.scalars import GraphQLSkipField
1819

1920

@@ -145,7 +146,12 @@ def resolver(*args):
145146
return self.resolve(*args)
146147
else:
147148
resolver = self.resolve
148-
return GraphQLField(
149+
150+
field_type = GraphQLField
151+
if object_type and issubclass(object_type, InputObjectType):
152+
field_type = GraphQLInputObjectField
153+
154+
return field_type(
149155
internal_type,
150156
description=description,
151157
args=args,

graphene/core/types.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from graphql.core.type import (
77
GraphQLObjectType,
8+
GraphQLInputObjectType,
89
GraphQLInterfaceType,
910
GraphQLArgument
1011
)
@@ -170,9 +171,8 @@ def resolve_type(cls, schema, instance, *_):
170171
@memoize
171172
@register_internal_type
172173
def internal_type(cls, schema):
173-
fields_list = cls._meta.fields
174174
fields = lambda: OrderedDict([(f.name, f.internal_field(schema))
175-
for f in fields_list])
175+
for f in cls._meta.fields])
176176
if cls._meta.is_interface:
177177
return GraphQLInterfaceType(
178178
cls._meta.type_name,
@@ -200,3 +200,17 @@ class ObjectType(six.with_metaclass(ObjectTypeMeta, BaseObjectType)):
200200

201201
class Mutation(six.with_metaclass(ObjectTypeMeta, BaseObjectType)):
202202
pass
203+
204+
205+
class InputObjectType(ObjectType):
206+
@classmethod
207+
@memoize
208+
@register_internal_type
209+
def internal_type(cls, schema):
210+
fields = lambda: OrderedDict([(f.name, f.internal_field(schema))
211+
for f in cls._meta.fields])
212+
return GraphQLInputObjectType(
213+
cls._meta.type_name,
214+
description=cls._meta.description,
215+
fields=fields,
216+
)

0 commit comments

Comments
 (0)