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

Apollo 3 Type Error with SubscriptionServer #5851

Closed
berkaytheunicorn opened this issue Oct 31, 2021 · 4 comments
Closed

Apollo 3 Type Error with SubscriptionServer #5851

berkaytheunicorn opened this issue Oct 31, 2021 · 4 comments

Comments

@berkaytheunicorn
Copy link

berkaytheunicorn commented Oct 31, 2021

I'm trying to setup an Apollo 3 + Typescript project, when I follow the subscription example on docs, I'm getting these errors.

Screen Shot 2021-10-31 at 13 38 06

both execute and subscribe has different type on GraphQL package.

Btw, I'm importing those from graphql.

Any suggestions?

@glasser
Copy link
Member

glasser commented Nov 1, 2021

Hi @berkaey. It's definitely possible there's an error in our doc example that explains how to continue to use the unmaintained subscriptions-transport-ws package with Apollo Server 3; we don't automatically type-check the doc examples. However, it's hard to debug this based on a screen shot, especially one where the error obscures the code. Do you think you could demonstrate the issue via a full repository that fails to build (eg a git repo or codesandbox.io sandbox)?

@riginoommen
Copy link

riginoommen commented Nov 2, 2021

I also face same issue when the graphql is upgrades to v16.x

graphql/graphql-js#2301

with the latest graphql the support of execute and subscribe is depricated

@berkaytheunicorn
Copy link
Author

@glasser something like this helps?

import { execute, GraphQLError, subscribe, TypeDefinitionNode } from "graphql";
import { SubscriptionServer } from "subscriptions-transport-ws";

// setup subscription server
    this.apolloSubscrtipions = SubscriptionServer.create(
      {
        schema,
        // @ts-ignore
        execute,
        // @ts-ignore
        subscribe,

        async onConnect(
          connectionParams: Object,
          webSocket: WebSocket,
          context: any,
        ) {
          if (this.onConnect) {
            await this.clientDidConnect(connectionParams, webSocket, context);
          }

          this.log.info("CONNECTED");

          return context;
        },

        async onDisconnect(webSocket: any, connectionContext: any) {
          if (connectionContext) {
            const context = await connectionContext.initPromise;
            await this.clientDidDisconnect(
              webSocket,
              connectionContext,
              context,
            );
            this.log.info("DISCONNECTED");
          }
        },
      },
      {
        server: this.httpServer,
        path: this.config.paths.graphqlSubscription,
      },
    );

I had to use // @ts-ignore.

@glasser
Copy link
Member

glasser commented Nov 2, 2021

My belief is that if you upgrade to the newly-released subscriptions-transport-ws@0.11.0 it should resolve the issue with no changes needed to the example code or Apollo Server. Let me know if that turns out not to be true!

@glasser glasser closed this as completed Nov 2, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants