Beispiel #1
0
def resolve_create_message(
    _root: Any,
    board: MessageBoard,
    _info: Any,
    *,
    data: CreateMessageInput,
    room_id: uuid.UUID,
) -> Message:
    try:
        return board.create_message(room_id, **data)
    except ValueError as err:
        raise ResolverError(str(err))
Beispiel #2
0
async def create_messages_subscription(
        _root: Any, board: MessageBoard, _info: Any,
        room_id: uuid.UUID) -> NewMessageIterator:

    try:
        board.rooms[room_id]
    except KeyError:
        raise ResolverError("No room with id {}".format(room_id))

    iterator = NewMessageIterator(asyncio.get_event_loop(), room_id)
    board.add_callback(iterator.on_message)
    return iterator
Beispiel #3
0
 async def wrapper(*args, **kwargs):
     try:
         return await func(*args, **kwargs)
     except aiohttp.client_exceptions.ClientResponseError as err:
         raise ResolverError(
             "Cannot reach SWAPI",
             extensions={
                 "msg": str(err),
                 "code": err.status,
                 "url": err.request.url,
             },
         )
Beispiel #4
0
 def wrapper(*args, **kwargs):
     try:
         return func(*args, **kwargs)
     except requests.exceptions.HTTPError as err:
         raise ResolverError(
             "Cannot reach SWAPI",
             extensions={
                 "msg": str(err),
                 "code": err.response.status_code,
                 "url": err.request.url,
             },
         )
Beispiel #5
0
 def failToChangeTheNumber(self, _new_number):
     raise ResolverError("Cannot change the number")
Beispiel #6
0
def resolve_room(_root: Any, board: MessageBoard, _info: Any, *,
                 id: uuid.UUID) -> Room:
    try:
        return board.rooms[id]
    except KeyError:
        raise ResolverError("No room with id {}".format(id))
Beispiel #7
0
def resolve_message(_root: Any, board: MessageBoard, _info: Any, *,
                    id: uuid.UUID) -> Message:
    try:
        return board.messages[id]
    except KeyError:
        raise ResolverError(f"No message with id {id}")
Beispiel #8
0
def resolve_create_room(_root: Any, board: MessageBoard, _info: Any, *,
                        data: CreateRoomInput) -> Room:
    try:
        return board.create_room(data["name"])
    except ValueError as err:
        raise ResolverError(str(err))
Beispiel #9
0
 def block_deep_fields(next_, root, ctx, info, **args):
     if len(info.path) > 3:
         raise ResolverError("Query too deep.")
     return next_(root, ctx, info, **args)
Beispiel #10
0
 def resolver(event, *_, **__):
     if event % 2:
         raise ResolverError("I don't like odd numbers.")
     return event
Beispiel #11
0
def test_GraphQLResult_bool():
    assert GraphQLResult(data={"foo": 42})
    assert not GraphQLResult(errors=[ResolverError("foo")])
    assert not GraphQLResult(data={"foo": None}, errors=[ResolverError("foo")])
Beispiel #12
0
def resolve_secret_backstory(*args, **kwargs):
    raise ResolverError("secretBackstory is secret.", extensions={"code": 42})
Beispiel #13
0
 async def resolve_baz(*_):
     raise ResolverError("Baz Error")
Beispiel #14
0
def resolve_sync_error(*_: Any) -> None:
    raise ResolverError("FOO")