Пример #1
0
    def arguments(self) -> List[ArgumentDefinition]:
        # TODO: Move to StrawberryArgument? StrawberryResolver ClassVar?
        SPECIAL_ARGS = {"root", "self", "info"}

        annotations = self.wrapped_func.__annotations__
        parameters = inspect.signature(self.wrapped_func).parameters
        function_arguments = set(parameters) - SPECIAL_ARGS

        annotations = {
            name: annotation
            for name, annotation in annotations.items()
            if name not in (SPECIAL_ARGS | {"return"})
        }

        annotated_arguments = set(annotations)
        arguments_missing_annotations = function_arguments - annotated_arguments

        if any(arguments_missing_annotations):
            raise MissingArgumentsAnnotationsError(
                field_name=self.wrapped_func.__name__,
                arguments=arguments_missing_annotations,
            )

        return get_arguments_from_annotations(annotations,
                                              parameters,
                                              origin=self.wrapped_func)
Пример #2
0
    def arguments(self) -> List[StrawberryArgument]:
        annotations = self.resolver.__annotations__
        annotations = dict(islice(annotations.items(), 1, None))
        annotations.pop("return", None)

        parameters = inspect.signature(self.resolver).parameters

        return get_arguments_from_annotations(annotations,
                                              parameters,
                                              origin=self.resolver)
Пример #3
0
def get_arguments_for_directive(
    resolver: typing.Callable, ) -> typing.List[ArgumentDefinition]:
    # TODO: move this into directive declaration
    annotations = resolver.__annotations__
    annotations = dict(islice(annotations.items(), 1, None))
    annotations.pop("return", None)

    parameters = inspect.signature(resolver).parameters

    return get_arguments_from_annotations(annotations,
                                          parameters,
                                          origin=resolver)