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

Missing Query from the query field of schema #237

Open
kmtym1998 opened this issue Sep 11, 2022 · 0 comments
Open

Missing Query from the query field of schema #237

kmtym1998 opened this issue Sep 11, 2022 · 0 comments

Comments

@kmtym1998
Copy link

kmtym1998 commented Sep 11, 2022

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!
}

@kmtym1998 kmtym1998 changed the title Missing Query from the query field of the schema. Missing Query from the query field of the schema Sep 11, 2022
@kmtym1998 kmtym1998 changed the title Missing Query from the query field of the schema Missing Query from the query field of schema Sep 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant