0

I decided to wrap up the GraphQLModule that is created by ng add apollo-angular into our own Angular Shared Module.

https://www.apollographql.com/docs/angular/basics/setup/#installation-with-angular-schematics

While performing queries inside of this module, I receive responses from the server.

However, when using this module in another application, we receive no response or errors:

  myQuery = gql`
    {
      member {
        id
        details {
          id
        }
      }
    }
  `

  queryOptions: WatchQueryOptions = {query: this.myQuery, errorPolicy: 'all'}
  myQueryObs: Observable<any>

  constructor(private apollo: Apollo) {}

  ngOnInit() {
    this.myQueryObs = this.apollo.watchQuery<Query>(this.queryOptions)
    .valueChanges.pipe(map (results => {
      if (results.errors) {
        console.log('ERRORS!!! YAY!!!') // NEVER GET HERE
      }
      console.log('RESULTS') // NEVER GET HERE EITHER
    }));
  }

I've logged the crap out of it and cannot determine why it is not responding at all. It acts like Apollo is not instantiated at all, but console output proves otherwise.

Any advice or help is greatly appreciated!

Vippy
  • 1,356
  • 3
  • 20
  • 30

1 Answers1

0

Ok, the answer was quite easy. The example above is returning an observable, which is why no results. I still need to subscribe to that observable to get results. So, to get results it would be better to:

   this.apollo
      .watchQuery(this.queryOptions)
      .valueChanges.subscribe((result: any) => {
        console.log('++++++++ RESULTS +++++++++', result)
      });
Vippy
  • 1,356
  • 3
  • 20
  • 30