mirror of
https://github.com/zhigang1992/examples.git
synced 2026-04-30 10:22:50 +08:00
add comment to explain authentication setup
This commit is contained in:
@@ -2,15 +2,23 @@ import { ApolloClient, HttpLink, InMemoryCache } from '@apollo/client';
|
|||||||
// import { setContext } from '@apollo/link-context';
|
// import { setContext } from '@apollo/link-context';
|
||||||
|
|
||||||
const GRAPHQL_API_URL = 'https://www.graphqlhub.com/graphql';
|
const GRAPHQL_API_URL = 'https://www.graphqlhub.com/graphql';
|
||||||
// const TOKEN = '';
|
|
||||||
|
|
||||||
// const asyncAuthLink = setContext(async () => {
|
/*
|
||||||
// return {
|
uncomment the code below in case you are using a GraphQL API that requires some form of
|
||||||
// headers: {
|
authentication. asyncAuthLink will run every time your request is made and use the token
|
||||||
// Authorization: TOKEN,
|
you provide while making the request.
|
||||||
// },
|
|
||||||
// };
|
|
||||||
// });
|
const TOKEN = '';
|
||||||
|
const asyncAuthLink = setContext(async () => {
|
||||||
|
return {
|
||||||
|
headers: {
|
||||||
|
Authorization: TOKEN,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
const httpLink = new HttpLink({
|
const httpLink = new HttpLink({
|
||||||
uri: GRAPHQL_API_URL,
|
uri: GRAPHQL_API_URL,
|
||||||
@@ -19,6 +27,5 @@ const httpLink = new HttpLink({
|
|||||||
export const apolloClient = new ApolloClient({
|
export const apolloClient = new ApolloClient({
|
||||||
cache: new InMemoryCache(),
|
cache: new InMemoryCache(),
|
||||||
link: httpLink,
|
link: httpLink,
|
||||||
// use this when using with auth token
|
|
||||||
// link: asyncAuthLink.concat(httpLink),
|
// link: asyncAuthLink.concat(httpLink),
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user