Skip to content

Instantly share code, notes, and snippets.

@patcito
Created January 21, 2018 19:57
Show Gist options
  • Save patcito/1a7f148ecadc65d9a1735f1fc350477e to your computer and use it in GitHub Desktop.
Save patcito/1a7f148ecadc65d9a1735f1fc350477e to your computer and use it in GitHub Desktop.
open ApolloLinks;
open ApolloInMemoryCache;
module InMemoryCache =
ApolloInMemoryCache.CreateInMemoryCache(
{
type dataObject;
let inMemoryCacheObject = Js.Nullable.undefined;
}
);
let getAccessToken = () => "123";
let logout = () => ();
let contextHandler = () => {
let token = getAccessToken();
let headers = {"headers": {"authorization": {j|Bearer $token|j}}};
asJsObject(headers)
};
/* Create an HTTP Link */
module AuthLink =
ApolloLinks.CreateContextLink(
{
let contextHandler = contextHandler;
}
);
/* Create an HTTP Link */
module HttpLink =
ApolloLinks.CreateHttpLink(
{
let uri = "https://api.graph.cool/simple/v1/123";
}
);
module Client =
ReasonApollo.CreateClient(
{
let apolloClient =
ReasonApollo.createApolloClient(
~cache=InMemoryCache.cache,
~link=from([|AuthLink.link,HttpLink.link|]),
()
);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment