0

我有这个查询我试图用 graphql_ppx 库的原因进行测试。代码要点

这是编辑器类型注释的截图: 在此处输入图像描述

使用@mhallin/graphql_ppx库,我设置了以下查询:

    module FilmQuery = [%graphql
  {|
    {
      allFilms {
        films {
          id
          title
          releaseDate
        }
      }
    }
|}
];

exception Graphql_error(string);

/* Construct a "packaged" query; FilmQuery takes no arguments: */
let filmQuery = FilmQuery.make();

/* Send this query string to the server */
let query = filmQuery##query // type string

当我将查询发送到服务器时,我收到以下错误,它返回以下错误。

{ errors: [ { message: 'Must provide query string.' } ] }

但是如果你 Js.log(query) 你会看到它正在构建,它适用于 https://swapi.apis.guru

query films($first: Int)  {
  allFilms(first: $first)  {
   films  {
     id  
     title  
     releaseDate  
   }
  }
}

如果你 Js.log(filmQuery) 你得到:

{ query: 'query   {\nallFilms  {\nfilms  {\nid  \ntitle  \nreleaseDate  \n}\n}\n}',

变量:空,解析:[功能:解析]}

如果您在 Altair 中运行相同的查询并检查在 devtools 网络选项卡中发送的查询,您会看到:

{"query":"    query films($first: Int) {\n      allFilms(first: $first) {\n        films {\n          id\n          title\n          releaseDate\n        }\n      }\n    }\n","variables":{}}

为编辑器提供了这种类型的错误:“-错误 [bucklescript] 这有类型:字符串但在某个地方想要:Js.t({.. 查询:字符串,变量:Js.Json.t }) 字符串”

如何解决此承诺/单位类型?谢谢你。

所以新的问题是:为什么 sendQuery() 函数不能识别filmQuery##parse密钥?

4

1 回答 1

0

您的方法sendQuery期望FilmQuery.make()从.querystring

您可以通过传递filmQueryas intosendQuery而不仅仅是变量引用的query属性来解决此问题。filmQueryquery

于 2018-02-27T13:47:51.737 回答