Skip to content

Commit c699263

Browse files
committed
Add ID field to required nodes
- CommunityStatsType (all/last-30-days) - UserStats
1 parent 01c8a49 commit c699263

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

django/apps/existing_database/query.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def get_community_stats() -> CommunityStatsType:
4141
total_user_groups=models.Count("user_group", distinct=True),
4242
)
4343
return CommunityStatsType(
44+
id="all",
4445
total_contributors=user_agg_data["total_users"] or 0,
4546
total_user_groups=user_group_agg_data["total_user_groups"] or 0,
4647
total_swipes=user_agg_data["swipes_sum"] or 0,
@@ -64,6 +65,7 @@ def get_community_stats_latest() -> CommunityStatsType:
6465
total_user_groups=models.Count("user_group", distinct=True),
6566
)
6667
return CommunityStatsType(
68+
id="last-30-days",
6769
total_contributors=user_agg_data["total_users"] or 0,
6870
total_user_groups=user_group_agg_data["total_user_groups"] or 0,
6971
total_swipes=user_agg_data["swipes_sum"] or 0,

django/apps/existing_database/types.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class DateRangeInput:
2424

2525
@strawberry.type
2626
class CommunityStatsType:
27+
id: strawberry.ID
2728
total_swipes: int
2829
total_contributors: int
2930
total_user_groups: int
@@ -264,23 +265,33 @@ def __post_init__(self, date_range, user_id):
264265
filters = {
265266
"user_id": user_id,
266267
}
268+
self._user_id = user_id
267269
if date_range:
268270
filters.update(
269271
timestamp_date__gte=date_range.from_date,
270272
timestamp_date__lte=date_range.to_date,
271273
)
272274
self._qs = AggregatedUserStatData.objects.filter(**filters)
273275

276+
@strawberry.field
277+
async def id(self) -> strawberry.ID:
278+
return self._user_id
279+
274280

275281
@strawberry.type
276282
class UserStats:
277283
user_id: InitVar[str]
278284

279285
def __post_init__(self, user_id):
286+
self.id = user_id
280287
self._user_id = user_id
281288
self.qs = AggregatedUserStatData.objects.filter(user_id=user_id)
282289
self.ug_qs = AggregatedUserGroupStatData.objects.filter(user_id=user_id)
283290

291+
@strawberry.field
292+
async def id(self) -> strawberry.ID:
293+
return self._user_id
294+
284295
@strawberry.field
285296
async def stats(self) -> UserStatType:
286297
agg_data = await self.qs.aaggregate(

django/schema.graphql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
scalar AreaSqKm
22

33
type CommunityStatsType {
4+
id: ID!
45
totalSwipes: Int!
56
totalContributors: Int!
67
totalUserGroups: Int!
@@ -153,6 +154,7 @@ type UserFilteredStats implements UserUserGroupBaseFilterStatsQuery {
153154
swipeByProjectType: [ProjectTypeSwipeStatsType!]!
154155
swipeByOrganizationName: [OrganizationSwipeStatsType!]!
155156
contributionByGeo: [MapContributionStatsType!]!
157+
id: ID!
156158
}
157159

158160
input UserGroupFilter {
@@ -260,6 +262,7 @@ type UserStatType {
260262
}
261263

262264
type UserStats {
265+
id: ID!
263266
stats: UserStatType!
264267

265268
"""Stats from last 30 days"""

0 commit comments

Comments
 (0)