Closed shohamroditimemphis closed 1 year ago
You can use this project I maintain to accomplish this https://github.com/bhoriuchi/graphql-go-tools
@shohamroditimemphis You can use https://github.com/graph-gophers/graphql-go The Schema.ASTSchema() method does exactly what you want:
package main
import (
"fmt"
"github.com/graph-gophers/graphql-go"
)
func main() {
s := `
query {
translate(text: String!, from: Language!, to: Language!) String!
}
enum Language {
ENGLISH
FRENCH
GERMAN
SPANISH
}
`
schema := graphql.MustParseSchema(s, nil)
ast := schema.ASTSchema()
for _, e := range ast.Enums {
fmt.Printf("Enum %q has the following options:\n", e.Name)
for _, o := range e.EnumValuesDefinition {
fmt.Printf(" - %s\n", o.EnumValue)
}
}
// output:
// Enum "Language" has the following options:
// - ENGLISH
// - FRENCH
// - GERMAN
// - SPANISH
}
Thanks
There is an option to create *graphql.Schema from string. This is my string : `type Query { greeting:String students:[Student] }
` and I want to create from string *graphql.Schema