/go-gen-graphql

Primary LanguageGoMIT LicenseMIT

go-gen-graphql

Actions Status Coverage Status PkgGoDev go-report

Generate a graphql query/mutation body from a struct

package main

import (
	"fmt"
	gengraphql "github.com/Eun/go-gen-graphql"
)

func main() {
	type Data struct {
		ID             string
		Name           string `json:"name"`
		CreationTime   string `graphql:"createdOn"`
		ActiveProjects struct {
			ID string `json:"id"`
		} `json:"projects" graphql:"projects(filter: %q)"`
	}

	s, err := gengraphql.Generatef(Data{}, nil, "active")
	if err != nil {
		panic(err)
	}
	fmt.Println(s)
	// Output:
	// ID
	// name
	// createdOn
	// projects(filter: "active"){
	//   id
	// }
}

Build History

Build history