Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in apollo-angular-link-http-batch when changing headers #771

Closed
Dragons0458 opened this issue Aug 24, 2018 · 2 comments
Closed

Error in apollo-angular-link-http-batch when changing headers #771

Dragons0458 opened this issue Aug 24, 2018 · 2 comments
Labels

Comments

@Dragons0458
Copy link

Dragons0458 commented Aug 24, 2018

Hello! when I try to change the headers of my requests to be able to put the apollo-angular-link-http-batch token it gives me an error which I do not get with apollo-angular-link-http. This is my code:

const http = from([
     setContext((operation, {headers}) => observableToPromise(angularFireAuth.idToken.pipe(
        map(token => ({
          headers: {
            ...headers,
            Authorization: token ? `Bearer ${token}` : null
          }
        }))
      ))),
      onError(error => store.dispatch(new actions.ChangeErrorAction(error))),
      httpBatchLink.create({
        uri: `${environment.http}://${rootPath}`
      })
    ]);

This is the error:
imagen

When I change the httpBatchLink variable to httpLink everything works normal, is it a bug in the library? Thank you very much!

@kamilkisiela
Copy link
Owner

A simple workaround:

import { HttpHeaders } from '@angular/common/http';

const http = from([
     setContext((operation, {headers}) => observableToPromise(angularFireAuth.idToken.pipe(
        map(token => ({
          headers: new HttpHeaders().set('Authorization', token ? `Bearer ${token}` : null)
        }))
      ))),
      onError(error => store.dispatch(new actions.ChangeErrorAction(error))),
      httpBatchLink.create({
        uri: `${environment.http}://${rootPath}`
      })
    ]);

@kamilkisiela
Copy link
Owner

kamilkisiela commented Oct 17, 2019

Should fix it #1383

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants