reactpy-django icon indicating copy to clipboard operation
reactpy-django copied to clipboard

Deprecate `QueryOptions` and `MutationOptions`

Open Archmonger opened this issue 1 year ago • 1 comments
trafficstars

Ref: https://github.com/reactive-python/reactpy-django/issues/113

Current Situation

use_query and use_mutation currently require QueryOptions and MutationOptions objects to configure their behavior. Adding an extra import just for configuration is pretty annoying.

Proposed Actions

Deprecate QueryOptions and MutationOptions in favor of a different interface.

def use_query(
    query: Callable[FuncParams, Awaitable[Inferred]] | Callable[FuncParams, Inferred],
    args: Sequence | None = None,
    kwargs: MutableMapping | None = None,
    /,
    postprocessor: AsyncPostprocessor | SyncPostprocessor | None = None,
    postprocessor_kwargs: MutableMapping | None = None,
    thread_sensitive: bool = True,
):
    ...

This interface does pose a new challenge. Type hints for args and kwargs will no longer receive auto-complete support due to Python type hint limitations. However, this seems to be worth the trade off. Especially since it's likely this type hint limitation will eventually get resolved.

An alternative is to use unpacking (for example use_query(... , *args, **kwargs)), however, this would result in our configuration options, such as thread_sensitive and postprocessor, stepping into the bounds of **kwargs. As a result, that is unfortunately not a good solution since every config option we add has the potential to break a user application.

Archmonger avatar Jan 05 '24 12:01 Archmonger

@rmorshea When you have time can you provide your opinion on this suggested API change?

Will be folding it in to the next major release of ReactPy Django.

Archmonger avatar Jan 05 '24 22:01 Archmonger