Coverage for src/lexigram/graphql/scalars/misc.py: 48%
61 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-25 04:37 +0800
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-25 04:37 +0800
1from __future__ import annotations
3from typing import Any
4import uuid
7class UUID:
8 """Custom scalar for UUID values."""
10 @staticmethod
11 def serialize(uid: uuid.UUID | None) -> str | None:
12 if uid is None:
13 return None
14 if isinstance(uid, uuid.UUID):
15 return str(uid)
16 raise ValueError(f"Cannot serialize {type(uid)} as UUID")
18 @staticmethod
19 def parse_value(value: str | None) -> uuid.UUID | None:
20 if value is None:
21 return None
22 return uuid.UUID(value)
25class Email:
26 """Custom scalar for email values."""
28 @staticmethod
29 def serialize(email: str | None) -> str | None:
30 if email is None:
31 return None
32 if isinstance(email, str) and "@" in email:
33 return email.lower()
34 raise ValueError(f"Cannot serialize {type(email)} as Email")
36 @staticmethod
37 def parse_value(value: str | None) -> str | None:
38 if value is None:
39 return None
40 return value.lower()
43class URL:
44 """Custom scalar for URL values."""
46 @staticmethod
47 def serialize(url: str | None) -> str | None:
48 if url is None:
49 return None
50 if isinstance(url, str):
51 return url
52 raise ValueError(f"Cannot serialize {type(url)} as URL")
54 @staticmethod
55 def parse_value(value: str | None) -> str | None:
56 if value is None:
57 return None
58 return value
61class BigInt:
62 """Custom scalar for big integer values."""
64 @staticmethod
65 def serialize(value: int | None) -> str | None:
66 if value is None:
67 return None
68 return str(value)
70 @staticmethod
71 def parse_value(value: str | None) -> int | None:
72 if value is None:
73 return None
74 return int(value)
77class Void:
78 """Custom scalar for void/null values."""
80 @staticmethod
81 def serialize(_value: Any) -> None:
82 return
84 @staticmethod
85 def parse_value(_value: Any) -> None:
86 return
89__all__ = [
90 "URL",
91 "UUID",
92 "BigInt",
93 "Email",
94 "Void",
95]