Skip to content

Commit

Permalink
Update code
Browse files Browse the repository at this point in the history
  • Loading branch information
arkid15r committed Jan 25, 2025
1 parent b838e62 commit ed7432b
Show file tree
Hide file tree
Showing 25 changed files with 122 additions and 127 deletions.
File renamed without changes.
10 changes: 10 additions & 0 deletions backend/apps/common/graphql/nodes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""Common GraphQL types."""

from graphene_django import DjangoObjectType


class BaseNode(DjangoObjectType):
"""Base node."""

class Meta:
abstract = True
7 changes: 7 additions & 0 deletions backend/apps/common/graphql/queries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""Common GraphQL queries."""

import graphene


class BaseQuery(graphene.ObjectType):
"""Base GraphQL query."""
17 changes: 0 additions & 17 deletions backend/apps/common/schema.py

This file was deleted.

19 changes: 19 additions & 0 deletions backend/apps/github/graphql/nodes/issue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""GitHub issue GraphQL types."""

from apps.common.graphql.nodes import BaseNode
from apps.github.models.issue import Issue


class IssueNode(BaseNode):
"""GitHub issue."""

class Meta:
model = Issue
fields = (
"author",
"comments_count",
"created_at",
"number",
"state",
"title",
)
23 changes: 23 additions & 0 deletions backend/apps/github/graphql/nodes/release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""GitHub release GraphQL types."""

from graphene import Field

from apps.common.graphql.nodes import BaseNode
from apps.github.graphql.nodes.user import UserNode
from apps.github.models.release import Release


class ReleaseNode(BaseNode):
"""GitHub release."""

author = Field(UserNode)

