Skip to content

Commit 458fbae

Browse files
committed
Initialised and setup for the Strawberry
1 parent 2479d1f commit 458fbae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+643
-806
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ repos:
4747
- types-python-dateutil
4848
- types-PyYAML
4949
- types-requests
50+
- strawberry-graphql-django
5051
args:
5152
- --config-file
5253
- backend/pyproject.toml

backend/apps/common/graphql/__init__.py

Whitespace-only changes.

backend/apps/common/graphql/nodes.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

backend/apps/common/graphql/queries.py

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,39 @@
11
"""GitHub issue GraphQL node."""
22

3-
import graphene
3+
import strawberry
4+
import strawberry_django
45

5-
from apps.common.graphql.nodes import BaseNode
6+
from apps.github.graphql.nodes.user import UserNode
67
from apps.github.models.issue import Issue
78

89

9-
class IssueNode(BaseNode):
10+
@strawberry_django.type(
11+
Issue,
12+
fields=[
13+
"created_at",
14+
"state",
15+
"title",
16+
"url",
17+
],
18+
)
19+
class IssueNode:
1020
"""GitHub issue node."""
1121

12-
organization_name = graphene.String()
13-
repository_name = graphene.String()
22+
@strawberry.field
23+
def author(self) -> UserNode | None:
24+
"""Resolve author."""
25+
return self.author
1426

15-
class Meta:
16-
model = Issue
17-
fields = (
18-
"author",
19-
"created_at",
20-
"state",
21-
"title",
22-
"url",
23-
)
24-
25-
def resolve_organization_name(self, info) -> str | None:
27+
@strawberry.field
28+
def organization_name(self) -> str | None:
2629
"""Return organization name."""
27-
return self.repository.organization.login if self.repository.organization else None
30+
return (
31+
self.repository.organization.login
32+
if self.repository and self.repository.organization
33+
else None
34+
)
2835

29-
def resolve_repository_name(self, info):
36+
@strawberry.field
37+
def repository_name(self) -> str | None:
3038
"""Resolve the repository name."""
31-
return self.repository.name
39+
return self.repository.name if self.repository else None
Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,40 @@
11
"""Github Milestone Node."""
22

3-
import graphene
3+
import strawberry
4+
import strawberry_django
45

5-
from apps.common.graphql.nodes import BaseNode
6+
from apps.github.graphql.nodes.user import UserNode
67
from apps.github.models.milestone import Milestone
78

89

9-
class MilestoneNode(BaseNode):
10+
@strawberry_django.type(
11+
Milestone,
12+
fields=[
13+
"closed_issues_count",
14+
"created_at",
15+
"open_issues_count",
16+
"title",
17+
"url",
18+
],
19+
)
20+
class MilestoneNode:
1021
"""Github Milestone Node."""
1122

12-
organization_name = graphene.String()
13-
repository_name = graphene.String()
23+
@strawberry.field
24+
def author(self) -> UserNode | None:
25+
"""Resolve author."""
26+
return self.author
1427

15-
class Meta:
16-
model = Milestone
17-
18-
fields = (
19-
"author",
20-
"created_at",
21-
"title",
22-
"open_issues_count",
23-
"closed_issues_count",
24-
"url",
28+
@strawberry.field
29+
def organization_name(self) -> str | None:
30+
"""Return organization name."""
31+
return (
32+
self.repository.organization.login
33+
if self.repository and self.repository.organization
34+
else None
2535
)
2636

27-
def resolve_repository_name(self, info):
37+
@strawberry.field
38+
def repository_name(self) -> str | None:
2839
"""Resolve repository name."""
29-
return self.repository.name
30-
31-
def resolve_organization_name(self, info):
32-
"""Return organization name."""
33-
return self.repository.organization.login if self.repository.organization else None
40+
return self.repository.name if self.repository else None
Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,46 @@
11
"""GitHub organization GraphQL node."""
22

3-
import graphene
3+
import strawberry
4+
import strawberry_django
45
from django.db import models
56

6-
from apps.common.graphql.nodes import BaseNode
77
from apps.github.models.organization import Organization
88
from apps.github.models.repository import Repository
99
from apps.github.models.repository_contributor import RepositoryContributor
1010

1111

12-
class OrganizationStatsNode(graphene.ObjectType):
12+
@strawberry.type
13+
class OrganizationStatsNode:
1314
"""Organization stats node."""
1415

15-
total_repositories = graphene.Int()
16-
total_contributors = graphene.Int()
17-
total_stars = graphene.Int()
18-
total_forks = graphene.Int()
19-
total_issues = graphene.Int()
16+
total_contributors: int
17+
total_forks: int
18+
total_issues: int
19+
total_repositories: int
20+
total_stars: int
2021

2122

22-
class OrganizationNode(BaseNode):
23+
@strawberry_django.type(
24+
Organization,
25+
fields=[
26+
"avatar_url",
27+
"collaborators_count",
28+
"company",
29+
"created_at",
30+
"description",
31+
"email",
32+
"followers_count",
33+
"location",
34+
"login",
35+
"name",
36+
"updated_at",
37+
],
38+
)
39+
class OrganizationNode:
2340
"""GitHub organization node."""
2441

25-
stats = graphene.Field(OrganizationStatsNode)
26-
url = graphene.String()
27-
28-
class Meta:
29-
model = Organization
30-
fields = (
31-
"avatar_url",
32-
"collaborators_count",
33-
"company",
34-
"created_at",
35-
"description",
36-
"email",
37-
"followers_count",
38-
"location",
39-
"login",
40-
"name",
41-
"updated_at",
42-
)
43-
44-
def resolve_stats(self, info):
42+
@strawberry.field
43+
def stats(self) -> OrganizationStatsNode:
4544
"""Resolve organization stats."""
4645
repositories = Repository.objects.filter(organization=self)
4746

@@ -51,9 +50,10 @@ def resolve_stats(self, info):
5150
total_forks=models.Sum("forks_count"),
5251
total_issues=models.Sum("open_issues_count"),
5352
)
54-
total_stars = aggregated_stats["total_stars"] or 0
55-
total_forks = aggregated_stats["total_forks"] or 0
56-
total_issues = aggregated_stats["total_issues"] or 0
53+
54+
total_stars = aggregated_stats.get("total_stars") or 0
55+
total_forks = aggregated_stats.get("total_forks") or 0
56+
total_issues = aggregated_stats.get("total_issues") or 0
5757

