Coverage for src/lexigram/graphql/web/contributor.py: 92%

12 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-08-25 04:37 +0800

1"""GraphQL web contributor for controller and middleware discovery.""" 

2 

3from __future__ import annotations 

4 

5from typing import Any 

6 

7 

8class GraphQLWebContributor: 

9 """Web contributor that registers GraphQL HTTP controller. 

10 

11 This contributor exposes the GraphQL HTTP endpoint controller to the 

12 web provider via entry-point discovery. WebSocket subscriptions are 

13 handled separately by GraphQLIntegration. 

14 

15 Example: 

16 Registered via entry-point in pyproject.toml:: 

17 

18 [project.entry-points."lexigram.web.contributors"] 

19 graphql = "lexigram.graphql.web.contributor:GraphQLWebContributor" 

20 """ 

21 

22 @property 

23 def contributor_id(self) -> str: 

24 """Return unique contributor identifier. 

25 

26 Returns: 

27 The string "graphql" as the contributor identifier. 

28 """ 

29 return "graphql" 

30 

31 def get_controllers(self) -> list[type[Any]]: 

32 """Return GraphQL HTTP controller class. 

33 

34 Returns: 

35 List containing GraphQLController class. 

36 """ 

37 from lexigram.graphql.controllers.graphql import GraphQLController 

38 

39 return [GraphQLController] 

40 

41 def get_middleware(self) -> list[type[Any]]: 

42 """Return middleware classes contributed by GraphQL package. 

43 

44 Currently GraphQL does not contribute any middleware. 

45 

46 Returns: 

47 Empty list. 

48 """ 

49 return [] 

50 

51 async def mount_to_app(self, app: Any, container: object) -> None: 

52 """No-op mount hook for GraphQL contributor. 

53 

54 GraphQL exposes routes via controller rather than app mount. 

55 WebSocket subscriptions are handled separately by GraphQLIntegration. 

56 

57 Args: 

58 app: The ASGI application (unused). 

59 container: The DI container (unused). 

60 """