Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 54 additions & 13 deletions apps/contributor/graphql/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import strawberry
import strawberry_django
from django.db.models import QuerySet
from django.shortcuts import aget_object_or_404
from strawberry_django.pagination import OffsetPaginated
from strawberry_django.permissions import IsAuthenticated

from apps.contributor.models import ContributorUser
from apps.contributor.models import ContributorTeam, ContributorUser, ContributorUserGroup, ContributorUserGroupMembership

from .filters import (
ContributorTeamFilter,
Expand All @@ -31,26 +33,65 @@ class Query:

contributor_user: ContributorUserType = strawberry_django.field()

contributor_user_groups: OffsetPaginated[ContributorUserGroupType] = strawberry_django.offset_paginated(
contributor_user_group: ContributorUserGroupType = strawberry_django.field()

# Team
contributor_team: ContributorTeamType = strawberry_django.field()

@strawberry.field
async def contributor_user_by_user_id(self, user_id: strawberry.ID) -> ContributorUserType:
obj = await aget_object_or_404(ContributorUser, user_id=user_id)
return typing.cast("ContributorUserType", obj)

# --- Paginated
# --- ContributorUserGroup
@strawberry_django.offset_paginated(
OffsetPaginated[ContributorUserGroupType],
order=ContributorUserGroupOrder,
filters=ContributorUserGroupFilter,
)
# TODO: We need attribute description `include_all` visible in graphiql
def contributor_user_groups(
self,
include_all: bool = False,
) -> QuerySet[ContributorUserGroup]:
# XXX: Filter out user group without name. They aren't sync yet.
# TODO: This is from old system, make sure name aren't empty and remove this filter
queryset = ContributorUserGroup.objects.exclude(name="").all()
if include_all:
return queryset
return queryset.exclude(is_archived=True).all()

contributor_user_group: ContributorUserGroupType = strawberry_django.field()

contributor_user_group_members: OffsetPaginated[ContributorUserGroupMembershipType] = strawberry_django.offset_paginated(
# --- Paginated
# --- ContributorUserGroupMembership
@strawberry_django.offset_paginated(
OffsetPaginated[ContributorUserGroupMembershipType],
order=ContributorUserGroupMembershipOrder,
filters=ContributorUserGroupMembershipFilter,
)
# TODO: We need attribute description `include_all` visible in graphiql
def contributor_user_group_members(
self,
include_all: bool = False,
) -> QuerySet[ContributorUserGroupMembership]:
queryset = ContributorUserGroupMembership.objects.all()
if include_all:
return queryset
return queryset.exclude(is_active=False).all()

# Team
contributor_team: ContributorTeamType = strawberry_django.field()
contributor_teams: OffsetPaginated[ContributorTeamType] = strawberry_django.offset_paginated(
# --- Paginated
# --- Team
@strawberry_django.offset_paginated(
OffsetPaginated[ContributorTeamType],
order=ContributorTeamOrder,
filters=ContributorTeamFilter,
extensions=[IsAuthenticated()],
)

@strawberry.field
async def contributor_user_by_user_id(self, user_id: strawberry.ID) -> ContributorUserType:
obj = await aget_object_or_404(ContributorUser, user_id=user_id)
return typing.cast("ContributorUserType", obj)
# TODO: We need attribute description `include_all` visible in graphiql
def contributor_teams(
self,
include_all: bool = False,
) -> QuerySet[ContributorTeam]:
if include_all:
return ContributorTeam.objects.all()
return ContributorTeam.objects.exclude(is_archived=True).all()
6 changes: 0 additions & 6 deletions apps/contributor/graphql/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,6 @@ def user_memberships(
) -> models.QuerySet[ContributorUserGroupMembership]:
return ContributorUserGroupMembership.objects.filter(user_group_id=contributor_user_group.pk).order_by("user_id")

@classmethod
def get_queryset(cls, queryset, info, **kwargs):
# XXX: Filter out user group without name. They aren't sync yet.
# TODO: This is from old system, make sure name aren't empty and remove this filter
return queryset.exclude(name="")


@strawberry_django.type(ContributorUserGroupMembership)
class ContributorUserGroupMembershipType:
Expand Down
42 changes: 34 additions & 8 deletions apps/project/graphql/queries.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import strawberry
import strawberry_django
from django.db.models import QuerySet
from strawberry_django.pagination import OffsetPaginated
from strawberry_django.permissions import IsAuthenticated

from apps.project.models import Organization, Project
from utils.geo.raster_tile_server.config import RasterConfig, RasterTileServerNameEnum, RasterTileServerNameEnumWithoutCustom
from utils.geo.vector_tile_server.config import VectorConfig, VectorTileServerNameEnum, VectorTileServerNameEnumWithoutCustom

Expand Down Expand Up @@ -57,13 +59,6 @@ class Query:
# Private --------------------
project: ProjectType = strawberry_django.field(extensions=[IsAuthenticated()])

# --- Paginated
projects: OffsetPaginated[ProjectType] = strawberry_django.offset_paginated(
order=ProjectOrder,
filters=ProjectFilter,
extensions=[IsAuthenticated()],
)

project_asset: ProjectAssetType = strawberry_django.field(extensions=[IsAuthenticated()])

# --- Paginated
Expand All @@ -76,8 +71,39 @@ class Query:
organization: OrganizationType = strawberry_django.field(extensions=[IsAuthenticated()])

# --- Paginated
organizations: OffsetPaginated[OrganizationType] = strawberry_django.offset_paginated(
@strawberry_django.offset_paginated(
OffsetPaginated[OrganizationType],
order=OrganizationOrder,
filters=OrganizationFilter,
extensions=[IsAuthenticated()],
)
# TODO: We need attribute description `include_all` visible in graphiql
def organizations(
self,
include_all: bool = False,
) -> QuerySet[Organization]:
if include_all:
return Organization.objects.all()
return Organization.objects.exclude(is_archived=True).all()

# --- Paginated
@strawberry_django.offset_paginated(
OffsetPaginated[ProjectType],
order=ProjectOrder,
filters=ProjectFilter,
extensions=[IsAuthenticated()],
)
# TODO: We need attribute description `include_all` visible in graphiql
def projects(
self,
include_all: bool = False,
) -> QuerySet[Project]:
if include_all:
return Project.objects.all()
return Project.objects.filter(
status__in=[
Project.Status.READY,
Project.Status.PUBLISHED,
Project.Status.PAUSED,
],
).all()
10 changes: 8 additions & 2 deletions apps/project/tests/filter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@
class TestProjectFiltersAndOrders(TestCase):
class Query:
PROJECTS_WITH_FILTERS = """
query Projects($pagination: OffsetPaginationInput, $filters: ProjectFilter, $order: ProjectOrder) {
projects(pagination: $pagination, filters: $filters, order: $order) {
query Projects(
$pagination: OffsetPaginationInput,
$filters: ProjectFilter,
$order: ProjectOrder,
$includeAll: Boolean
) {
projects(pagination: $pagination, filters: $filters, order: $order, includeAll: $includeAll) {
totalCount
pageInfo {
offset
Expand Down Expand Up @@ -104,6 +109,7 @@ def _query(
return self.query_check(
self.Query.PROJECTS_WITH_FILTERS,
variables={
"includeAll": True,
"pagination": {
"limit": 10,
"offset": 0,
Expand Down
5 changes: 3 additions & 2 deletions apps/project/tests/query_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class Query:
credits
}
}
query Projects($pagination: OffsetPaginationInput) {
projects(order: {id: ASC}, pagination: $pagination) {
query Projects($pagination: OffsetPaginationInput, $includeAll: Boolean = false) {
projects(order: {id: ASC}, pagination: $pagination, includeAll: $includeAll) {
totalCount
pageInfo {
offset
Expand Down Expand Up @@ -305,6 +305,7 @@ def _query():
"limit": 10,
"offset": 0,
},
"includeAll": True,
},
)

Expand Down
14 changes: 13 additions & 1 deletion apps/tutorial/graphql/queries.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import strawberry
import strawberry_django
from django.db.models import QuerySet
from strawberry_django.pagination import OffsetPaginated
from strawberry_django.permissions import IsAuthenticated

from apps.tutorial.models import Tutorial

from .filters import TutorialFilter
from .orders import TutorialOrder
from .types.types import TutorialType
Expand All @@ -14,8 +17,17 @@ class Query:
tutorial: TutorialType = strawberry_django.field(extensions=[IsAuthenticated()])

# --- Paginated
tutorials: OffsetPaginated[TutorialType] = strawberry_django.offset_paginated(
@strawberry_django.offset_paginated(
OffsetPaginated[TutorialType],
order=TutorialOrder,
filters=TutorialFilter,
extensions=[IsAuthenticated()],
)
# TODO: We need attribute description `include_all` visible in graphiql
def tutorials(
self,
include_all: bool = False,
) -> QuerySet[Tutorial]:
if include_all:
return Tutorial.objects.all()
return Tutorial.objects.filter(status=Tutorial.Status.PUBLISHED).all()
5 changes: 3 additions & 2 deletions apps/tutorial/tests/filter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
class TestTutorialFilterQuery(TestCase):
class Query:
TUTORIALS_WITH_FILTERS = """
query Tutorials($pagination: OffsetPaginationInput, $filters: TutorialFilter) {
tutorials(pagination: $pagination, filters: $filters) {
query Tutorials($pagination: OffsetPaginationInput, $filters: TutorialFilter, $includeAll: Boolean) {
tutorials(pagination: $pagination, filters: $filters, includeAll: $includeAll) {
totalCount
pageInfo {
offset
Expand Down Expand Up @@ -85,6 +85,7 @@ def _query(
return self.query_check(
self.Query.TUTORIALS_WITH_FILTERS,
variables={
"includeAll": True,
"pagination": {
"limit": 10,
"offset": 0,
Expand Down
12 changes: 6 additions & 6 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1524,21 +1524,21 @@ type Query {
users(filters: UserFilter, order: UserOrder, pagination: OffsetPaginationInput): UserTypeOffsetPaginated! @isAuthenticated
tileServers: RasterTileServersType! @isAuthenticated
project(id: ID!): ProjectType! @isAuthenticated
projects(pagination: OffsetPaginationInput, filters: ProjectFilter, order: ProjectOrder): ProjectTypeOffsetPaginated! @isAuthenticated
projectAsset(id: ID!): ProjectAssetType! @isAuthenticated
projectAssets(pagination: OffsetPaginationInput, filters: ProjectAssetFilter, order: ProjectAssetOrder): ProjectAssetTypeOffsetPaginated! @isAuthenticated
organization(id: ID!): OrganizationType! @isAuthenticated
organizations(pagination: OffsetPaginationInput, filters: OrganizationFilter, order: OrganizationOrder): OrganizationTypeOffsetPaginated! @isAuthenticated
organizations(includeAll: Boolean! = false, filters: OrganizationFilter, order: OrganizationOrder, pagination: OffsetPaginationInput): OrganizationTypeOffsetPaginated! @isAuthenticated
projects(includeAll: Boolean! = false, filters: ProjectFilter, order: ProjectOrder, pagination: OffsetPaginationInput): ProjectTypeOffsetPaginated! @isAuthenticated
tutorial(id: ID!): TutorialType! @isAuthenticated
tutorials(pagination: OffsetPaginationInput, filters: TutorialFilter, order: TutorialOrder): TutorialTypeOffsetPaginated! @isAuthenticated
tutorials(includeAll: Boolean! = false, filters: TutorialFilter, order: TutorialOrder, pagination: OffsetPaginationInput): TutorialTypeOffsetPaginated! @isAuthenticated
contributorUsers(pagination: OffsetPaginationInput, filters: ContributorUserFilter, order: ContributorUserOrder): ContributorUserTypeOffsetPaginated!
contributorUser(id: ID!): ContributorUserType!
contributorUserGroups(pagination: OffsetPaginationInput, filters: ContributorUserGroupFilter, order: ContributorUserGroupOrder): ContributorUserGroupTypeOffsetPaginated!
contributorUserGroup(id: ID!): ContributorUserGroupType!
contributorUserGroupMembers(pagination: OffsetPaginationInput, filters: ContributorUserGroupMembershipFilter, order: ContributorUserGroupMembershipOrder): ContributorUserGroupMembershipTypeOffsetPaginated!
contributorTeam(id: ID!): ContributorTeamType!
contributorTeams(pagination: OffsetPaginationInput, filters: ContributorTeamFilter, order: ContributorTeamOrder): ContributorTeamTypeOffsetPaginated!
contributorUserByUserId(userId: ID!): ContributorUserType!
contributorUserGroups(includeAll: Boolean! = false, filters: ContributorUserGroupFilter, order: ContributorUserGroupOrder, pagination: OffsetPaginationInput): ContributorUserGroupTypeOffsetPaginated!
contributorUserGroupMembers(includeAll: Boolean! = false, filters: ContributorUserGroupMembershipFilter, order: ContributorUserGroupMembershipOrder, pagination: OffsetPaginationInput): ContributorUserGroupMembershipTypeOffsetPaginated!
contributorTeams(includeAll: Boolean! = false, filters: ContributorTeamFilter, order: ContributorTeamOrder, pagination: OffsetPaginationInput): ContributorTeamTypeOffsetPaginated! @isAuthenticated
communityStats: CommunityStatsType!

"\nStats from last 30 days\n"
Expand Down
Loading