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))
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
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, }, )
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, }, )
def failToChangeTheNumber(self, _new_number): raise ResolverError("Cannot change the number")
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))
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}")
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))
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)
def resolver(event, *_, **__): if event % 2: raise ResolverError("I don't like odd numbers.") return event
def test_GraphQLResult_bool(): assert GraphQLResult(data={"foo": 42}) assert not GraphQLResult(errors=[ResolverError("foo")]) assert not GraphQLResult(data={"foo": None}, errors=[ResolverError("foo")])
def resolve_secret_backstory(*args, **kwargs): raise ResolverError("secretBackstory is secret.", extensions={"code": 42})
async def resolve_baz(*_): raise ResolverError("Baz Error")
def resolve_sync_error(*_: Any) -> None: raise ResolverError("FOO")