Exemple #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))
Exemple #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
Exemple #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,
             },
         )
Exemple #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,
             },
         )
Exemple #5
0
 def failToChangeTheNumber(self, _new_number):
     raise ResolverError("Cannot change the number")
Exemple #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))
Exemple #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}")
Exemple #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))
Exemple #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)
Exemple #10
0
 def resolver(event, *_, **__):
     if event % 2:
         raise ResolverError("I don't like odd numbers.")
     return event
Exemple #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")])
Exemple #12
0
def resolve_secret_backstory(*args, **kwargs):
    raise ResolverError("secretBackstory is secret.", extensions={"code": 42})
Exemple #13
0
 async def resolve_baz(*_):
     raise ResolverError("Baz Error")
Exemple #14
0
def resolve_sync_error(*_: Any) -> None:
    raise ResolverError("FOO")