Skip to main content

Generate HTML docs for your GraphQL API

Project description

Graphdoc - Generate docs for your GraphQL API

Graphdoc uses you GraphQL schema to generate an HTML page documenting your API. It works with Graphene and Ariadne and any other framework generating GraphQLSchema instances from the graphql-core package.

You can see an example of autogenerated docs using the SWAPI schema in this page

Installation

Install using pip:

pip install graphdoc

Usage

You can use graphdoc.to_doc to convert a GraphQLSchema or a string to an HTML with the docs.

Django and Graphene

# view.py
from django.http import HttpResponse
from graphene_django.views import GraphQLView
import graphdoc

def graphql_docs(request):
    # For graphene>=3 use schema.graphql_schema
    # html = graphdoc.to_doc(GraphQLView().schema.graphql_schema)
    html = graphdoc.to_doc(GraphQLView().schema)
    return HttpResponse(html, content_type='text/html')


# urls.py
from graphene_django.views import GraphQLView
from .views import graphql_docs

urlpatterns = [
    path('graphql', GraphQLView.as_view(), name='graphql_endpoint'),
    path('docs', graphql_docs, name='graphql_docs'),
]

FastAPI and Ariadne

# schema.py
from ariadne import load_schema_from_path

schema = load_schema_from_path("schema.graphql")


# main.py
from fastapi import FastAPI, Response
from schema import schema
import graphdoc

app = FastAPI()


@app.get("/docs")
async def graphql_docs():
    html = graphdoc.to_doc(schema)
    return Response(content=html, media_type="text/html")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

graphdoc-0.2.4.tar.gz (10.6 kB view hashes)

Uploaded Source

Built Distribution

graphdoc-0.2.4-py3-none-any.whl (19.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page