Skip to content
This repository was archived by the owner on Jul 28, 2020. It is now read-only.

Latest commit

 

History

History
47 lines (33 loc) · 1.94 KB

README.md

File metadata and controls

47 lines (33 loc) · 1.94 KB

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