From ec4c8997187452a12e091d3e94c6851e7c235156 Mon Sep 17 00:00:00 2001 From: David Vogt Date: Fri, 1 Jul 2022 14:43:07 +0200 Subject: [PATCH] feat(core): allow input type override 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. --- caluma/caluma_core/mutation.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/caluma/caluma_core/mutation.py b/caluma/caluma_core/mutation.py index 85257a5da..acda63756 100644 --- a/caluma/caluma_core/mutation.py +++ b/caluma/caluma_core/mutation.py @@ -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:]