openreplay / openreplay

Session replay and analytics tool you can self-host. Ideal for reproducing issues, co-browsing with users and optimizing your product.
https://openreplay.com
Other
9.31k stars 512 forks source link

createTrackerLink from @openreplay/tracker-graphql returns incompatible type #2504

Open andreialecu opened 3 weeks ago

andreialecu commented 3 weeks ago

Ref: https://github.com/openreplay/openreplay/blob/5700a16a945797f002f778fa7ebf95a07c79ab98/tracker/tracker-graphql/src/apolloMiddleware.ts#L5-L11

@apollo/client exports a type for RequestHandler which is incompatible with the one exported by @openreplay/tracker-graphql, resulting in TS errors when trying to assign the result of tracker.use to a variable of type RequestHandler

Type '(operation: Operation, forward: NextLink) => Observable<unknown>' is not assignable to type 'RequestHandler'.
  Types of parameters 'forward' and 'forward' are incompatible.
    Types of parameters 'operation' and 'operation' are incompatible.
      Type 'Operation' is missing the following properties from type 'Operation': setContext, getContextts(2322)

repro:

import type { RequestHandler } from '@apollo/client/core';

class AnalyticsService {
  trackerLink: RequestHandler | undefined = undefined;

  init() {
    this.trackerLink = tracker.use(createTrackerLink());
  }
}

The type from @apollo/client should be used instead. Also @apollo/client should probably be an optional peer dependency in package.json, see: https://yarnpkg.com/configuration/manifest#peerDependenciesMeta.optional

nick-delirium commented 2 weeks ago

can merge as soon as this is resolved