Merge pull request #56 from dukebody/graphqlview-schema-explicit

Explain alternative way to specify schema in tutorial.
This commit is contained in:
Syrus Akbary 2016-11-13 19:20:42 -08:00 committed by GitHub
commit dd07cb1f6c

View File

@ -188,6 +188,8 @@ And then add the ``SCHEMA`` to the ``GRAPHENE`` config in ``cookbook/settings.py
'SCHEMA': 'cookbook.schema.schema' 'SCHEMA': 'cookbook.schema.schema'
} }
Alternatively, we can specify the schema to be used in the urls definition,
as explained below.
Creating GraphQL and GraphiQL views Creating GraphQL and GraphiQL views
----------------------------------- -----------------------------------
@ -199,6 +201,22 @@ view.
This view will serve as GraphQL endpoint. As we want to have the This view will serve as GraphQL endpoint. As we want to have the
aforementioned GraphiQL we specify that on the params with ``graphiql=True``. aforementioned GraphiQL we specify that on the params with ``graphiql=True``.
.. code:: python
from django.conf.urls import url, include
from django.contrib import admin
from graphene_django.views import GraphQLView
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^graphql', GraphQLView.as_view(graphiql=True)),
]
If we didn't specify the target schema in the Django settings file
as explained above, we can do so here using:
.. code:: python .. code:: python
from django.conf.urls import url, include from django.conf.urls import url, include
@ -210,7 +228,7 @@ aforementioned GraphiQL we specify that on the params with ``graphiql=True``.
urlpatterns = [ urlpatterns = [
url(r'^admin/', admin.site.urls), url(r'^admin/', admin.site.urls),
url(r'^graphql', GraphQLView.as_view(graphiql=True)), url(r'^graphql', GraphQLView.as_view(graphiql=True, schema=schema)),
] ]
Apply model changes to database Apply model changes to database