-
-
Save patcito/1a7f148ecadc65d9a1735f1fc350477e 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
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