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

fix: the current Apollo docs causes an async error #1082

Closed
wants to merge 1 commit into from
Closed

fix: the current Apollo docs causes an async error #1082

wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented Aug 22, 2021

Closes #1078

Description

The current Apollo Docs for setting up a GraphQL project causes an async and await error.

throw new Error('You must `await server.start()` before calling `server.' +
            ^
Error: You must `await server.start()` before calling `server.applyMiddleware()`

The way I fixed this is by creating a main function where it is asynchronous and await when we call server.start()

const main = async () => {
  const app = express();
  await server.start();
  server.applyMiddleware({ app });

  app.listen({ port: 4000 }, () =>
    console.log("Now browse to http://localhost:4000" + server.graphqlPath)
  );
};

main();

Add also when you install all the dependencies there is also missing package graphql

- npm install apollo-server-express express 
+ npm install apollo-server-express express graphql

@linux-foundation-easycla
Copy link

CLA Not Signed

@ghost ghost changed the title fix: the current Apollo docs causes an async error #1078 fix: the current Apollo docs causes an async error Aug 22, 2021
@orta
Copy link
Member

orta commented Oct 27, 2021

Thanks, I've merged a PR which fixes this!

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

Successfully merging this pull request may close these issues.

Docs: Apollo Server example throws error
2 participants