forked from sogko/golang-relay-starter-kit
/
updateSchema.go
41 lines (38 loc) · 944 Bytes
/
updateSchema.go
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
package main
import (
"encoding/json"
"github.com/graphql-go/graphql"
"github.com/graphql-go/graphql/testutil"
"github.com/sogko/golang-relay-starter-kit/data"
"io/ioutil"
"log"
"os"
)
func main() {
// Save JSON of full schema introspection for Babel Relay Plugin to use
result := graphql.Do(graphql.Params{
Schema: data.Schema,
RequestString: testutil.IntrospectionQuery,
})
if result.HasErrors() {
log.Fatalf("ERROR introspecting schema: %v", result.Errors)
return
} else {
b, err := json.MarshalIndent(result, "", " ")
if err != nil {
log.Fatalf("ERROR: %v", err)
}
err = ioutil.WriteFile("../data/schema.json", b, os.ModePerm)
if err != nil {
log.Fatalf("ERROR: %v", err)
}
}
// TODO: Save user readable type system shorthand of schema
// pending implementation of printSchema
/*
fs.writeFileSync(
path.join(__dirname, '../data/schema.graphql'),
printSchema(Schema)
);
*/
}