我试图让我的elm(v:0.18)客户端通过graphql与我的后端通话。我现在试图避免使用elm-graphql库,以及基本的elm HttpBuilder模块。
login命令如下所示:
loginCmd : Model -> Cmd Msg
loginCmd model =
let
graphiql =
"""
mutation {
login(email: "me@myapp.com", password: "password") {
token
}
}
"""
in
HttpBuilder.post ("http://localhost:4000/api")
|> HttpBuilder.withStringBody graphiql
|> HttpBuilder.withExpect (Http.expectJson myJsonDecoder)
|> HttpBuilder.send GetTokenCompleted
问题在于withStringBody
功能。编译器正在发送给我:
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
我不确定问题是什么,因为HttpBuilder docs说它是withStringBody : String -> RequestBuilder -> RequestBuilder
类型,并以此为例:
post "https://example.com/api/items/1"
|> withHeader "Content-Type" "application/json"
|> withStringBody """{ "sortBy": "coolness", "take": 10 }"""
我在这里做错了什么?
答案 0 :(得分:3)
根据文档,withStringBody
实际上需要String -> String -> RequestBuilder a
,所以我要说你需要在graphql
字符串之前添加一个内容字符串,无论你的{{1}是什么后端。
graphql