-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
37 lines (33 loc) · 828 Bytes
/
main.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
package main
import (
"GO-Mysql-grphql/schema/query"
"encoding/json"
"fmt"
"github.com/graphql-go/graphql"
"GO-Mysql-grphql/schema/mutation"
"net/http"
)
func executeQuery(query string, schema graphql.Schema) *graphql.Result {
result := graphql.Do(graphql.Params{
Schema: schema ,
RequestString: query,
})
if len(result.Errors) > 0 {
fmt.Printf("wrong result, unexpected errors: %v", result.Errors)
}
return result
}
func main(){
var Schame,err = graphql.NewSchema(graphql.SchemaConfig{
Query:query.RootQuery,
Mutation: mutation.Mutation,
})
if err != nil{
panic(err.Error())
}
http.HandleFunc("/graphql", func(w http.ResponseWriter, r *http.Request) {
result := executeQuery(r.URL.Query().Get("Query"), Schame)
json.NewEncoder(w).Encode(result)
})
http.ListenAndServe(":8088", nil)
}