Skip to content

Commit

Permalink
Fix default values for input objects
Browse files Browse the repository at this point in the history
  • Loading branch information
BenoitToulet authored Nov 21, 2023
1 parent 615adb3 commit db2abf2
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions graphene_mongo/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def construct_self_referenced_fields(self_referenced, registry):
return fields


def create_graphene_generic_class(object_type, option_type):
def create_graphene_generic_class(object_type, option_type, field_type):
class MongoengineGenericObjectTypeOptions(option_type):

model = None
Expand Down Expand Up @@ -124,7 +124,7 @@ def __init_subclass_with_meta__(
model, registry, only_fields, exclude_fields, non_required_fields
)
mongoengine_fields = yank_fields_from_attrs(
converted_fields, _as=graphene.Field
converted_fields, _as=field_type
)
if use_connection is None and interfaces:
use_connection = any(
Expand Down Expand Up @@ -188,7 +188,7 @@ def __init_subclass_with_meta__(
)
if converted_fields:
mongoengine_fields = yank_fields_from_attrs(
converted_fields, _as=graphene.Field
converted_fields, _as=field_type
)
cls._meta.fields.update(mongoengine_fields)
registry.register(cls)
Expand All @@ -206,7 +206,7 @@ def rescan_fields(cls):
)

mongoengine_fields = yank_fields_from_attrs(
converted_fields, _as=graphene.Field
converted_fields, _as=field_type
)

# The initial scan should take precedence
Expand Down Expand Up @@ -247,9 +247,14 @@ def resolve_id(self, info):
return GrapheneMongoengineGenericType, MongoengineGenericObjectTypeOptions


MongoengineObjectType, MongoengineObjectTypeOptions = create_graphene_generic_class(ObjectType, ObjectTypeOptions)
MongoengineInterfaceType, MongoengineInterfaceTypeOptions = create_graphene_generic_class(Interface, InterfaceOptions)
MongoengineObjectType, MongoengineObjectTypeOptions = create_graphene_generic_class(ObjectType,
ObjectTypeOptions,
graphene.Field)
MongoengineInterfaceType, MongoengineInterfaceTypeOptions = create_graphene_generic_class( Interface,
InterfaceOptions,
graphene.Field)
MongoengineInputType, MongoengineInputTypeOptions = create_graphene_generic_class(InputObjectType,
InputObjectTypeOptions)
InputObjectTypeOptions,
graphene.InputField)

GrapheneMongoengineObjectTypes = (MongoengineObjectType, MongoengineInputType, MongoengineInterfaceType)

0 comments on commit db2abf2

Please sign in to comment.