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 v3 Subscriptions #1875

Open
a-type opened this issue Sep 27, 2021 · 1 comment
Open

Apollo v3 Subscriptions #1875

a-type opened this issue Sep 27, 2021 · 1 comment

Comments

@a-type
Copy link

a-type commented Sep 27, 2021

Describe the bug

Since incorporating graphql-modules I've not been able to get a subscription socket to connect and stay connected. The socket sends a connection_init message and then dies.

I've not been able to find any examples or documentation on using this library with Apollo's latest subscription recommendations, which is to create a SubscriptionServer directly.

To Reproduce

Here's how I'm setting up the server. I'll try to find some time to create a sandbox for reproduction.

  // applyDirectives visits directives in the schema and implements them
  const schema = applyDirectives(schemaApplication.createSchemaForApollo());
  const subscribe = schemaApplication.createSubscription();
  const execute = schemaApplication.createExecution();

  const app = express();

  const httpServer = createServer(app);

  const server = new ApolloServer({
    schema,
    context: createContext,
    // allow introspection in non-prod environments
    introspection: APP_ENV !== 'production',
    plugins: [
      {
        async serverWillStart() {
          return {
            async drainServer() {
              subscriptionServer.close();
            },
          };
        },
      },
      ApolloServerPluginDrainHttpServer({ httpServer }),
    ],
  });

  const subscriptionServer = SubscriptionServer.create(
    {
      schema,
      execute,
      subscribe,
      onConnect: (arg1: any) => {
        console.log(`Connected`, arg1);
      },
      onDisconnect: (arg1: any) => {
        console.log('Disconnected', arg1);
      },
      onOperation: (arg1: any) => {
        console.log('Operation', arg1);
      },
    },
    {
      server: httpServer,
      path: server.graphqlPath
    },
  );

  await server.start();

  server.applyMiddleware({
    app,
  });

  httpServer.listen(PORT, () => {
    console.log(
      `🚀 Server ready at http://localhost:${PORT}${server.graphqlPath}`,
    );
  });

Expected behavior

I expect the Subscription client to connect via websocket and receive an ack, then maintain the connection.

I also expect the console logs to be invoked from my SubscriptionServer (they're not)

Environment:

  • OS: MacOS 11.5.2
  • @graphql-modules/1.4.4:
  • NodeJS: 16.6.2

Additional context

The Apollo subscriptions example seems to use an API that's no longer part of their documentation in either v2 or v3.

@a-type
Copy link
Author

a-type commented Sep 28, 2021

Apologies for my misunderstanding here, we tried rolling back the inclusion of this library and found similar problems existed. I do think some more documentation on usage with subscriptions and modern Apollo would be nice, but the problem itself seems to lie elsewhere. Feel free to close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant