SHARE
TWEET

Drivers

a guest Aug 9th, 2019 190 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module GetDrivers = [%graphql
  2.   {|
  3.   query getDrivers{
  4.     all_drivers {
  5.       id
  6.       name
  7.       email
  8.     }
  9.   }
  10.   |}
  11. ];
  12.  
  13. module Driver = {
  14.   [@react.component];
  15.   let make = (~driver) =>
  16.     switch (driver##name) {
  17.     | Some(name) => <div> {ReasonReact.string(name)} </div>
  18.     | None => React.null
  19.     };
  20. };
  21.  
  22. module Drivers = {
  23.   [@react.component];
  24.   let make = (~drivers) =>
  25.     <div>
  26.       {
  27.         React.array(
  28.           Array.of_list(List.map(driver => <Driver driver />, drivers)),
  29.         )
  30.       }
  31.     </div>;
  32. };
  33.  
  34. module GetDriversQuery = ReasonApollo.CreateQuery(GetDrivers);
  35. [@react.component]
  36. let make = () =>
  37.   <GetDriversQuery>
  38.     ...{
  39.          ({result}) =>
  40.            switch (result) {
  41.            | Loading => <div> {ReasonReact.string("Loading")} </div>
  42.            | Error(error) =>
  43.              <div> {ReasonReact.string(error##message)} </div>
  44.            | Data(response) =>
  45.              response##all_drivers
  46.              |> Js.Option.getWithDefault([||])
  47.              |> Array.map(
  48.                   fun
  49.                   | Some(drivers) => <Drivers drivers />
  50.                   | None => React.null,
  51.                 )
  52.              |> ReasonReact.array
  53.            }
  54.        }
  55.   </GetDriversQuery>;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top