Created
September 22, 2017 18:03
-
-
Save Jannis/98b79abf467bcecda6ee803dd62c051a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* GraphQlTag.re */ | |
type query; | |
type gql = (string => query) [@bs]; | |
external gql : string => query = "default" [@@bs.module "graphql-tag"]; | |
let gql = gql; | |
/* Types.re */ | |
type httpLinkOptions = Js.t {. uri : string}; | |
type link = Js.t {.}; | |
type clientOptions = Js.t {. link : link}; | |
type queryOptions = Js.t {. query : GraphQlTag.query}; | |
type queryResult; | |
type client = Js.t {. query : (queryOptions => Js.Promise.t queryResult) [@bs.meth]}; | |
/* ApolloClientPreset.re */ | |
type httpLinkOptions = Js.t {. uri : string}; | |
type link = Js.t {.}; | |
type clientOptions = Js.t {. link : link}; | |
type queryOptions = Js.t {. query : GraphQlTag.query}; | |
type queryResult; | |
type client = Js.t {. query : (queryOptions => Js.Promise.t queryResult) [@bs.meth]}; | |
/* ApolloProvider.re */ | |
external apollo_provider : ReasonReact.reactClass = "ApolloProvider" [@@bs.module "react-apollo"]; | |
let make ::client children => | |
ReasonReact.wrapJsForReason reactClass::apollo_provider props::{"client": client} children; | |
/* ReactApollo.re */ | |
type wrapper = (ReasonReact.reactClass => ReasonReact.reactClass) [@bs]; | |
type graphql = (GraphQlTag.query => wrapper) [@bs]; | |
external graphql : graphql = "graphql" [@@bs.module "react-apollo"]; | |
let graphql = graphql; | |
/* Apollo.re */ | |
let link = | |
ApolloClientPreset.httpLink { | |
"uri": "https://api.graph.cool/simple/v1/??????????????????????" | |
}; | |
let client = ApolloClientPreset.apolloClient {"link": link}; | |
/* Queries.re */ | |
open GraphQlTag; | |
let allSectionsQuery = | |
gql {| | |
query { | |
allSections { | |
id | |
title | |
content | |
} | |
} | |
|}; | |
/* Index.re */ | |
/* | |
open Js.Promise; | |
open Queries; | |
let promise = | |
Apollo.client##query {"query": allSectionsQuery} | |
|> then_ (fun result => Js.log result |> resolve) | |
|> catch (fun error => Js.log ("Error", error) |> resolve); | |
*/ | |
ReactDOMRe.renderToElementWithId | |
<ApolloProvider client=Apollo.client> <App /> </ApolloProvider> "app"; | |
/* App.re */ | |
let addAllSections = ReactApollo.graphql Queries.allSectionsQuery [@bs]; | |
let componentWithAllSections = addAllSections Sections.jsComponent [@bs]; | |
let make children => | |
ReasonReact.wrapJsForReason | |
reactClass::componentWithAllSections props::(Js.Obj.empty ()) children; | |
/* Sections.re */ | |
let component = ReasonReact.statelessComponent "Sections"; | |
let make ::data _children => { | |
...component, | |
render: fun _self => | |
if data##loading { | |
<div> (ReasonReact.stringToElement "Loading...") </div> | |
} else { | |
let sections = data##allSections; | |
<div> | |
( | |
ReasonReact.arrayToElement ( | |
Array.map | |
( | |
fun section => | |
<div key=section##id> | |
<h1> (ReasonReact.stringToElement section##title) </h1> | |
<p> (ReasonReact.stringToElement section##content) </p> | |
</div> | |
) | |
sections | |
) | |
) | |
</div> | |
} | |
}; | |
let jsComponent = | |
ReasonReact.wrapReasonForJs ::component (fun props => make data::props##data [||]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like there are some bindings missing from the
ApolloClientPreset.re
block here.