Coverage for src / lexigram / contracts / graphql / types.py: 100%

10 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-08-19 05:41 +0800

1"""GraphQL type definitions. 

2 

3Shared types for GraphQL execution context and principal resolution. 

4""" 

5 

6from __future__ import annotations 

7 

8from dataclasses import dataclass 

9from typing import Any 

10 

11 

12@dataclass(frozen=True) 

13class GraphQLPrincipal: 

14 """Unified principal representation for GraphQL context. 

15 

16 Provides a common interface for accessing user identity across 

17 the framework, decoupling GraphQL resolvers from authentication 

18 implementation details. 

19 

20 All fields default to ``None`` to support unauthenticated requests 

21 and partial principal information from different authentication 

22 sources (JWT, OAuth2, API keys, etc.). 

23 

24 Attributes: 

25 internal_user_id: Framework-internal user identifier (e.g., database PK). 

26 subject_id: External subject identifier (e.g., JWT ``sub`` claim, OAuth2 user ID). 

27 email: User email address, if available. 

28 raw_user: Original authentication payload (e.g., decoded JWT, OAuth2 user object). 

29 """ 

30 

31 internal_user_id: str | None = None 

32 subject_id: str | None = None 

33 email: str | None = None 

34 raw_user: Any | None = None 

35 

36 

37__all__ = [ 

38 "GraphQLPrincipal", 

39]