aboutsummaryrefslogtreecommitdiffstats
path: root/graphql/gen_graphql.go
blob: 84e0cfe018a57a866fa346423bcecaefe33c8c54 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// +build ignore

package main

import (
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"path"

	"github.com/99designs/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(os.Stdout)

	config, err := codegen.LoadConfigFromDefaultLocations()
	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())
	}
}