@@ -23,7 +23,7 @@ type Handler struct {
23
23
Schema * graphql.Schema
24
24
render * render.Render
25
25
}
26
- type requestOptions struct {
26
+ type RequestOptions struct {
27
27
Query string `json:"query" url:"query" schema:"query"`
28
28
Variables map [string ]interface {} `json:"variables" url:"variables" schema:"variables"`
29
29
OperationName string `json:"operationName" url:"operationName" schema:"operationName"`
@@ -36,7 +36,8 @@ type requestOptionsCompatibility struct {
36
36
OperationName string `json:"operationName" url:"operationName" schema:"operationName"`
37
37
}
38
38
39
- func getRequestOptions (r * http.Request ) * requestOptions {
39
+ // RequestOptions Parses a http.Request into GraphQL request options struct
40
+ func NewRequestOptions (r * http.Request ) * RequestOptions {
40
41
41
42
query := r .URL .Query ().Get ("query" )
42
43
if query != "" {
@@ -46,17 +47,17 @@ func getRequestOptions(r *http.Request) *requestOptions {
46
47
variablesStr := r .URL .Query ().Get ("variables" )
47
48
json .Unmarshal ([]byte (variablesStr ), variables )
48
49
49
- return & requestOptions {
50
+ return & RequestOptions {
50
51
Query : query ,
51
52
Variables : variables ,
52
53
OperationName : r .URL .Query ().Get ("operationName" ),
53
54
}
54
55
}
55
56
if r .Method != "POST" {
56
- return & requestOptions {}
57
+ return & RequestOptions {}
57
58
}
58
59
if r .Body == nil {
59
- return & requestOptions {}
60
+ return & RequestOptions {}
60
61
}
61
62
62
63
// TODO: improve Content-Type handling
@@ -68,26 +69,26 @@ func getRequestOptions(r *http.Request) *requestOptions {
68
69
case ContentTypeGraphQL :
69
70
body , err := ioutil .ReadAll (r .Body )
70
71
if err != nil {
71
- return & requestOptions {}
72
+ return & RequestOptions {}
72
73
}
73
- return & requestOptions {
74
+ return & RequestOptions {
74
75
Query : string (body ),
75
76
}
76
77
case ContentTypeFormURLEncoded :
77
- var opts requestOptions
78
+ var opts RequestOptions
78
79
err := r .ParseForm ()
79
80
if err != nil {
80
- return & requestOptions {}
81
+ return & RequestOptions {}
81
82
}
82
83
err = decoder .Decode (& opts , r .PostForm )
83
84
if err != nil {
84
- return & requestOptions {}
85
+ return & RequestOptions {}
85
86
}
86
87
return & opts
87
88
case ContentTypeJSON :
88
89
fallthrough
89
90
default :
90
- var opts requestOptions
91
+ var opts RequestOptions
91
92
body , err := ioutil .ReadAll (r .Body )
92
93
if err != nil {
93
94
return & opts
@@ -108,7 +109,7 @@ func getRequestOptions(r *http.Request) *requestOptions {
108
109
func (h * Handler ) ServeHTTP (w http.ResponseWriter , r * http.Request ) {
109
110
110
111
// get query
111
- opts := getRequestOptions (r )
112
+ opts := NewRequestOptions (r )
112
113
113
114
// execute graphql query
114
115
params := graphql.Params {
0 commit comments