Reasonml-React: невозможно проанализировать результат graphql - PullRequest
0 голосов
/ 11 июня 2019

У меня есть следующее:

module GetLaunches = [%graphql
  {|
  query getLaunches{
      launches {
        flight_number
        mission_name
        launch_year
      }
  }
|}
];

let str = ReasonReact.string;

module Launch = {
  [@react.component]
  let make = (~launch)=>
  <div>
    (str("launch"))
  </div>
}

module Launches = {
  [@react.component]
  let make = (~launches) =>
  <div>
    {
      launches
      |> Js.Array.map(launch => <Launch  launch key=launch##flight_number/>)
      |> ReasonReact.array
    }
  </div>
};

module GetLaunchesQuery = ReasonApollo.CreateQuery(GetLaunches);

[@react.component]
let make = () =>
  <GetLaunchesQuery>
    ...{
      ({result}) =>
        switch(result){
          | Loading => <div> {ReasonReact.string("Loading")} </div>
          | Error(error) =>
            <div> {ReasonReact.string(error##message)} </div>
          | Data(response) =>
            <Launches launches=(response##launches)/>
        }
      }
  </GetLaunchesQuery>;

Но я продолжаю получать следующую ошибку:

This has type:
    {. "launches": option(Js.Array.t(option({. "flight_number": option(int),
                                              "launch_year": option(int),
                                              "mission_name": option(string)})))}
  But somewhere wanted:
    {. "launches": Js.Array.t(Js.t(({.. flight_number: string} as 'a)))}

  The incompatible parts:
    option(Js.Array.t(option({. "flight_number": option(int),
                               "launch_year": option(int),
                               "mission_name": option(string)})))
    vs
    Js.Array.t(Js.t('a)) (defined as array(Js.t('a)))
  Types for method launches are incompatible
...