class Meta:
model = Release
fields = (
"author",
"is_pre_release",
"name",
"published_at",
"tag_name",
)
18 changes: 18 additions & 0 deletions backend/apps/github/graphql/nodes/user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""GitHub user GraphQL types."""

from apps.common.graphql.nodes import BaseNode
from apps.github.models.user import User


class UserNode(BaseNode):
"""GitHub user."""

class Meta:
model = User
fields = (
"avatar_url",
"email",
"id",
"login",
"name",
)
15 changes: 0 additions & 15 deletions backend/apps/github/graphql/types/issue.py

This file was deleted.

19 changes: 0 additions & 19 deletions backend/apps/github/graphql/types/release.py

This file was deleted.

15 changes: 0 additions & 15 deletions backend/apps/github/graphql/types/user.py

This file was deleted.

Empty file.
Original file line number Diff line number Diff line change
@@ -1,46 +1,28 @@
"""Defines the GraphQL types for OWASP projects."""
"""GraphQL types for OWASP projects."""

import graphene

from apps.common.schema import BaseModelType
from apps.github.graphql.types.issue import IssueType
from apps.github.graphql.types.release import ReleaseType
from apps.common.graphql.nodes import BaseNode
from apps.github.graphql.nodes.issue import IssueNode
from apps.github.graphql.nodes.release import ReleaseNode
from apps.github.models.issue import Issue
from apps.github.models.release import Release
from apps.owasp.models.project import Project


class ProjectType(BaseModelType):
"""GraphQL type for OWASP projects."""
class ProjectNode(BaseNode):
"""Project node."""

recent_issues = graphene.List(
IssueType,
IssueNode,
limit=graphene.Int(default_value=10),
state=graphene.String(default_value="open"),
)
recent_releases = graphene.List(ReleaseType, limit=graphene.Int(default_value=10))
recent_releases = graphene.List(ReleaseNode, limit=graphene.Int(default_value=10))

class Meta:
"""Meta options for the ProjectType."""

model = Project
fields = (
"id",
"name",
"key",
"level",
"type",
"description",
"leaders_raw",
"contributors_count",
"custom_tags",
"forks_count",
"stars_count",
"open_issues_count",
"languages",
"created_at",
"updated_at",
)
fields = ()

def resolve_recent_issues(self, info, limit=10, state="open"):
"""Resolve recent issues for the project."""
Expand Down
6 changes: 3 additions & 3 deletions backend/apps/owasp/graphql/queries/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from apps.owasp.graphql.queries.project import ProjectQueries
from apps.owasp.graphql.queries.project import ProjectQuery


class OWASPQuery(ProjectQueries):
"""GraphQL query class for OWASP-related queries."""
class OwaspQuery(ProjectQuery):
"""GraphQL query class for owasp app queries."""
20 changes: 11 additions & 9 deletions backend/apps/owasp/graphql/queries/project.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
"""Defines the GraphQL queries for OWASP projects."""
"""OWASP project GraphQL queries."""

import graphene

from apps.owasp.graphql.types.project import ProjectType
from apps.common.graphql.queries import BaseQuery
from apps.owasp.graphql.nodes.project import ProjectNode
from apps.owasp.models.project import Project


class ProjectQueries(graphene.ObjectType):
"""GraphQL queries for OWASP projects."""
class ProjectQuery(BaseQuery):
"""Project GraphQL queries."""

project = graphene.Field(ProjectType, key=graphene.String())
project = graphene.Field(ProjectNode, key=graphene.String(required=True))

def resolve_project(self, info, key=None):
"""Resolve a project by its key."""
if key:
def resolve_project(root, info, key):
"""Resolve project by key."""
try:
return Project.objects.get(key=key)
return None
except Project.DoesNotExist:
return None
5 changes: 4 additions & 1 deletion backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ django-filter = "^24.3"
django-storages = { extras = ["s3"], version = "^1.14.4" }
djangorestframework = "^3.15.2"
geopy = "^2.4.1"
graphene-django = "^3.2.2"
gunicorn = "^23.0.0"
humanize = "^4.11.0"
lxml = "^5.3.0"
Expand All @@ -42,7 +43,6 @@ pyyaml = "^6.0.2"
requests = "^2.32.3"
sentry-sdk = {extras = ["django"], version = "^2.20.0"}
slack-bolt = "^1.22.0"
graphene-django = "^3.2.2"


[tool.poetry.group.dev.dependencies]
Expand Down Expand Up @@ -123,6 +123,9 @@ select = ["ALL"]
"**/admin.py" = ["D100", "D101", "D104"]
"**/api/*.py" = ["D106"]
"**/apps.py" = ["D100", "D101", "D104"]
"**/graphql/**/nodes.py" = ["D106"]
"**/graphql/nodes/*.py" = ["D106"]
"**/graphql/queries/*.py" = ["N805"]
"**/management/commands/*.py" = ["D101", "D102", "T201"]
"**/migrations/*.py" = ["D100", "D101", "D104"]
"**/models.py" = ["D106"]
Expand Down
10 changes: 5 additions & 5 deletions backend/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class Base(Configuration):
THIRD_PARTY_APPS = (
"algoliasearch_django",
"corsheaders",
"graphene_django",
"rest_framework",
"storages",
"graphene_django",
)

LOCAL_APPS = (
Expand Down Expand Up @@ -138,6 +138,10 @@ class Base(Configuration):
},
}

GRAPHENE = {
"SCHEMA": "settings.graphql.schema",
}

# Password validation
# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
Expand Down Expand Up @@ -191,7 +195,3 @@ class Base(Configuration):
SLACK_COMMANDS_ENABLED = True
SLACK_EVENTS_ENABLED = True
SLACK_SIGNING_SECRET = values.SecretValue()

GRAPHENE = {
"SCHEMA": "settings.graphql.schema",
}
9 changes: 4 additions & 5 deletions backend/settings/graphql.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
"""Defines the GraphQL schema for the application."""
"""Nest GraphQL schema."""

import graphene

from apps.common.schema import BaseQuery
from apps.owasp.graphql.queries import OWASPQuery
from apps.owasp.graphql.queries import OwaspQuery


class Query(BaseQuery, OWASPQuery):
"""Combines base and OWASP queries."""
class Query(OwaspQuery):
"""Schema queries."""


schema = graphene.Schema(query=Query)
2 changes: 1 addition & 1 deletion backend/settings/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
router.registry.extend(owasp_router.registry)

urlpatterns = [
path("graphql/", csrf_exempt(GraphQLView.as_view(graphiql=True))),
path("api/v1/", include(router.urls)),
path("a/", admin.site.urls),
path("graphql/", csrf_exempt(GraphQLView.as_view(graphiql=True))),
]

if SlackConfig.app:
Expand Down
2 changes: 1 addition & 1 deletion cspell/custom-dict.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
a2eeef
ansa
arkid15r
askowasp
Expand Down Expand Up @@ -26,7 +27,6 @@ saft
samm
SLF
Truncator
a2eeef
tsc
winsrdf
wsgi
Expand Down
4 changes: 2 additions & 2 deletions frontend/.env.example
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
VITE_ALGOLIA_APP_ID=your-algolia-app-id
VITE_ALGOLIA_SEARCH_API_KEY=your-algolia-search-api-key
VITE_API_URL=http://localhost:8000/api/v1
VITE_API_URL=http://localhost:8000/api/v1/
VITE_ENVIRONMENT=local
VITE_GRAPHQL_URL=http://localhost:8000/graphql/
VITE_GTM_AUTH=your-google-tag-manager-auth
VITE_GTM_ID=your-google-tag-manager-id
VITE_GTM_PREVIEW=
VITE_RELEASE_VERSION=
VITE_SENTRY_DSN=
VITE_GRAPHQL_URI=http://localhost:8000/graphql/
1 change: 0 additions & 1 deletion frontend/src/api/queries/projectQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { gql } from '@apollo/client'
export const GET_PROJECT_BY_KEY = gql`
query GetProject($key: String!) {
project(key: $key) {
name
recentReleases {
name
tagName
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/utils/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ export const ALGOLIA_APP_ID = process.env.VITE_ALGOLIA_APP_ID
export const ALGOLIA_SEARCH_API_KEY = process.env.VITE_ALGOLIA_SEARCH_API_KEY
export const API_URL = process.env.VITE_API_URL
export const ENVIRONMENT = process.env.VITE_ENVIRONMENT
export const GRAPHQL_URL = process.env.VITE_GRAPHQL_URL
export const GTM_AUTH = process.env.VITE_GTM_AUTH
export const GTM_ID = process.env.VITE_GTM_ID
export const GTM_PREVIEW = process.env.VITE_GTM_PREVIEW
export const RELEASE_VERSION = process.env.VITE_RELEASE_VERSION
export const SENTRY_DSN = process.env.VITE_SENTRY_DSN
export const GRAPHQL_URI = process.env.VITE_GRAPHQL_URI
7 changes: 3 additions & 4 deletions frontend/src/utils/helpers/apolloClient.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { ApolloClient, InMemoryCache } from '@apollo/client'
import { GRAPHQL_URI } from 'utils/credentials'
import { GRAPHQL_URL } from 'utils/credentials'
import { AppError, handleAppError } from 'wrappers/ErrorWrapper'

const createApolloClient = () => {
const GRAPHQL_URL = GRAPHQL_URI
if (!GRAPHQL_URL) {
const error = new AppError(500, 'Missing GraphQL URI')
const error = new AppError(500, 'Missing GraphQL URL')
handleAppError(error)
return null
}

return new ApolloClient({
uri: GRAPHQL_URL,
cache: new InMemoryCache(),
uri: GRAPHQL_URL,
})
}
const apolloClient = createApolloClient()
Expand Down
Loading

0 comments on commit ed7432b

Please sign in to comment.