Failed to map apollo-angular watch().valuechanges

453 Views Asked by At

im trying to create a graphql service to get and keep my data. To do that im extending a graphql-base.service, who has a executeQuery method, that return a observable.

graphql-base:

export class GraphqlBaseService {
  constructor() {}

  executeQuery(query: Query<any>) {
    return query.watch().valueChanges;
  }

  executeMutation(mutation: Mutation<any>) {
    return mutation.mutate().pipe();
  }

  executeSubscription(subscription: Subscription<any>) {
    return subscription.subscribe();
  }
}

On the section.service, i have the extension of graphql-base, and im using executeQuery method to get sections, like this:

export class SectionService extends GraphqlBaseService {
  sections$ = new BehaviorSubject<SectionModel[] | undefined | null>(undefined);

  constructor(private _sectionQuery: Section) {
    super();
  }

  getSections(bruteForce: boolean) {
    console.log(`getting sections...`);

    if (!bruteForce) {
      return this.sections$;
    }

    this.executeQuery(this._sectionQuery).pipe(
      map((result) => this.sections$ = result.data.section)
    );

    return this.sections$;
  }

  setSectionsData(sections: SectionModel[]) {
    this.sections$.next(sections);
  }
}

But, when im trying to map the response, vs code shows a cast error ->

Argument of type 'import("/Users/flavio.luiz/Documents/front-end/accenture/celesc/conecte-app/node_modules/rxjs/dist/types/internal/types").OperatorFunction<import("/Users/flavio.luiz/Documents/front-end/accenture/celesc/conecte-app/node_modules/@apollo/client/core/types").ApolloQueryResult<any>, any>' is not assignable to parameter of type 'import("/Users/flavio.luiz/node_modules/rxjs/internal/types").OperatorFunction<import("/Users/flavio.luiz/Documents/front-end/accenture/celesc/conecte-app/node_modules/@apollo/client/core/types").ApolloQueryResult<any>, any>'.

Im doing exactly what apollo-angular docs requires. Any help? o/ thx.

0

There are 0 best solutions below