JPG
JPG

Reputation: 88529

Retrieve GraphQL Introspection Schema as http response

I can generate the Django Graphene introspection schema by using the Django management command as

./manage.py graphql_schema --schema tutorial.quickstart.schema --out schema.json

How can I return the JSON schema as HTTP Response from a view, so that the client is able to view/fetch the same any time?

Upvotes: 2

Views: 976

Answers (1)

JPG
JPG

Reputation: 88529

Use introspect()--(GitHub) method of the Schema(...)--(GitHub) class

from django.http.response import JsonResponse
from tutorial.quickstart import schema


def introspection_schema(request):
    data = {"data": schema.introspect()}
    return JsonResponse(data)

Upvotes: 1

Related Questions