Portfolio website written with Next.js
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
wychdev-nextjs/graphql/apolloClient.tsx

31 lines
561 B

2 years ago
import {
ApolloClient,
InMemoryCache,
createHttpLink
} from "@apollo/client";
import { setContext } from "@apollo/client/link/context";
export async function createClient() {
const httpLink = createHttpLink({
uri: "https://api.github.com/graphql",
});
const authLink = setContext((_, { headers }) => {
return {
headers: {
...headers,
authorization: `Bearer ${process.env.GITHUB_ACCESS_TOKEN}`,
}
}
});
const client = new ApolloClient({
link: authLink.concat(httpLink),
cache: new InMemoryCache()
});
return client;
}