question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: Network error: Cannot read property 'append' of undefined

See original GitHub issue
there was an error sending the query Error: Network error: Cannot read property 'append' of undefined 
at new ApolloError (ApolloError.js:34)
at Object.error (QueryManager.js:118)
at SubscriptionObserver.error (zen-observable.js:178)     
at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:388)     
at Object.onInvoke (core.es5.js:3890)     
at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:387)     
at Zone.webpackJsonp.../../../../zone.js/dist/zone.js.Zone.run (zone.js:138)     
at zone.js:858    
at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421)     at Object.onInvokeTask (core.es5.js:3881)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
albertonaperijrcommented, May 5, 2018

I’d encountered the same issue before. I’d successfully passed the authorization header by directly putting it inside the headers object.

return {
    headers: {
        Authorization: `Bearer ${token}`
    }
};
1reaction
juansmolanocommented, Sep 2, 2018

@kamilkisiela @apollographql HI, I was about to open a new issue but I saw this first. I had the same problem.

The solution is in this doc: https://github.com/apollographql/apollo-angular/tree/master/packages/apollo-angular-link-headers

It seems there is documentation mismatch.

The solution that is working for me is:

const auth = setContext((request, previousContext) => ({ authorization: token }));

Below is the full service, and it is working: note: the token is gather by KeyCloak and is used on HTTP and WS

import { Injectable } from '@angular/core';
import { environment } from '../../environments/environment';
import { KeycloakService } from 'keycloak-angular';
import { HttpHeaders } from '@angular/common/http';
import { Apollo } from 'apollo-angular';
import { HttpLink } from 'apollo-angular-link-http';
import { setContext } from 'apollo-link-context';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { WebSocketLink } from 'apollo-link-ws';
import { split } from 'apollo-link';
import { getMainDefinition } from 'apollo-utilities';
import { httpHeaders } from 'apollo-angular-link-headers';


@Injectable()
export class GatewayService {

  constructor(
    public apollo: Apollo,
    private httpLink: HttpLink,
    private keycloakService: KeycloakService
  ) {

    //HTTP end-point
    const http = httpLink.create({ uri: environment.api.gateway.graphql.httpEndPoint });


    this.keycloakService.getToken().then(token => {


      const auth = setContext((request, previousContext) => ({
        authorization: token
      }));

      // //Add the JWT token in every request
      // const auth = setContext((operation, {headers}) => {

      // Create a WebSocket link:
      const ws = new WebSocketLink({
        uri: environment.api.gateway.graphql.wsEndPoint,
        options: {
          reconnect: true,
          connectionParams: {
            authToken: token,
          },
        }
      });



      // using the ability to split links, you can send data to each link
      // depending on what kind of operation is being sent
      const link = split(
        // split based on operation type
        ({ query }) => {
          const { kind, operation } = getMainDefinition(query);
          return kind === 'OperationDefinition' && operation === 'subscription';
        },
        ws,
        auth.concat(http),
      );


      //Create Apollo client
      this.apollo.create({
        link,
        cache: new InMemoryCache()
      });

    });



  }

}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Network error: Cannot read property 'append' of undefined ...
It seems there is documentation mismatch. The solution that is working for me is: const auth = setContext((request, previousContext) => ({ ...
Read more >
What does Cannot read property 'append' of undefined error ...
The error means that the object you're trying to call .append on is undefined and that call is in the AddItem method. ·...
Read more >
ERROR TypeError: Cannot read property 'append' of undefined
I want to build a column chart but I got the following error: ERROR TypeError: Cannot read property 'append' of undefined. The error...
Read more >
Uncaught TypeError: Cannot read property of undefined In
Uncaught TypeError : Cannot read property of undefined error occurs in Chrome when you read a property or call a method on an...
Read more >
Cannot read properties of undefined' - JavaScript Debugging
How To Fix 'Uncaught TypeError : Cannot read properties of undefined ' - JavaScript Debugging.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found