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

Type error in SSELink Apollo example #108

Open
extremegf opened this issue Sep 17, 2024 · 8 comments
Open

Type error in SSELink Apollo example #108

extremegf opened this issue Sep 17, 2024 · 8 comments
Labels
bug Something isn't working

Comments

@extremegf
Copy link

extremegf commented Sep 17, 2024

Screenshot
I use code from the example here
image

Expected Behaviour
The example should work without type errors.

Actual Behaviour
Instead I get the error as shown above.

Further Information
This started showing up when i updated all patch versions of my packages. Likely some typescript instrumentation just caught it, because downgrading back the apollo and graphql packages did not help.

@extremegf
Copy link
Author

Out of curiosity, I've checked the dependency update one by one. This is caused by updating @apollo/client 3.10.4 -> 3.11.8

@WKampel
Copy link

WKampel commented Oct 15, 2024

Any solutions here?

@extremegf
Copy link
Author

I just downgraded.

@enisdenjo
Copy link
Owner

You can always cast to any.

@extremegf
Copy link
Author

I assume it will be fixed eventually, if not I'll probably do that.

@RMHonor
Copy link

RMHonor commented Nov 25, 2024

Instead of importing FetchResult from @apollo/client, import ExecutionResult from graphql.

import { ApolloLink, Operation, Observable } from "@apollo/client/core";
import { ExecutionResult, print } from "graphql";
import { createClient, ClientOptions, Client } from "graphql-sse";

export class SSELink extends ApolloLink {
  private client: Client;

  constructor(options: ClientOptions) {
    super();
    this.client = createClient(options);
  }

  public request(operation: Operation): Observable<ExecutionResult> {
    return new Observable((sink) => {
      return this.client.subscribe<ExecutionResult>(
        { ...operation, query: print(operation.query) },
        {
          next: sink.next.bind(sink),
          complete: sink.complete.bind(sink),
          error: sink.error.bind(sink),
        },
      );
    });
  }
}

@extremegf
Copy link
Author

I confirm, that @RMHonor suggestion sovles the problem.
🎉

@enisdenjo
Copy link
Owner

Even though #108 (comment) is a fix, I consider this a bug because there's no reason the FetchResult should not work. I think the issue is caused by the lack/improper usage of the patch message in graphql-sse.

@enisdenjo enisdenjo added the bug Something isn't working label Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants