|
| 1 | +import strawberry |
| 2 | +from strawberry.django.views import AsyncGraphQLView |
| 3 | + |
| 4 | +from user import mutations as user_mutations |
| 5 | +from user import queries as user_queries |
| 6 | + |
| 7 | +from .context import GraphQLContext |
| 8 | +from .dataloaders import GlobalDataLoader |
| 9 | +from .enums import AppEnumCollection, AppEnumCollectionData |
| 10 | +from .permissions import IsAuthenticated |
| 11 | + |
| 12 | + |
| 13 | +class CustomAsyncGraphQLView(AsyncGraphQLView): |
| 14 | + async def get_context(self, *args, **kwargs) -> GraphQLContext: |
| 15 | + return GraphQLContext( |
| 16 | + *args, |
| 17 | + **kwargs, |
| 18 | + dl=GlobalDataLoader(), |
| 19 | + ) |
| 20 | + |
| 21 | + |
| 22 | +@strawberry.type |
| 23 | +class PublicQuery( |
| 24 | + user_queries.PublicQuery, |
| 25 | +): |
| 26 | + id: strawberry.ID = strawberry.ID("public") |
| 27 | + |
| 28 | + |
| 29 | +@strawberry.type |
| 30 | +class PrivateQuery( |
| 31 | + user_queries.PrivateQuery, |
| 32 | +): |
| 33 | + id: strawberry.ID = strawberry.ID("private") |
| 34 | + |
| 35 | + |
| 36 | +@strawberry.type |
| 37 | +class PublicMutation( |
| 38 | + user_mutations.PublicMutation, |
| 39 | +): |
| 40 | + id: strawberry.ID = strawberry.ID("public") |
| 41 | + |
| 42 | + |
| 43 | +@strawberry.type |
| 44 | +class PrivateMutation: |
| 45 | + id: strawberry.ID = strawberry.ID("private") |
| 46 | + |
| 47 | + |
| 48 | +@strawberry.type |
| 49 | +class Query: |
| 50 | + public: PublicQuery = strawberry.field(resolver=lambda: PublicQuery()) |
| 51 | + private: PrivateQuery = strawberry.field(permission_classes=[IsAuthenticated], resolver=lambda: PrivateQuery()) |
| 52 | + enums: AppEnumCollection = strawberry.field( # type: ignore[reportGeneralTypeIssues] |
| 53 | + resolver=lambda: AppEnumCollectionData() |
| 54 | + ) |
| 55 | + |
| 56 | + |
| 57 | +@strawberry.type |
| 58 | +class Mutation: |
| 59 | + public: PublicMutation = strawberry.field(resolver=lambda: PublicMutation()) |
| 60 | + private: PrivateMutation = strawberry.field( |
| 61 | + resolver=lambda: PrivateMutation(), |
| 62 | + permission_classes=[IsAuthenticated], |
| 63 | + ) |
| 64 | + |
| 65 | + |
| 66 | +schema = strawberry.Schema( |
| 67 | + query=Query, |
| 68 | + mutation=Mutation, |
| 69 | +) |
0 commit comments