当前位置: 首页 > 知识库问答 >
问题:

通过elm发送graphql突变

解晟睿
2023-03-14

我试图让我的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
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
post "https://example.com/api/items/1"
  |> withHeader "Content-Type" "application/json"
  |> withStringBody """{ "sortBy": "coolness", "take": 10 }"""

共有1个答案

齐弘业
2023-03-14

根据文档,withStringBody实际上使用String->RequestBuilder a,因此我认为您需要在GraphQL字符串之前添加一个内容字符串,无论该字符串适合您的GraphQL后端。

|> HttpBuilder.withStringBody "text/plain" """{ "sortBy": "coolness", "take": 10 }"""
 类似资料:
  • dillonkearns/elm-graphql Why use this package over the other available Elm GraphQL packages? This is the only one thatgenerates type-safe code for your entire schema. Check out this blog post, Type-Sa

  • 如何通过Azure从我的UWP-App向不同设备上的应用程序的其他实例发送推送通知? 以下是注册设备以接收推送的说明。(这是可行的)第二部分是关于如何在控制台应用程序上发送推送(这也是可行的)https://azure.microsoft.com/en-us/documentation/articles/notification-hubs-windows-store-dotnet-get-star

  • 我想在登录时向特定用户发送通知,我使用Firebase消息,我可以通过控制台发送通知,但我想使用发送到主题和request以Swift代码发送此通知。当我在postman中运行代码时,我无法实现http请求以发送通知。我有以下错误: 请求缺少身份验证密钥(FCM令牌)。请参阅FCM文档的“认证”部分,网址为https://firebase.google.com/docs/cloud-messagi

  • 我一直在用代表我的office365帐号发送SMTP邮件,工作了大概一个星期,然后突然不工作了,不知道怎么变了。 当我在PHPMailer中启用high debug logging时,我看到: SMTP- 这篇文章似乎是最相关的: 不接受来自服务器的身份验证:504 5.7.4无法识别的身份验证类型 以下是我交给PHPMailer的文字SMTP设置: 以及实际的PHP代码: 作为理智检查,我在中使

  • 我的一个EC2实例上有一个graphql服务器正在运行。我也有AWS appsync运行,但目前它只与几个Lambda集成。 我想将我的Appsync连接到graphql服务器,这样Appsync将作为特定查询/变化的代理。 因此,从客户端来看,它将如下所示: 客户端将一个查询发送到APPESNC,让我们假设它看起来像这样: Appsync已经定义了一个查询,它被配置为在graphql服务器上代理

  • 我正在尝试向使用Apollo的GraphQL服务器发送突变查询。 然而,我只看到实现这一点的唯一方法是使用突变组件。https://www.apollographql.com/docs/react/essentials/mutations/#the-突变成分 有没有一种简单的方法可以发送这样的突变? 从“graphql标记”导入gql;