Skip to content

Commit

Permalink
feat(core): allow input type override
Browse files Browse the repository at this point in the history
The original Graphene API allows adding an `Input` (or, without Relay, a
`Arguments`) class to be added on mutation classes. Caluma derives it's
inputs solely from the attached serializer.

This fails if the required data type is more complex than what can
be represented on the serializer, whose most complex type is a list
of strings.

However, we need a list of well-defined objects, so we check on the
mutation class to see if a more specific field type is declared, and
use that one in the schema.
  • Loading branch information
winged committed Jul 4, 2022
1 parent 020785d commit ec4c899
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions caluma/caluma_core/mutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,17 @@ def __init_subclass_with_meta__(

input_fields = fields_for_serializer(serializer, fields, exclude, is_input=True)

if hasattr(cls, "Input"):
# Allow input type override in case the serializer fields cannot
# define exactly what we need
input_obj = cls.Input()
explicit_inputs = [
name for name in dir(input_obj) if not name.startswith("_")
]
for name in explicit_inputs:
input_type = getattr(input_obj, name)
input_fields[name] = input_type

if return_field_name is None:
model_name = model_class.__name__
return_field_name = model_name[:1].lower() + model_name[1:]
Expand Down

0 comments on commit ec4c899

Please sign in to comment.