This tool generates boilerplate code for graphql-go based on a provided graphql.schema file. Additional config file can be provided to customize output.
go install github.com/Applifier/graphql-codegen
- Allow custom templates (without rebuilding)
Example below generates code for schema.graphql. Optional config config.hcl file is provided to tell the codegen where and how to fetch the data for the resolvers.
graphql-codegen generate -s=codegen/fixtures/httpget/schema.graphql -c=codegen/fixtures/httpget/config.hcl -p=httpget -o=test_output/
Example of the generated code (_gen.go files) can be found under /codegen/fixtures/httpget
- More examples under codegen/fixtures
Resolve field based on a struct property with the same name as the schema type field
Skips code generation for the field
Check example config and conversation.go
Resolve field with a http GET request to a server
type "Query" {
field "user" {
imports = ["\"fmt\""]
template "http_resolver" {
url = "fmt.Sprintf(\"https://static.everyplay.com/developer-quiz/data/users/%s\", args.ID)"
}
}
}