Skip to main content

Generate HTML docs for your GraphQL API

Project description

Graphdoc - Generate docs for your GraphQL API

Graphdoc uses your 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

Use graphdoc.to_doc to create documentation from a GraphQLSchema instance or a string with your schema in SDL.

Examples

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")

Custom templates

The graphdoc.to_doc method accepts a second argument with a path to a templates folder. Templates are loaded using jinja's FileSystemLoader.

Files in this folder will override the default templates. Take a look to the defaults here.

You can find more example apps using custom templates and documenting multiple schemas in the examples folder

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.3.1.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

graphdoc-0.3.1-py3-none-any.whl (19.8 kB view details)

Uploaded Python 3

File details

Details for the file graphdoc-0.3.1.tar.gz.

File metadata

  • Download URL: graphdoc-0.3.1.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for graphdoc-0.3.1.tar.gz
Algorithm Hash digest
SHA256 97bebb9d239e484594e4e0a72f14fe56b186eef56ca3b767a2e6187a96e3b530
MD5 7a71bcf92905ae9835e4d258631f9271
BLAKE2b-256 c573325e796af0fc6a547735e5300b6b8c6bb4586f9b829c563ece9a9fea1cc0

See more details on using hashes here.

File details

Details for the file graphdoc-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: graphdoc-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 19.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for graphdoc-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d3c6450fbf2e6be489b142a0f61382941e6c587396611b44b44123c610cca7b3
MD5 b1a395c641a561ed82c0434f314ca805
BLAKE2b-256 4c61dbf09696fe5c01536d72bd1545599d3b82c13f91c5cb7ee52ef8eeec9e14

See more details on using hashes here.

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