Coverage for src/lexigram/graphql/subscriptions/protocol.py: 100%

23 statements  

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

1"""GraphQL subscription protocol definitions. 

2 

3Defines message types and constants for the graphql-transport-ws protocol. 

4""" 

5 

6from __future__ import annotations 

7 

8from enum import StrEnum 

9 

10 

11class GQLWSMessageType(StrEnum): 

12 """GraphQL-WS message types (graphql-transport-ws protocol).""" 

13 

14 # Connection 

15 CONNECTION_INIT = "connection_init" 

16 CONNECTION_ACK = "connection_ack" 

17 CONNECTION_ERROR = "connection_error" 

18 CONNECTION_KEEP_ALIVE = "ka" 

19 

20 # Subscription 

21 SUBSCRIBE = "subscribe" 

22 NEXT = "next" 

23 ERROR = "error" 

24 COMPLETE = "complete" 

25 

26 # Ping/Pong 

27 PING = "ping" 

28 PONG = "pong" 

29 

30 

31# Protocol constants 

32PROTOCOL_NAME_LEGACY = "graphql-ws" 

33PROTOCOL_NAME_TRANSPORT_WS = "graphql-transport-ws" 

34 

35DEFAULT_KEEPALIVE_INTERVAL = 30.0 # seconds 

36DEFAULT_CONNECTION_TIMEOUT = 10.0 # seconds 

37 

38# Error codes 

39ERROR_CODE_INTERNAL = "INTERNAL_ERROR" 

40ERROR_CODE_AUTH_NOT_SUPPORTED = "AUTH_NOT_SUPPORTED" 

41ERROR_CODE_AUTH_INVALID = "AUTH_INVALID" 

42ERROR_CODE_BAD_REQUEST = "BAD_REQUEST" 

43ERROR_CODE_OPERATION_RESULT = "OPERATION_RESULT_ERROR" 

44 

45 

46__all__ = [ 

47 "DEFAULT_CONNECTION_TIMEOUT", 

48 "DEFAULT_KEEPALIVE_INTERVAL", 

49 "ERROR_CODE_AUTH_INVALID", 

50 "ERROR_CODE_AUTH_NOT_SUPPORTED", 

51 "ERROR_CODE_BAD_REQUEST", 

52 "ERROR_CODE_INTERNAL", 

53 "ERROR_CODE_OPERATION_RESULT", 

54 "PROTOCOL_NAME_LEGACY", 

55 "PROTOCOL_NAME_TRANSPORT_WS", 

56 "GQLWSMessageType", 

57]