Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

feat: Added support for API #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
23 changes: 23 additions & 0 deletions questions/schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import graphene
from graphene_django.types import DjangoObjectType
from .models import Type, Topic

class TypeNode(DjangoObjectType):
class Meta:
model= Type

class TopicNode(DjangoObjectType):
class Meta:
model= Topic

# Writing an app level query
class Query(graphene.ObjectType):
all_types= graphene.List(TypeNode)
all_topics= graphene.List(TopicNode)

def resolve_all_types(self, info):
return Type.objects.all()


def resolve_all_topic(self, info):
return Topic.objectsall()
9 changes: 9 additions & 0 deletions qujini/schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import graphene
import questions.schema


class Query(questions.schema.Query, graphene.ObjectType):
# This class extends all abstract apps level Queries and graphene.ObjectType
pass

schema = graphene.Schema(query=Query)
5 changes: 4 additions & 1 deletion qujini/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
'django.contrib.staticfiles',
'questions',
'ckeditor',
'graphene_django',
]

MIDDLEWARE = [
Expand Down Expand Up @@ -101,7 +102,9 @@
},
]


GRAPHENE= {
'SCHEMA': 'qujini.schema.schema'
}
# Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/

Expand Down
6 changes: 5 additions & 1 deletion qujini/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
"""
from django.contrib import admin
from django.urls import path
from graphene_django.views import GraphQLView
from qujini.schema import schema


urlpatterns = [
path('admin/', admin.site.urls),
path(r'admin/', admin.site.urls),
path(r'',GraphQLView.as_view(graphiql=True)),
]