mirror of
https://github.com/zhigang1992/examples.git
synced 2026-01-12 17:13:21 +08:00
32 lines
754 B
JavaScript
32 lines
754 B
JavaScript
import { ApolloClient, HttpLink, InMemoryCache } from '@apollo/client';
|
|
// import { setContext } from '@apollo/link-context';
|
|
|
|
const GRAPHQL_API_URL = 'https://www.graphqlhub.com/graphql';
|
|
|
|
/*
|
|
uncomment the code below in case you are using a GraphQL API that requires some form of
|
|
authentication. asyncAuthLink will run every time your request is made and use the token
|
|
you provide while making the request.
|
|
|
|
|
|
const TOKEN = '';
|
|
const asyncAuthLink = setContext(async () => {
|
|
return {
|
|
headers: {
|
|
Authorization: TOKEN,
|
|
},
|
|
};
|
|
});
|
|
|
|
*/
|
|
|
|
const httpLink = new HttpLink({
|
|
uri: GRAPHQL_API_URL,
|
|
});
|
|
|
|
export const apolloClient = new ApolloClient({
|
|
cache: new InMemoryCache(),
|
|
link: httpLink,
|
|
// link: asyncAuthLink.concat(httpLink),
|
|
});
|