How to use the apollo-client-preset.from function in apollo-client-preset

To help you get started, we’ve selected a few apollo-client-preset examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github codinger41 / TrekLite / src / graphql / client.ts View on Github external
const httpLink = createHttpLink({
  uri: GRAPHQL_API_ENDPOINT
})

const authMiddleware = setContext(async (req, { headers }) => {
  const token = await AsyncStorage.getItem('token')
  return {
    headers: {
      ...headers,
      Authorization: `Bearer ${token}`
    }
  }
})

const client = new ApolloClient({
  link: from([authMiddleware, httpLink]),
  cache: new InMemoryCache()
})

export default client