Apollo v3 GraphQL Subscription Error: Must provide document

Viewed 328

I'm testing out subscription on Apollo v3 using the example setup on the docs. But I get the above error. I'm not sure what I'm missing.

Here's the complete reproducible code on Github gist


const typeDefs = gql`
  type Subscription {
    incremented: Int
  }
`;

const resolvers = {
  Subscription: {
    incremented: {
      subscribe: () => pubsub.asyncIterator('NUMINCREMENTED'),
    },
  },
};

(async function () {
  const schema = makeExecutableSchema({
    typeDefs,
    resolvers,
  });

  const subscriptionServer = SubscriptionServer.create(
    {
      schema,
      execute,
      subscribe,
    },
    { server: httpServer }
  );

  const server = new ApolloServer({
    schema,
    plugins: [
      {
        async serverWillStart() {
          return {
            async drainServer() {
              subscriptionServer.close();
            },
          };
        },
      },
    ],
  });
})();

Here's the error when I try the subscription on Apollo Studio.

enter image description here

1 Answers

I had the same problem. Downgrade apollo-server-express to 3.1.2.

Then everything should work.

Related