5858
unique_contributors = (
5959
RepositoryContributor.objects.filter(repository__in=repositories)
@@ -70,6 +70,7 @@ def resolve_stats(self, info):
7070
total_issues=total_issues,
7171
)
7272

73-
def resolve_url(self, info):
73+
@strawberry.field
74+
def url(self) -> str:
7475
"""Resolve organization URL."""
7576
return self.url
Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,38 @@
11
"""GitHub Pull Request Node."""
22

3-
import graphene
3+
import strawberry
4+
import strawberry_django
45

5-
from apps.common.graphql.nodes import BaseNode
6+
from apps.github.graphql.nodes.user import UserNode
67
from apps.github.models.pull_request import PullRequest
78

89

9-
class PullRequestNode(BaseNode):
10+
@strawberry_django.type(
11+
PullRequest,
12+
fields=[
13+
"created_at",
14+
"title",
15+
],
16+
)
17+
class PullRequestNode:
1018
"""GitHub pull request node."""
1119

12-
organization_name = graphene.String()
13-
repository_name = graphene.String()
14-
url = graphene.String()
20+
@strawberry.field
21+
def author(self) -> UserNode | None:
22+
"""Resolve author."""
23+
return self.author
1524

16-
class Meta:
17-
model = PullRequest
18-
fields = (
19-
"author",
20-
"created_at",
21-
"title",
22-
)
23-
24-
def resolve_organization_name(self, info):
25+
@strawberry.field
26+
def organization_name(self) -> str | None:
2527
"""Return organization name."""
2628
return self.repository.organization.login if self.repository.organization else None
2729

28-
def resolve_repository_name(self, info):
30+
@strawberry.field
31+
def repository_name(self) -> str:
2932
"""Resolve repository name."""
3033
return self.repository.name
3134

32-
def resolve_url(self, info):
35+
@strawberry.field
36+
def url(self) -> str:
3337
"""Resolve URL."""
34-
return self.url
38+
return str(self.url) if self.url else ""
Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
11
"""GitHub release GraphQL node."""
22

3-
from __future__ import annotations
3+
import strawberry
4+
import strawberry_django
45

5-
import graphene
6-
7-
from apps.common.graphql.nodes import BaseNode
86
from apps.github.graphql.nodes.user import UserNode
97
from apps.github.models.release import Release
108
from apps.owasp.constants import OWASP_ORGANIZATION_NAME
119

1210

13-
class ReleaseNode(BaseNode):
11+
@strawberry_django.type(
12+
Release,
13+
fields=[
14+
"is_pre_release",
15+
"name",
16+
"published_at",
17+
"tag_name",
18+
],
19+
)
20+
class ReleaseNode:
1421
"""GitHub release node."""
1522

16-
author = graphene.Field(UserNode)
17-
organization_name = graphene.String()
18-
project_name = graphene.String()
19-
repository_name = graphene.String()
20-
url = graphene.String()
21-
22-
class Meta:
23-
model = Release
24-
fields = (
25-
"author",
26-
"is_pre_release",
27-
"name",
28-
"published_at",
29-
"tag_name",
30-
)
31-
32-
def resolve_organization_name(self, info) -> str | None:
23+
@strawberry.field
24+
def author(self) -> UserNode | None:
25+
"""Resolve author."""
26+
return self.author
27+
28+
@strawberry.field
29+
def organization_name(self) -> str | None:
3330
"""Return organization name."""
3431
return self.repository.organization.login if self.repository.organization else None
3532

36-
def resolve_project_name(self, info) -> str:
33+
@strawberry.field
34+
def project_name(self) -> str:
3735
"""Return project name."""
3836
return self.repository.project.name.lstrip(OWASP_ORGANIZATION_NAME)
3937

40-
def resolve_repository_name(self, info) -> str:
38+
@strawberry.field
39+
def repository_name(self) -> str:
4140
"""Return repository name."""
4241
return self.repository.name
4342

44-
def resolve_url(self, info) -> str:
43+
@strawberry.field
44+
def url(self) -> str:
4545
"""Return release URL."""
4646
return self.url

0 commit comments

Comments
 (0)