From 2f3ce764ecbb3323d9f5b699999f31490906c59e Mon Sep 17 00:00:00 2001 From: Faraz Patankar Date: Thu, 14 May 2020 18:51:32 -0400 Subject: [PATCH] add comment to explain authentication setup --- with-apollo/apollo.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/with-apollo/apollo.js b/with-apollo/apollo.js index 16cba29..97c4013 100644 --- a/with-apollo/apollo.js +++ b/with-apollo/apollo.js @@ -2,15 +2,23 @@ import { ApolloClient, HttpLink, InMemoryCache } from '@apollo/client'; // import { setContext } from '@apollo/link-context'; const GRAPHQL_API_URL = 'https://www.graphqlhub.com/graphql'; -// const TOKEN = ''; -// const asyncAuthLink = setContext(async () => { -// return { -// headers: { -// Authorization: TOKEN, -// }, -// }; -// }); +/* +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, @@ -19,6 +27,5 @@ const httpLink = new HttpLink({ export const apolloClient = new ApolloClient({ cache: new InMemoryCache(), link: httpLink, - // use this when using with auth token // link: asyncAuthLink.concat(httpLink), });