Skip to content
Open
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
36 changes: 36 additions & 0 deletions package/api/schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import graphene
from graphene_django.types import DjangoObjectType
from package.models import Category, Project, ProjectImage


class CategoryType(DjangoObjectType):
class Meta:
model = Category
fields = ('title', 'description')


class ProjectType(DjangoObjectType):
repository_url = graphene.Field(graphene.String)

class Meta:
model = Project
fields = ('name', 'description', 'url', 'category', 'images',)

def resolve_repository_url(self, info):
return self.repo_url


class ProjectImageType(DjangoObjectType):
class Meta:
model = ProjectImage


class Query(object):
categories = graphene.List(CategoryType)
projects = graphene.List(ProjectType)

def resolve_categories(self, info, **kwargs):
return Category.objects.all()

def resolve_projects(self, info, **kwargs):
return Project.objects.all()
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Pillow==4.2.1
rocketchat-API==0.6.3
markdown==2.6.11
python-dotenv==0.8.0
graphene_django==2.8.2
django-cors-headers==3.2.1

# Redis support
django-redis==4.6.0
Expand Down
9 changes: 9 additions & 0 deletions schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import graphene
import package.api.schema


class Query(package.api.schema.Query, graphene.ObjectType):
pass


schema = graphene.Schema(query=Query)
15 changes: 15 additions & 0 deletions settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'dj_pagination.middleware.PaginationMiddleware',
'social_auth_local.middleware.SocialAuthLocalExceptionMiddleware',
'corsheaders.middleware.CorsMiddleware',
]

TEMPLATES = [
Expand Down Expand Up @@ -141,6 +142,7 @@
"social_auth_local",
"im",
"timeline",

]

PREREQ_APPS = [
Expand All @@ -154,6 +156,7 @@
"django.contrib.humanize",
"django.contrib.staticfiles",


# external
"crispy_forms",
"dj_pagination",
Expand All @@ -167,6 +170,8 @@
'rest_framework',
'chroniker',
'dynamic_preferences',
'graphene_django',
'corsheaders',
]

INSTALLED_APPS = PREREQ_APPS + PROJECT_APPS
Expand Down Expand Up @@ -541,3 +546,13 @@
CHRONIKER_CHECK_LOCK_FILE = False
CHRONIKER_DISABLE_RAW_COMMAND = True
CHRONIKER_EMAIL_SENDER = 'Chroniker'

GRAPHENE = {
'SCHEMA': 'schema.schema'
}
CORS_ORIGIN_WHITELIST = [
'http://localhost:8080',
'https://localhost:8080',
]

CORS_ALLOW_CREDENTIALS = True
5 changes: 5 additions & 0 deletions urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
from homepage.views import homepage, error_404_view, error_500_view, health_check_view, SitemapView
from package.views import category, python3_list
from django.contrib.auth.views import logout as contrib_logout_view
from graphene_django.views import GraphQLView
from django.views.decorators.csrf import csrf_exempt

urlpatterns = [

Expand Down Expand Up @@ -81,6 +83,9 @@
view=apiv1_gone,
name="apiv1_gone",
),
# url(r'^graphql/$', GraphQLView.as_view(graphiql=True)),
url(r'^explore', GraphQLView.as_view(graphiql=True)),
url(r'^graphql', csrf_exempt(GraphQLView.as_view())),

# url(r'^api/v1/', include('core.apiv1', namespace="apitest")),

Expand Down