Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Work in progress branch for graphql endpoints #256

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# cookbook/schema.py
import graphene
from graphene_django import DjangoObjectType

from enterprise_catalog.apps.catalog.models import EnterpriseCatalog


class EnterpriseCatalogType(DjangoObjectType):
something_not_on_model = graphene.String(name='yolo', default_value='you only live once')
class Meta:
model = EnterpriseCatalog
fields = (
'uuid',
'title',
'enterprise_uuid',
'enterprise_name',
'enabled_course_modes',
'publish_audit_enrollment_urls',
)

# def resolve_something_not_on_model(root, info):
# return 'WHYYYYYY Hello There'

def resolve_title(root, info):
return 'an overwritten title!'
29 changes: 29 additions & 0 deletions enterprise_catalog/apps/api/graphql/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from django.conf.urls import url

from django.views.decorators.csrf import csrf_exempt

from enterprise_catalog.apps.api.graphql.views import schema

from edx_rest_framework_extensions.auth.jwt.authentication import (
JwtAuthentication,
)

from rest_framework.authentication import SessionAuthentication
from graphene_django.views import GraphQLView
from rest_framework import permissions
from rest_framework.decorators import authentication_classes, permission_classes, api_view

# Reusing the rest api permission and authentication stufffff to handle authentication and csrf things
# Janky but works
def rest_permissions_view():
view = GraphQLView.as_view(graphiql=True, schema=schema)
view = permission_classes((permissions.IsAuthenticated,))(view)
view = authentication_classes((JwtAuthentication, SessionAuthentication))(view)
view = api_view(['GET', 'POST'])(view)
return view

urlpatterns = [
# ...
url('authgraph', rest_permissions_view()),
url('graphiql', csrf_exempt(GraphQLView.as_view(graphiql=True, schema=schema)))
]
6 changes: 6 additions & 0 deletions enterprise_catalog/apps/api/graphql/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import graphene

class Query(graphene.ObjectType):
hello = graphene.String(default='Hi there')

schema = graphene.Schema(query=Query)
2 changes: 2 additions & 0 deletions enterprise_catalog/apps/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
from django.conf.urls import include, url

from enterprise_catalog.apps.api.v1 import urls as v1_urls
from enterprise_catalog.apps.api.graphql import urls as graphql_urls


app_name = 'api'
urlpatterns = [
url(r'^v1/', include(v1_urls)),
url(r'^graphql/', include(graphql_urls)),
]
10 changes: 10 additions & 0 deletions enterprise_catalog/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
THIRD_PARTY_APPS = (
'corsheaders',
'csrf.apps.CsrfAppConfig', # Enables frontend apps to retrieve CSRF tokens
'graphene_django',
'rest_framework',
'rest_framework_swagger',
'social_django',
Expand Down Expand Up @@ -348,6 +349,15 @@
'API_KEY': '',
}

# Graphql
GRAPHENE = {
'SCHEMA': 'enterprise_catalog.apps.api.graphql.view.schema',
'MIDDLEWARE': [
'edx_rest_framework_extensions.auth.jwt.middleware.JwtAuthCookieMiddleware',
'edx_rest_framework_extensions.auth.jwt.middleware.JwtRedirectToLoginIfUnauthenticatedMiddleware',
],
}

# Set up system-to-feature roles mapping for edx-rbac
SYSTEM_TO_FEATURE_ROLE_MAPPING = {
# The enterprise catalog admin role is for users who need to perform state altering requests on catalogs
Expand Down
1 change: 1 addition & 0 deletions requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ edx-django-release-util
edx-drf-extensions
edx_rbac
edx-rest-api-client==1.9.2
graphene-django
mysqlclient
pytz
jsonfield2==3.0.3
Expand Down
Loading