Slide 62
Slide 62 text
Connect Apollo to React Provider
function InstaPostApp() {
return (
);
}
import { HttpLink, InMemoryCache, ApolloClient } from 'apollo-boost';
import { setContext } from 'apollo-link-context';
import CONFIG from '../config';
// Add an Authorization header to each GraphQL request
const authLink = setContext((_, { headers }) => ({
headers: {
...headers,
Authorization: `Bearer ${CONFIG.accessToken}`,
},
}));
// Connect Apollo to the GraphQL Endpoint
const GRAPHQL_URL = `https://stitch.mongodb.com/api/client/v2.0/app/${STICH_APP_ID}/graphql`;
const httpLink = new HttpLink({ uri: GRAPHQL_URL });
// Instantiate the Apollo Client
const client = new ApolloClient({
link: authLink.concat(httpLink),
cache: new InMemoryCache(),
});
import React, { Fragment } from 'react';
import { ApolloProvider } from '@apollo/react-hooks';