Coverage for src/lexigram/graphql/__init__.py: 89%
18 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"""Lexigram GraphQL - GraphQL support for Lexigram Framework.
3This package provides GraphQL capabilities for Lexigram Framework applications,
4including schema building, execution, subscriptions, and monitoring.
5"""
7from __future__ import annotations
9import importlib.metadata
11__path__ = __import__("pkgutil").extend_path(__path__, __name__)
13from typing import TYPE_CHECKING, Any
15from lexigram.graphql.constants import __version__ as __version__
17if TYPE_CHECKING:
18 # Types and configuration
19 # Provider
20 from lexigram.graphql.config import (
21 CacheConfig,
22 DataLoaderConfig,
23 DepthLimitConfig,
24 ErrorConfig,
25 GraphQLConfig,
26 IntrospectionConfig,
27 MetricsConfig,
28 PlaygroundConfig,
29 SubscriptionConfig,
30 TracingConfig,
31 )
33 # Core GraphQL components
34 from lexigram.graphql.core.context import (
35 ContextFactory,
36 GraphQLContext,
37 GraphQLRequest,
38 GraphQLResponse,
39 )
40 from lexigram.graphql.core.execution import (
41 ExecutionContextProtocol,
42 GraphQLExecutorProtocol,
43 execute_query,
44 )
45 from lexigram.graphql.core.introspection import (
46 IntrospectionHandler,
47 get_introspection_query,
48 )
49 from lexigram.graphql.core.validation import (
50 SchemaValidator,
51 ValidationResult,
52 validate_query,
53 )
54 from lexigram.graphql.dataloader.cache import (
55 InMemoryCache,
56 LoaderCache,
57 NoOpCache,
58 )
60 # DataLoaderProtocol support
61 from lexigram.graphql.dataloader.loader import (
62 DataLoaderProtocol,
63 create_loader,
64 )
66 # Package-level decorators
67 from lexigram.graphql.decorators import log_resolver, retry_resolver
68 from lexigram.graphql.di.provider import GraphQLProvider
69 from lexigram.graphql.events import (
70 AfterExecuteEvent,
71 BeforeExecuteEvent,
72 OnErrorEvent,
73 SchemaBuiltEvent,
74 SubscriptionStartedEvent,
75 )
77 # Errors
78 from lexigram.graphql.exceptions import (
79 AuthenticationError,
80 AuthorizationError,
81 ForbiddenError,
82 GraphQLError,
83 InputGraphQLError,
84 NotFoundError,
85 ParseError,
86 QueryTooComplexError,
87 QueryTooDeepError,
88 RateLimitError,
89 ResolverError,
90 SubscriptionError,
91 )
92 from lexigram.graphql.module import GraphQLModule
94 # Monitoring
95 from lexigram.graphql.monitoring.metrics import (
96 GraphQLMetrics,
97 MetricsCollectorProtocol,
98 MetricsExtension,
99 QueryStats,
100 get_metrics_collector,
101 )
102 from lexigram.graphql.monitoring.tracing import (
103 ExecutionTrace,
104 TraceSpan,
105 TracingExtension,
106 trace_resolver,
107 )
108 from lexigram.graphql.schema.builder import (
109 SchemaBuilderProtocol,
110 create_schema,
111 )
113 # Schema decorators and utilities
114 from lexigram.graphql.schema.decorators import (
115 field,
116 get_context,
117 mutation,
118 query,
119 resolver,
120 subscription,
121 )
122 from lexigram.graphql.schema.types import (
123 Connection,
124 CursorPaginationInput,
125 DeleteResult,
126 EnumType,
127 InputType,
128 InterfaceType,
129 MutationResult,
130 ObjectType,
131 PagedResult,
132 PaginationInput,
133 ScalarType,
134 SortInput,
135 create_connection_type,
136 union_type,
137 )
138 from lexigram.graphql.security.alias import (
139 AliasLimitExtension,
140 AliasLimitValidator,
141 )
143 # Security
144 from lexigram.graphql.security.depth import (
145 DepthLimitExtension,
146 DepthLimitValidator,
147 create_depth_limit,
148 )
149 from lexigram.graphql.security.extensions import RateLimitExtension
150 from lexigram.graphql.security.permissions import (
151 AbstractPermission,
152 AllowAny,
153 DenyAll,
154 IsAdmin,
155 IsAuthenticated,
156 IsOwner,
157 IsOwnerOrAdmin,
158 allow_any,
159 deny_all,
160 is_admin,
161 is_authenticated,
162 is_owner,
163 is_owner_or_admin,
164 )
165 from lexigram.graphql.security.rate_limit import (
166 RateLimitConfig,
167 RateLimiter,
168 UnifiedRateLimiter,
169 )
170 from lexigram.graphql.types import (
171 CacheControl,
172 CacheScope,
173 DataLoaderStats,
174 DirectiveLocation,
175 FieldInfo,
176 GraphQLErrorCode,
177 GraphQLErrorData,
178 GraphQLErrorExtensions,
179 GraphQLLocation,
180 OperationInfo,
181 OperationType,
182 QueryMetrics,
183 ResolverInfo,
184 SubscriptionInfo,
185 SubscriptionProtocol,
186 )
188_LAZY_IMPORTS = {
189 # Module
190 "GraphQLModule": "lexigram.graphql.module",
191 # Types
192 "OperationType": "lexigram.graphql.types",
193 "GraphQLErrorCode": "lexigram.graphql.types",
194 "DirectiveLocation": "lexigram.graphql.types",
195 "CacheScope": "lexigram.graphql.types",
196 "SubscriptionProtocol": "lexigram.graphql.types",
197 "GraphQLLocation": "lexigram.graphql.types",
198 "GraphQLErrorExtensions": "lexigram.graphql.types",
199 "GraphQLErrorData": "lexigram.graphql.types",
200 "FieldInfo": "lexigram.graphql.types",
201 "OperationInfo": "lexigram.graphql.types",
202 "ResolverInfo": "lexigram.graphql.types",
203 "CacheControl": "lexigram.graphql.types",
204 "QueryMetrics": "lexigram.graphql.types",
205 "SubscriptionInfo": "lexigram.graphql.types",
206 "DataLoaderStats": "lexigram.graphql.types",
207 # Config
208 "GraphQLConfig": "lexigram.graphql.config",
209 "CacheConfig": "lexigram.graphql.config",
210 "DepthLimitConfig": "lexigram.graphql.config",
211 "IntrospectionConfig": "lexigram.graphql.config",
212 "PlaygroundConfig": "lexigram.graphql.config",
213 "SubscriptionConfig": "lexigram.graphql.config",
214 "DataLoaderConfig": "lexigram.graphql.config",
215 "TracingConfig": "lexigram.graphql.config",
216 "MetricsConfig": "lexigram.graphql.config",
217 "ErrorConfig": "lexigram.graphql.config",
218 # Core
219 "GraphQLContext": "lexigram.graphql.core.context",
220 "GraphQLRequest": "lexigram.graphql.core.context",
221 "GraphQLResponse": "lexigram.graphql.core.context",
222 "ContextFactory": "lexigram.graphql.core.context",
223 "GraphQLExecutorProtocol": "lexigram.graphql.core.execution",
224 "ExecutionContextProtocol": "lexigram.graphql.core.execution",
225 "execute_query": "lexigram.graphql.core.execution",
226 # Events
227 "BeforeExecuteEvent": "lexigram.graphql.events",
228 "AfterExecuteEvent": "lexigram.graphql.events",
229 "OnErrorEvent": "lexigram.graphql.events",
230 "SchemaBuiltEvent": "lexigram.graphql.events",
231 "SubscriptionStartedEvent": "lexigram.graphql.events",
232 "SchemaValidator": "lexigram.graphql.core.validation",
233 "ValidationResult": "lexigram.graphql.core.validation",
234 "validate_query": "lexigram.graphql.core.validation",
235 "IntrospectionHandler": "lexigram.graphql.core.introspection",
236 "get_introspection_query": "lexigram.graphql.core.introspection",
237 # Decorators
238 "log_resolver": "lexigram.graphql.decorators",
239 "retry_resolver": "lexigram.graphql.decorators",
240 # Schema
241 "query": "lexigram.graphql.schema.decorators",
242 "mutation": "lexigram.graphql.schema.decorators",
243 "subscription": "lexigram.graphql.schema.decorators",
244 "resolver": "lexigram.graphql.schema.decorators",
245 "field": "lexigram.graphql.schema.decorators",
246 "get_context": "lexigram.graphql.schema.decorators",
247 "SchemaBuilderProtocol": "lexigram.graphql.schema.builder",
248 "create_schema": "lexigram.graphql.schema.builder",
249 # Protocol re-exports (contracts + type aliases)
250 "GraphQLResolver": "lexigram.graphql.protocols",
251 "GraphQLSchema": "lexigram.graphql.protocols",
252 "ObjectType": "lexigram.graphql.schema.types",
253 "InputType": "lexigram.graphql.schema.types",
254 "InterfaceType": "lexigram.graphql.schema.types",
255 "union_type": "lexigram.graphql.schema.types",
256 "EnumType": "lexigram.graphql.schema.types",
257 "ScalarType": "lexigram.graphql.schema.types",
258 "Connection": "lexigram.graphql.schema.types",
259 "PagedResult": "lexigram.graphql.schema.types",
260 "PaginationInput": "lexigram.graphql.schema.types",
261 "CursorPaginationInput": "lexigram.graphql.schema.types",
262 "SortInput": "lexigram.graphql.schema.types",
263 "MutationResult": "lexigram.graphql.schema.types",
264 "DeleteResult": "lexigram.graphql.schema.types",
265 "create_connection_type": "lexigram.graphql.schema.types",
266 # DataLoaderProtocol
267 "DataLoaderProtocol": "lexigram.graphql.dataloader.loader",
268 "create_loader": "lexigram.graphql.dataloader.loader",
269 "LoaderCache": "lexigram.graphql.dataloader.cache",
270 "InMemoryCache": "lexigram.graphql.dataloader.cache",
271 "NoOpCache": "lexigram.graphql.dataloader.cache",
272 # Security
273 "DepthLimitExtension": "lexigram.graphql.security.depth",
274 "DepthLimitValidator": "lexigram.graphql.security.depth",
275 "create_depth_limit": "lexigram.graphql.security.depth",
276 "AliasLimitValidator": "lexigram.graphql.security.alias",
277 "AbstractPermission": "lexigram.graphql.security.permissions",
278 "IsAuthenticated": "lexigram.graphql.security.permissions",
279 "IsAdmin": "lexigram.graphql.security.permissions",
280 "IsOwner": "lexigram.graphql.security.permissions",
281 "IsOwnerOrAdmin": "lexigram.graphql.security.permissions",
282 "AllowAny": "lexigram.graphql.security.permissions",
283 "DenyAll": "lexigram.graphql.security.permissions",
284 "is_authenticated": "lexigram.graphql.security.permissions",
285 "is_admin": "lexigram.graphql.security.permissions",
286 "is_owner": "lexigram.graphql.security.permissions",
287 "is_owner_or_admin": "lexigram.graphql.security.permissions",
288 "allow_any": "lexigram.graphql.security.permissions",
289 "deny_all": "lexigram.graphql.security.permissions",
290 "RateLimiter": "lexigram.graphql.security.rate_limit",
291 "RateLimitConfig": "lexigram.graphql.security.rate_limit",
292 "UnifiedRateLimiter": "lexigram.graphql.security.rate_limit",
293 "RateLimitExtension": "lexigram.graphql.security.extensions",
294 # Monitoring
295 "GraphQLMetrics": "lexigram.graphql.monitoring.metrics",
296 "MetricsCollectorProtocol": "lexigram.graphql.monitoring.metrics",
297 "MetricsExtension": "lexigram.graphql.monitoring.metrics",
298 "QueryStats": "lexigram.graphql.monitoring.metrics",
299 "get_metrics_collector": "lexigram.graphql.monitoring.metrics",
300 "TracingExtension": "lexigram.graphql.monitoring.tracing",
301 "trace_resolver": "lexigram.graphql.monitoring.tracing",
302 "ExecutionTrace": "lexigram.graphql.monitoring.tracing",
303 "TraceSpan": "lexigram.graphql.monitoring.tracing",
304 # Errors
305 "GraphQLError": "lexigram.graphql.exceptions",
306 "InputGraphQLError": "lexigram.graphql.exceptions",
307 "ResolverError": "lexigram.graphql.exceptions",
308 "ParseError": "lexigram.graphql.exceptions",
309 "AuthenticationError": "lexigram.graphql.exceptions",
310 "AuthorizationError": "lexigram.graphql.exceptions",
311 "ForbiddenError": "lexigram.graphql.exceptions",
312 "NotFoundError": "lexigram.graphql.exceptions",
313 "RateLimitError": "lexigram.graphql.exceptions",
314 "QueryTooComplexError": "lexigram.graphql.exceptions",
315 "QueryTooDeepError": "lexigram.graphql.exceptions",
316 "SubscriptionError": "lexigram.graphql.exceptions",
317 "GraphQLConnectionError": "lexigram.graphql.exceptions",
318 # Provider
319 "GraphQLProvider": "lexigram.graphql.di.provider",
320 # Resolvers
321 "ResolverAdapter": "lexigram.graphql.resolvers",
322 # "resolver" is intentionally omitted here to avoid duplicate keys;
323 # it can be imported directly from `lexigram.graphql.resolvers` if needed.
324 # Directives
325 "DirectiveRegistry": "lexigram.graphql.directives",
326 "DeprecationDirectiveHandler": "lexigram.graphql.directives",
327 # Pagination
328 "Edge": "lexigram.graphql.pagination",
329 "PageInfo": "lexigram.graphql.pagination",
330 "CursorConnection": "lexigram.graphql.pagination",
331 "encode_cursor": "lexigram.graphql.pagination",
332 "decode_cursor": "lexigram.graphql.pagination",
333 "encode_cursor_from_id": "lexigram.graphql.pagination",
334 "decode_cursor_to_id": "lexigram.graphql.pagination",
335 # Web Integration
336 "GraphQLController": "lexigram.graphql.controllers",
337 "GraphQLSubscriptionController": "lexigram.graphql.controllers",
338 # APQ
339 "PersistedQueryStore": "lexigram.graphql.core.persisted_queries",
340 "InMemoryPersistedQueryStore": "lexigram.graphql.core.persisted_queries",
341 "RedisPersistedQueryStore": "lexigram.graphql.core.persisted_queries",
342 "CacheBackendPersistedQueryStore": "lexigram.graphql.core.persisted_queries",
343 "APQResult": "lexigram.graphql.core.persisted_queries",
344 "APQHandler": "lexigram.graphql.core.persisted_queries",
345 "compute_query_hash": "lexigram.graphql.core.persisted_queries",
346 # Hooks
347 "GraphQLRequestReceivedHook": "lexigram.graphql.hooks",
348 "GraphQLResponsePreparedHook": "lexigram.graphql.hooks",
349 "GraphQLSchemaBuiltHook": "lexigram.graphql.hooks",
350}
353def __getattr__(name: str) -> Any:
354 if name in _LAZY_IMPORTS:
355 import importlib
357 module_path = _LAZY_IMPORTS[name]
358 module = importlib.import_module(module_path)
359 value = getattr(module, name)
360 globals()[name] = value
361 return value
362 raise AttributeError(f"module {__name__} has no attribute {name}")
365def __dir__() -> list[str]:
366 return sorted(set(__all__) | set(_LAZY_IMPORTS.keys()))
369__all__ = list(_LAZY_IMPORTS.keys())