Coverage for core/graphql/mixins.py: 75%

18 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-10 18:35 +0000

1from typing import TYPE_CHECKING, Annotated 

2 

3import strawberry 

4import strawberry_django 

5from django.contrib.contenttypes.models import ContentType 

6from strawberry.types import Info 

7 

8from core.models import ObjectChange 

9 

10if TYPE_CHECKING: 10 ↛ 11line 10 didn't jump to line 11 because the condition on line 10 was never true

11 from core.graphql.types import DataFileType, DataSourceType, ObjectChangeType 

12 

13__all__ = ( 

14 'ChangelogMixin', 

15 'SyncedDataMixin', 

16) 

17 

18 

19@strawberry.type 

20class ChangelogMixin: 

21 

22 @strawberry_django.field 

23 def changelog(self, info: Info) -> list[Annotated['ObjectChangeType', strawberry.lazy('.types')]]: # noqa: F821 

24 content_type = ContentType.objects.get_for_model(self) 

25 object_changes = ObjectChange.objects.filter( 

26 changed_object_type=content_type, 

27 changed_object_id=self.pk 

28 ) 

29 return object_changes.restrict(info.context.request.user, 'view') 

30 

31 

32@strawberry.type 

33class SyncedDataMixin: 

34 data_source: Annotated['DataSourceType', strawberry.lazy('core.graphql.types')] | None 

35 data_file: Annotated['DataFileType', strawberry.lazy('core.graphql.types')] | None