Example #1
0
def resolve_playlists(obj: Any, info: GraphQLResolveInfo, **kwargs) -> dict:
    kwargs = convert_keys_case(kwargs)
    return {
        "results": playlist.search(info.context.db, **kwargs),
        "total": playlist.count(info.context.db,
                                **del_pagination_keys(kwargs)),
    }
Example #2
0
def resolve_update_artist(
    _,
    info: GraphQLResolveInfo,
    id: int,
    **changes,
) -> artist.T:
    art = artist.from_id(id, info.context.db)
    if not art:
        raise NotFound(f"Artist {id} does not exist.")

    return artist.update(art, info.context.db, **convert_keys_case(changes))
Example #3
0
def resolve_update_track(
    _,
    info: GraphQLResolveInfo,
    id: int,
    **changes,
) -> track.T:
    trk = track.from_id(id, info.context.db)
    if not trk:
        raise NotFound(f"Track {id} does not exist.")

    return track.update(trk, info.context.db, **convert_keys_case(changes))
Example #4
0
def resolve_update_playlist(
    _,
    info: GraphQLResolveInfo,
    id: int,
    **changes,
) -> playlist.T:
    ply = playlist.from_id(id, info.context.db)
    if not ply:
        raise NotFound(f"Playlist {id} does not exist.")

    return playlist.update(ply, info.context.db, **convert_keys_case(changes))
Example #5
0
def resolve_update_collection(
    _,
    info: GraphQLResolveInfo,
    id: int,
    **changes,
) -> collection.T:
    col = collection.from_id(id, info.context.db)
    if not col:
        raise NotFound(f"Collection {id} does not exist.")

    return collection.update(col, info.context.db,
                             **convert_keys_case(changes))
Example #6
0
def resolve_update_release(
    _,
    info: GraphQLResolveInfo,
    id: int,
    **changes,
) -> release.T:
    rls = release.from_id(id, info.context.db)
    if not rls:
        raise NotFound(f"Release {id} does not exist.")

    # Convert the "releaseDate" update from a string to a `date` object. If it is not in
    # the changes dict, do nothing.
    try:
        changes["releaseDate"] = date.fromisoformat(changes["releaseDate"])
    except ValueError:
        raise ParseError("Invalid release date.")
    except KeyError:
        pass

    return release.update(rls, info.context.db, **convert_keys_case(changes))
Example #7
0
def resolve_releases(_: Any, info: GraphQLResolveInfo, **kwargs) -> dict:
    kwargs = convert_keys_case(kwargs)
    return {
        "results": release.search(info.context.db, **kwargs),
        "total": release.count(info.context.db, **del_pagination_keys(kwargs)),
    }