Applifier / graphql-codegen

Generates go code from graphql schema (to be used with github.com/neelance/graphql-go)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status

graphql-codegen

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

TODO

  • Allow custom templates (without rebuilding)

example

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

templates

default

Resolve field based on a struct property with the same name as the schema type field

custom

Skips code generation for the field

Check example config and conversation.go

http_resolver

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)"
    }
  }
}

About

Generates go code from graphql schema (to be used with github.com/neelance/graphql-go)


Languages

Language:Go 95.3%Language:HCL 4.2%Language:Makefile 0.5%