doc

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 4, 2020 License: MIT Imports: 12 Imported by: 0

README

Documentation Generator

The documentation generator handles generating CommonMark documentation for a GraphQL document.

Example

Input:

schema {
	query: Query
}

"Query represents the queries this example provides."
type Query {
	hello: String
}

Output:

# Example Documentation
*This was generated by gqlc.*

## Table of Contents
- [Schema](#Schema)
- [Objects](#Objects)
	* [Query](#Query)

## Schema

*Root Operations*:
- query **([Query](#Query))**

## Objects

### Query
Query represents the queries this example provides.

*Fields*:
- hello **(String)**

Documentation

Overview

Package doc contains a CommonMark documentation generator for GraphQL Documents.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Generator

type Generator struct {
	sync.Mutex
	bytes.Buffer
	// contains filtered or unexported fields
}

Generator generates CommonMark documentation for GraphQL Documents.

func (*Generator) Generate

func (g *Generator) Generate(ctx context.Context, doc *ast.Document, opts map[string]interface{}) (err error)

Generate generates CommonMark documentation for the given document.

Example
g := new(Generator)

gqlSrc := `schema {
	query: Query
}

"Query represents the queries this example provides."
type Query {
	hello: String
}`

doc, err := parser.ParseDoc(token.NewDocSet(), "example", strings.NewReader(gqlSrc), 0)
if err != nil {
	return // Handle error
}

var b bytes.Buffer
ctx := gen.WithContext(context.Background(), gen.TestCtx{Writer: &b}) // Pass in an actual
err = g.Generate(ctx, doc, map[string]interface{}{"title": "Example Documentation"})
if err != nil {
	return // Handle err
}

fmt.Println(b.String())
Output:

# Example Documentation
*This was generated by gqlc.*

## Table of Contents
- [Schema](#Schema)
- [Objects](#Objects)
	* [Query](#Query)

## Schema

*Root Operations*:
- query **([Query](#Query))**

## Objects

### Query
Query represents the queries this example provides.

*Fields*:
- hello **(String)**

func (*Generator) In

func (g *Generator) In()

In increases the indent.

func (*Generator) Out

func (g *Generator) Out()

Out decreases the indent.

func (*Generator) P

func (g *Generator) P(str ...interface{})

P prints the arguments to the generated output.

func (*Generator) Reset

func (g *Generator) Reset()

Reset overrides the bytes.Buffer Reset method to assist in cleaning up some Generator state.

type Options

type Options struct {
	Title string
	HTML  bool
	// contains filtered or unexported fields
}

Options contains the options for the Documentation generator.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL