vektah / gqlparser

A port of the parser from graphql-js into golang
MIT License
498 stars 123 forks source link

Missing `Query` from the `query` field of `schema` #237

Open kmtym1998 opened 2 years ago

kmtym1998 commented 2 years ago

FormatSchema method omits schema if schema.query is Query (code). I confirmed the same behavior in case of Mutation and Subscription. Why does it omits Query, Mutation or Subscription from schema? If the process to omit Query, Mutation and Subscription is not needed, I would like to create a PR and fix it.

Thank you.

package main

import (
    "bytes"
    "fmt"

    "github.com/vektah/gqlparser/v2"
    "github.com/vektah/gqlparser/v2/ast"
    "github.com/vektah/gqlparser/v2/formatter"
)

func main() {
    strSchema := `
    schema {
        query: Query
    }
    type Query {
        noop: Boolean!
    }`

    var buf1 bytes.Buffer
    f := formatter.NewFormatter(&buf1, formatter.WithIndent("  "))
    schema, _ := gqlparser.LoadSchema(&ast.Source{
        Input: strSchema,
    })
    f.FormatSchema(schema)
    fmt.Println("formatted schema1:\n", buf1.String())

    strSchema = `
    schema {
        query: RenamedQuery
    }
    type RenamedQuery {
        noop: Boolean!
    }`

    var buf2 bytes.Buffer
    f = formatter.NewFormatter(&buf2, formatter.WithIndent("  "))
    schema, _ = gqlparser.LoadSchema(&ast.Source{
        Input: strSchema,
    })
    f.FormatSchema(schema)
    fmt.Println("formatted schema2:\n", buf2.String())
}
$ go run main.go
formatted schema1:
 type Query {
  noop: Boolean!
}

formatted schema2:
 schema {
  query: RenamedQuery
}
type RenamedQuery {
  noop: Boolean!
}