Coverage for src/lexigram/graphql/directives/builtin.py: 100%
10 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
1"""Built-in directive handlers for the GraphQL module.
3These concrete classes were previously defined in the package
4``__init__`` but are now moved here to keep the root lightweight.
5"""
7from __future__ import annotations
9from typing import Any
12class DeprecationDirectiveHandler:
13 """Marks targets as deprecated using the ``@deprecated`` directive.
15 Adds a ``__deprecated__`` attribute with the deprecation reason to any
16 target object that supports attribute assignment.
17 """
19 def apply_directive(
20 self,
21 directive_name: str,
22 args: dict[str, Any],
23 target: Any,
24 ) -> Any:
25 """Apply ``@deprecated`` by setting ``__deprecated__`` on *target*.
27 Args:
28 directive_name: Expected to be ``"deprecated"``.
29 args: May contain ``"reason"`` (str).
30 target: Any object.
32 Returns:
33 The *target* with ``__deprecated__`` set.
34 """
35 reason = args.get("reason", "No longer supported.")
36 try:
37 target.__deprecated__ = reason
38 except AttributeError:
39 pass
40 return target