comigor / artemis

Build dart types from GraphQL schemas and queries
MIT License
495 stars 119 forks source link

unable to add authorization header in Link #270

Open naikdp7 opened 3 years ago

naikdp7 commented 3 years ago

1)i have created one class which extends the Link 2)when my token is valid i have concat my customLink class with HttpLink(where i have set the uri and my header) 3)now while executing the request my server throws error of unAuthentication(token expired) 4)i have successfully refreshed my token 5)i want my current request(step3) to be executed with new token 6)for that i have to set my headers in my customLink class

i have tried below code

request.context.updateEntry((_)=>HttpLinkHeaders(headers: <String, String>{
              'Authorization': "Bearer ${new-token}"
            }));

Any help or guidance will be appreciated..thanks in advance

comigor commented 3 years ago

Hey @naikdp7! Artemis currently uses gql's Link as its underlining client mechanism. If you're changing/chaining new Links at runtime, you need to reinstantiate ArtemisClient.fromLink.

matehat commented 3 years ago

Somewhat related to #73. This comment specifically.

moseskarunia commented 3 years ago
  ArtemisClient client({required FirebaseAuth firebaseAuth}) =>
      ArtemisClient.fromLink(
        AuthLink(
          getToken: () async {
            final token = await firebaseAuth.currentUser?.getIdToken();
            return token;
          },
        ).concat(
          HttpLink(...),
        ),
      );
vasilich6107 commented 2 years ago

@naikdp7 do you still have issues with that?