通过 elm 发送 graphql 突变
Sending graphql mutations through elm
我正在尝试让我的 elm (v: 0.18) 客户端通过 graphql 与我的后端对话。我现在正在尝试避免使用 elm-graphql 库和基本的 elm HttpBuilder 模块。
登录命令如下所示:
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 }"""
我做错了什么?
根据文档,withStringBody
实际上需要 String -> String -> RequestBuilder a
,所以我会说您需要在 graphql
字符串之前添加一个内容字符串,无论什么适合您的 graphql
后端。
|> HttpBuilder.withStringBody "text/plain" """{ "sortBy": "coolness", "take": 10 }"""
我正在尝试让我的 elm (v: 0.18) 客户端通过 graphql 与我的后端对话。我现在正在尝试避免使用 elm-graphql 库和基本的 elm HttpBuilder 模块。
登录命令如下所示:
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 }"""
我做错了什么?
根据文档,withStringBody
实际上需要 String -> String -> RequestBuilder a
,所以我会说您需要在 graphql
字符串之前添加一个内容字符串,无论什么适合您的 graphql
后端。
|> HttpBuilder.withStringBody "text/plain" """{ "sortBy": "coolness", "take": 10 }"""