Git Product home page Git Product logo

graphdoc's Introduction

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 HTML documentation from a GraphQLSchema instance or a string with your schema in SDL. Use graphdoc.to_md to create Markdown documentation.

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

API

graphdoc.to_doc(schema, templates_folder=None, context=None)

schema: GraphQLSchema instance or a str with a schema in SDL.

templates_folder: Optional path to a templates folder. If received, Jinja will look for templates in this folder before falling back to the defaults here.

context: An optional custom dictionary to be passed to the templates variables.

Custom templates

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

graphdoc's People

Contributors

wallee94 avatar bst-gbr avatar aurthurm avatar srchase avatar vanessapr avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.