| 905 | |
| 906 | @dataclass |
| 907 | class Enum(Handler[GraphQLEnumType]): |
| 908 | predicate: ClassVar[Predicate] = staticmethod(is_enum_type) |
| 909 | |
| 910 | @joiner |
| 911 | def render_body(self, t: GraphQLEnumType) -> Iterable[str]: |
| 912 | if body := super().render_body(t): |
| 913 | yield body |
| 914 | |
| 915 | by_value = defaultdict(list) |
| 916 | for name, value in t.values.items(): |
| 917 | by_value[self._get_value(value)].append(name) |
| 918 | |
| 919 | for val, names in sorted(by_value.items()): |
| 920 | yield "" |
| 921 | |
| 922 | for name in names: |
| 923 | yield f"{name} = {val!r}" |
| 924 | |
| 925 | member = t.values[name] |
| 926 | desc = member.description |
| 927 | reason = rewrite_notice(member.deprecation_reason) |
| 928 | |
| 929 | doc_parts: list[str] = [] |
| 930 | if desc: |
| 931 | doc_parts.append(desc) |
| 932 | if reason is not None: |
| 933 | directive = ".. deprecated::" |
| 934 | if reason: |
| 935 | directive = f"{directive} {reason}" |
| 936 | doc_parts.append(directive) |
| 937 | |
| 938 | if doc_parts: |
| 939 | yield doc("\n\n".join(doc_parts)) |
| 940 | |
| 941 | def _get_value(self, value) -> str: |
| 942 | if value.ast_node and (directive := self.ctx.schema.get_directive("enumValue")): |
| 943 | args = graphql.get_directive_values(directive, value.ast_node) |
| 944 | if args: |
| 945 | return args["value"] |
| 946 | return value.value |
| 947 | |
| 948 | |
| 949 | class Field(Protocol): |