Reputation: 2674
I am trying to get my elm (v: 0.18) client to talk with my back-end via graphql. I am trying to avoid the elm-graphql libraries for now, and the basic elm HttpBuilder module.
The login command looks like this:
loginCmd : Model -> Cmd Msg
loginCmd model =
let
graphiql =
"""
mutation {
login(email: "[email protected]", password: "password") {
token
}
}
"""
in
HttpBuilder.post ("http://localhost:4000/api")
|> HttpBuilder.withStringBody graphiql
|> HttpBuilder.withExpect (Http.expectJson myJsonDecoder)
|> HttpBuilder.send GetTokenCompleted
The problem lies with the withStringBody
function. The compiler is sending me this:
The right side of (|>) is causing a type mismatch.
101| HttpBuilder.post ("http://localhost:4000/api")
102|> |> HttpBuilder.withStringBody graphiql
(|>) is expecting the right side to be a:
RequestBuilder () -> a
But the right side is:
String -> RequestBuilder a -> RequestBuilder a
I'm not sure what the problem is, given that the HttpBuilder docs say that it is of type withStringBody : String -> RequestBuilder -> RequestBuilder
, and uses this as an example:
post "https://example.com/api/items/1"
|> withHeader "Content-Type" "application/json"
|> withStringBody """{ "sortBy": "coolness", "take": 10 }"""
What am I doing wrong here?
Upvotes: 0
Views: 145
Reputation: 2406
According to the docs, withStringBody
actually takes String -> String -> RequestBuilder a
, so I would say you need to add a content string before the graphql
string, whatever would be appropriate for your graphql
backend.
|> HttpBuilder.withStringBody "text/plain" """{ "sortBy": "coolness", "take": 10 }"""
Upvotes: 3