def query_transform(request, **kwargs):
    """
    Merges the existing query params with any new ones passed as kwargs.

    Note that we cannot simply use request.GET.update() as that merges lists rather
    than replacing the value entirely.
    """

    updated_query_params = request.GET.copy()

    for key, value in kwargs.items():
        updated_query_params[key] = value

    return updated_query_params.urlencode()