gqlformatter

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2022 License: MIT Imports: 9 Imported by: 0

README

gqlformatter

This is a GraphQL formatter, based on vektah/gqlparser.

The main objective is to provide a line by line output of GraphQL so it's easy to spot changes in committed queries.

Example use:

package main

import (
    "fmt"
    "log"

    "github.com/diegosz/gqlformatter"
)

func main() {
    s := "query{products(where:{and:{id:{gte:20} label:{eq:$label}}}){id name price}}"
    q, err := gqlformatter.FormatQuery(s)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(q)
}
query {
  products(
    where: {
      and: {
        id: { gte: 20 }
        label: { eq: $label }
      }
    }
  ) {
    id
    name
    price
  }
}

Documentation

Index

Constants

View Source
const (
	DefaultIndent = "  "
)

Variables

This section is empty.

Functions

func FormatQuery

func FormatQuery(input string) (string, error)

func FormatQueryMinified

func FormatQueryMinified(input string) (string, error)

func FormatQueryWithIndent added in v1.1.0

func FormatQueryWithIndent(input, indent string) (string, error)

Types

type Formatter

type Formatter interface {
	FormatQueryDocument(doc *ast.QueryDocument)
}

func NewFormatter

func NewFormatter(
	w io.Writer,
	opts ...Option) Formatter

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option configures the Formatter.

func WithIndent added in v1.1.0

func WithIndent(indent string) Option

WithIndent returns an Option which sets the tab string to use.

func WithMinification

func WithMinification() Option

WithMinification returns an Option which sets minified output.

type Options

type Options []Option

Options turns a list of Option instances into an Option.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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