aboutsummaryrefslogtreecommitdiffstats
path: root/graphql/gen_graphql.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-08-14 14:48:41 +0200
committerMichael Muré <batolettre@gmail.com>2018-08-14 14:48:41 +0200
commit5c568a362b73cf163b06bc7371982f9a7ceaaf29 (patch)
tree755b61f969913b5290f3d56f4cfba4070b8155bc /graphql/gen_graphql.go
parentef0d8fa108fbdef24997a84a3c6ecbf21cbc0a9e (diff)
downloadgit-bug-5c568a362b73cf163b06bc7371982f9a7ceaaf29.tar.gz
gqlgen: add a small program to go:generate the code
Diffstat (limited to 'graphql/gen_graphql.go')
-rw-r--r--graphql/gen_graphql.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/graphql/gen_graphql.go b/graphql/gen_graphql.go
new file mode 100644
index 00000000..fb0cfa68
--- /dev/null
+++ b/graphql/gen_graphql.go
@@ -0,0 +1,46 @@
+// +build ignore
+
+package main
+
+import (
+ "fmt"
+ "io/ioutil"
+ "log"
+ "os"
+ "path"
+
+ "github.com/vektah/gqlgen/codegen"
+)
+
+func main() {
+ current, err := os.Getwd()
+ if err != nil {
+ log.Fatal(err.Error())
+ }
+
+ os.Chdir(path.Join(current, "graphql"))
+
+ fmt.Println("Generating graphql code ...")
+
+ log.SetOutput(ioutil.Discard)
+
+ config, err := codegen.LoadDefaultConfig()
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ schemaRaw, err := ioutil.ReadFile(config.SchemaFilename)
+ if err != nil {
+ log.Fatal("unable to open schema: " + err.Error())
+ }
+ config.SchemaStr = string(schemaRaw)
+
+ if err = config.Check(); err != nil {
+ log.Fatal("invalid config format: " + err.Error())
+ }
+
+ err = codegen.Generate(*config)
+ if err != nil {
+ log.Fatal(err.Error())
+ }
+}