[SOLVED] Apollo Server 3 and Meteor - connect support dropped

Hi all,

Has anyone here successfully updated to using Apollo 3 server within their Meteor environment?

I currently create an instance of an Apollo Server and add it to Meteor’s connect web server using by doing this:

import {
  ApolloServer,
} from "apollo-server-express";

...

const server = new ApolloServer({

...

server.applyMiddleware({
  app: WebApp.connectHandlers,
  path: "/graphql",
});

However, Apollo 3 has dropped official support for connect, and now only supports express:

In Apollo Server 3, we no longer guarantee future support for connect. We do still run a test suite against it and we will try not to *unintentionally* break functionality underconnect, but if future changes are easier to implement in an Express-only fashion, we reserve the right to breakconnect compatibility within Apollo Server 3.

(Source: Migrating to Apollo Server 3 - Apollo Server - Apollo GraphQL Docs)

While it sounds like it should work, it doesn’t since apollo-server-express now tries to import ‘express’, and Meteor fails to launch since it can’t find this import.

Now, I realise that I could perhaps add this package, but including the whole of express when it’s not actually going to be used is really annoying.

Creating and maintaining a connect integration is even worse.

Does anyone here have any bright ideas to solve this nicely?

Note: the only reason that apollo-server-express imports express is to get the types.

1 Like

Have anyone managed to do this? I’m going to use apollo server but I’m stuck at apollo-server-express version 2.25.3

Oh I read this post again and problem was solved already: Apollo 3, Meteor and “Cannot await without a Fiber” - #6 by Storyteller - Help - Apollo GraphQL
Thank you @storyteller

Version 2:

const resolvers = {
  Query: {
    getLink: (obj, { id }) => LinksCollection.findOne(id),
    getLinks: () => LinksCollection.find().fetch(),
  },
};

const server = new ApolloServer({
  typeDefs,
  resolvers,
  context: async ({ req }) => ({
    user: await getUser(req.headers.authorization),
  }),
});

server.applyMiddleware({
  app: WebApp.connectHandlers,
  cors: true,
});

Version 3:

  • add async to all resolvers queries
  • add server.start() function
const resolvers = {
  Query: {
    getLink: async (obj, { id }) => LinksCollection.findOne(id),
    getLinks: async () => LinksCollection.find().fetch(),
  },
};

const server = new ApolloServer({
  typeDefs,
  resolvers,
  context: async ({ req }) => ({
    user: await getUser(req.headers.authorization),
  }),
});
server.start().then(() => {
  server.applyMiddleware({
    app: WebApp.connectHandlers,
    cors: true,
  });
});