Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

astprinter: PrintIndent applies indentation twice #405

Open
polarina opened this issue Aug 18, 2022 · 0 comments
Open

astprinter: PrintIndent applies indentation twice #405

polarina opened this issue Aug 18, 2022 · 0 comments
Labels
bug Something isn't working good first issue Good for newcomers internally-reviewed Internally reviewed

Comments

@polarina
Copy link

Check out the following snippet: https://go.dev/play/p/FkEAZlnbd-E

The indentation is set to a single tab ("\t"), however, the printed output uses two tabs for indentation. Only one is expected.


package main

import (
	"fmt"
	"os"

	"github.com/wundergraph/graphql-go-tools/pkg/ast"
	"github.com/wundergraph/graphql-go-tools/pkg/astparser"
	"github.com/wundergraph/graphql-go-tools/pkg/astprinter"
	"github.com/wundergraph/graphql-go-tools/pkg/operationreport"
)

const graph = `
	{ foo bar(id: "123") }
`

func main() {
	parser := astparser.NewParser()
	doc := ast.NewDocument()
	doc.Input.ResetInputBytes([]byte(graph))

	report := operationreport.Report{}
	parser.Parse(doc, &report)

	if report.HasErrors() {
		fmt.Println(report.Error())
		return
	}

	if err := astprinter.PrintIndent(doc, doc, []byte("\t"), os.Stdout); err != nil {
		fmt.Println(err)
	}

	fmt.Println()
}

Output:

{
		foo
		bar(id: "123")
}
@devsergiy devsergiy added good first issue Good for newcomers bug Something isn't working labels Feb 21, 2023
@StarpTech StarpTech added the internally-reviewed Internally reviewed label Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers internally-reviewed Internally reviewed
Projects
None yet
Development

No branches or pull requests

3 participants