Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 1.17 KB | None | 0 0
  1.  
  2. /* Create a GraphQL Query by using the graphql_ppx */
  3. module PostsQuery = [%graphql {|
  4.     query {
  5.         allPostOffers {
  6.           id
  7.           title
  8.           body
  9.         }
  10.       }
  11.   |}];
  12.  
  13.   let component = ReasonReact.statelessComponent("Greeting");
  14.  
  15.   module Query = Apollo.Client.Query;
  16.  
  17.   let make = (_children) => {
  18.   ...component,
  19.   render: (_) => {
  20.       let unexpectedError = <div> (ReasonReact.stringToElement("There was an internal error")) </div>;
  21.       let PostsQuery = PostsQuery.make(());
  22.       <Query query=PostsQuery>
  23.       ((response, parse) => {
  24.         switch response {
  25.            | Loading => <div> (ReasonReact.stringToElement("Loading")) </div>
  26.            | Failed(error) => <div> (ReasonReact.stringToElement(error)) </div>
  27.            | Loaded(result) => {
  28.              <div>
  29.              (
  30.               ReasonReact.arrayToElement(
  31.                 Array.map(((PostOffer) => <div key=(PostOffer##id)>
  32.                 (ReasonReact.stringToElement(PostOffer##title))</div>),
  33.                 response##data##allPostOffers)
  34.               )
  35.              )
  36.  
  37.              </div>
  38.            }
  39.       }})
  40.     </Query>
  41.   }
  42.   };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement