Skip to content

Commit

Permalink
feat: add graphene and wagtail dependencies
Browse files Browse the repository at this point in the history
These prepare the project for GraphQL and content management
integration.
  • Loading branch information
ngurenyaga committed Nov 7, 2021
1 parent aeea79a commit ed0cf4f
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ steps:
'--platform', 'managed',
'--allow-unauthenticated',
'--add-cloudsql-instances', '${_CLOUDSQL_INSTANCE_CONNECTION_NAME}',
'--set-env-vars', 'GOOGLE_CLOUD_PROJECT=$PROJECT_ID,SETTINGS_NAME=${_SETTINGS_NAME},DJANGO_SETTINGS_MODULE=config.settings.production,DEFAULT_ORG_ID=99edd1b5-1ff2-49f4-8b0e-261c78909695',
'--set-env-vars', 'GOOGLE_CLOUD_PROJECT=$PROJECT_ID,SETTINGS_NAME=${_SETTINGS_NAME},DJANGO_SETTINGS_MODULE=config.settings.production,DEFAULT_ORG_ID=4181df12-ca96-4f28-b78b-8e8ad88b25df',
'--min-instances', '1',
'--max-instances', '8',
'--memory', '512M',
Expand Down
20 changes: 19 additions & 1 deletion config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,27 @@
"rest_framework_datatables",
"corsheaders",
"mjml",
"django.contrib.admin", # needs to come after jet so that jet static files are preferred
"django.contrib.admin",
"graphene_django",
"wagtail.contrib.forms",
"wagtail.contrib.redirects",
"wagtail.embeds",
"wagtail.sites",
"wagtail.users",
"wagtail.snippets",
"wagtail.documents",
"wagtail.images",
"wagtail.search",
"wagtail.admin",
"wagtail.core",
"taggit",
"modelcluster",
]

LOCAL_APPS = [
"mycarehub.users.apps.UsersConfig",
"mycarehub.common.apps.CommonConfig",
"mycarehub.content.apps.ContentConfig",
]
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS

Expand Down Expand Up @@ -131,6 +146,7 @@
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.common.BrokenLinkEmailsMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"wagtail.contrib.redirects.middleware.RedirectMiddleware",
]

# STATIC
Expand Down Expand Up @@ -342,3 +358,5 @@
"savannahghi.org",
],
)

GRAPHENE = {"SCHEMA": "mycarehub.schema.schema.schema"}
13 changes: 13 additions & 0 deletions config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.urls import include, path, re_path
from django.views import defaults as default_views
from django.views.decorators.csrf import csrf_exempt
from django.views.generic import RedirectView
from graphene_django.views import GraphQLView
from rest_framework.authtoken.views import obtain_auth_token
from wagtail.admin import urls as wagtailadmin_urls
from wagtail.documents import urls as wagtaildocs_urls

from mycarehub.common.views import AboutView, HomeView

Expand All @@ -29,6 +33,15 @@
r"^favicon\.ico$",
RedirectView.as_view(url=settings.STATIC_URL + "favicon.ico", permanent=True),
),
path("graphql", csrf_exempt(GraphQLView.as_view(graphiql=True)), name="graphql"),
# content management
path("admin/", include(wagtailadmin_urls)),
path("documents/", include(wagtaildocs_urls)),
# re_path(r"content", include("mycarehub.content.urls")),
# For anything not caught by a more specific rule above, hand over to
# Wagtail's serving mechanism
# from wagtail.core import urls as wagtail_urls
# re_path(r"", include(wagtail_urls)),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
if settings.DEBUG:
# Static file serving when using Gunicorn + Uvicorn for local web socket development
Expand Down
14 changes: 14 additions & 0 deletions mycarehub/common/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,17 @@ def test_drf_excel_io_mixin_get_filter_form(rf, user_with_all_permissions):
)(request=request)

assert response.status_code == status.HTTP_200_OK


def test_graphql_view_initialization(user_with_all_permissions, client):
client.force_login(user_with_all_permissions)
url = reverse("graphql")
response = client.post(
url,
data={"query": "query { hello }"},
content_type="application/json",
accept="application/json",
)

print(response.content)
assert response.status_code == status.HTTP_200_OK
Empty file added mycarehub/content/__init__.py
Empty file.
6 changes: 6 additions & 0 deletions mycarehub/content/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class ContentConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "mycarehub.content"
Empty file.
Empty file added mycarehub/schema/__init__.py
Empty file.
8 changes: 8 additions & 0 deletions mycarehub/schema/schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import graphene


class Query(graphene.ObjectType):
hello = graphene.String(default_value="Hi!")


schema = graphene.Schema(query=Query)
6 changes: 5 additions & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ django-compressor~=2.4.1 # https://github.com/django-compressor/django-compress
django-cors-headers~=3.10.0 # https://github.com/adamchainz/django-cors-headers
django-crispy-forms~=1.13.0 # https://github.com/django-crispy-forms/django-crispy-forms
django-environ~=0.8.1 # https://github.com/joke2k/django-environ
django-filter~=21.1
django-filter>=2.2,<3.0 # this constraint is required for wagtail
django-mjml[requests]~=0.11.0
django-taggit~=1.5.1
django-modelcluster~=5.2
django-model-utils~=4.2.0 # https://github.com/jazzband/django-model-utils
django-phonenumber-field~=5.2.0
django-storages[google]~=1.12.3 # https://github.com/jschneier/django-storages
Expand All @@ -21,6 +23,7 @@ google-api-python-client~=2.29.0
google-auth~=2.3.3
google-cloud-secret-manager~=2.7.0
google-cloud-storage~=1.42.3
graphene-django~=2.15.0
openpyxl~=3.0.7
phonenumbers~=8.12.29
python-slugify~=5.0.2 # https://github.com/un33k/python-slugify
Expand All @@ -29,3 +32,4 @@ rcssmin~=1.0.6 # https://github.com/ndparker/rcssmin
requests~=2.26.0
uvicorn[standard]~=0.15.0 # https://github.com/encode/uvicorn
whitenoise~=5.3.0 # https://github.com/evansd/whitenoise
wagtail~=2.15

0 comments on commit ed0cf4f

Please sign in to comment.