1
- module GraphQL.Client.Http.Util exposing (.. )
1
+ module GraphQL.Client.Http.Util exposing (DocumentLocation , Error (..) , RequestConfig , RequestError , RequestOptions , defaultRequestOptions , parameterizedUrl , postBody , postBodyJson , requestConfig )
2
2
3
3
import GraphQL.Response as Response
4
4
import Http
@@ -18,7 +18,7 @@ postBodyJson documentString variableValues =
18
18
|> Maybe . map ( \ obj -> [ ( " variables" , obj ) ] )
19
19
|> Maybe . withDefault []
20
20
in
21
- Json . Encode . object ( [ ( " query" , documentValue ) ] ++ extraParams)
21
+ Json . Encode . object ( [ ( " query" , documentValue ) ] ++ extraParams)
22
22
23
23
24
24
postBody : String -> Maybe Json .Encode .Value -> Http .Body
@@ -32,6 +32,7 @@ parameterizedUrl url documentString variableValues =
32
32
firstParamPrefix =
33
33
if String . contains " ?" url then
34
34
" &"
35
+
35
36
else
36
37
" ?"
37
38
@@ -46,7 +47,7 @@ parameterizedUrl url documentString variableValues =
46
47
)
47
48
|> Maybe . withDefault " "
48
49
in
49
- url ++ queryParam ++ variablesParam
50
+ url ++ queryParam ++ variablesParam
50
51
51
52
52
53
type alias RequestOptions =
@@ -81,7 +82,7 @@ type alias RequestConfig a =
81
82
, body : Http . Body
82
83
, expect : Http . Expect a
83
84
, timeout : Maybe Float
84
- , tracker: Maybe String
85
+ , tracker : Maybe String
85
86
}
86
87
87
88
@@ -105,40 +106,15 @@ requestConfig requestOptions documentString expect variableValues =
105
106
( url, body ) =
106
107
if requestOptions. method == " GET" then
107
108
( parameterizedUrl requestOptions. url documentString variableValues, Http . emptyBody )
109
+
108
110
else
109
111
( requestOptions. url, postBody documentString variableValues )
110
112
in
111
- { method = requestOptions. method
112
- , headers = requestOptions. headers
113
- , url = url
114
- , body = body
115
- , expect = expect
116
- , timeout = requestOptions. timeout
117
- , tracker = Nothing
118
- }
119
-
120
-
121
- dataDecoder =
122
- Json . Decode . field " data"
123
-
124
-
125
- errorsResponseDecoder : Json .Decode .Decoder (List RequestError )
126
- errorsResponseDecoder =
127
- Json . Decode . field " errors" Response . errorsDecoder
128
-
129
-
130
- convertHttpError : (Http .Error -> err ) -> (List RequestError -> err ) -> Http .Error -> err
131
- convertHttpError wrapHttpError wrapGraphQLError httpError =
132
- let
133
- handleErrorWithResponseBody responseBody =
134
- responseBody
135
- |> Json . Decode . decodeString errorsResponseDecoder
136
- |> Result . map wrapGraphQLError
137
- |> Result . withDefault ( wrapHttpError httpError)
138
- in
139
- case httpError of
140
- Http . BadBody body ->
141
- handleErrorWithResponseBody body
142
-
143
- _ ->
144
- wrapHttpError httpError
113
+ { method = requestOptions. method
114
+ , headers = requestOptions. headers
115
+ , url = url
116
+ , body = body
117
+ , expect = expect
118
+ , timeout = requestOptions. timeout
119
+ , tracker = Nothing
120
+ }
0 commit comments