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

feat: expose express from ApolloServer #2124

Closed
wants to merge 7 commits into from

Conversation

playerx
Copy link

@playerx playerx commented Dec 21, 2018

There are lots of use cases when you need to have access to express, first quick example is just adding voyager (I do it for every project) and using apollo-server-express for this task isn't good solution because you need more manual work to do.

Exposing express from apollo-server will be super helpful and it will avoid need of having additional library, like graphql-yoga

P.S. I think its must have feature of apollo-server library

TODO:

  • Update CHANGELOG.md with your change (include reference to issue & this PR)
  • Make sure all of the significant new logic is covered by tests
  • Rebase your changes on master so that they can be merged easily
  • Make sure all tests and linter rules pass

There are lots of use cases when you need to have access to express, first quick example is just adding voyager (I do it for every project) and using apollo-server-express for this task isn't good solution because you need more manual work to do.

Exposing express from apollo-server will be super helpful and it will avoid need of having additional library, like graphql-yoga

P.S. I think its must have feature of apollo-server library
@playerx playerx changed the title chore: expose express from ApolloServer feat: expose express from ApolloServer Dec 21, 2018
@abernix
Copy link
Member

abernix commented Jul 5, 2019

Thanks for opening this originally, but we're not going to be able accept this PR.

The apollo-server package itself is intended as a quick getting started package, but uses currently uses apollo-server-express under the hood. In the future, that could be any integration, and we may try to make it even more simplistic and avoid the more heavy cost of including express, since most functionality can be provided via a simple (req, res) pattern, which is supported natively by Node.js and similarly by, say, the Fetch API. For that reason, exposing the app (which does happen to be Express right now), is not something we're going to do.

That said, if one wants to use Express directly, they can and should! We provide apollo-server-express, which again apollo-server uses internally, which can be either passed an app:

const app = require('express')();

const server = new ApolloServer({
  /* full configuration not included here */
});
server.applyMiddleware({
  app: app,
});

But new, as of Apollo Server 2.7.0 (tracked in #2937), we now expose a getMiddleware method (from #2435) for Express and Koa integrations which provides the composed middleware for it to be used directly, rather than applying it directly to the app with applyMiddleware:

const app = require('express')();

const server = new ApolloServer({
  /* full configuration not included here */
});
app.use(server.getMiddleware());

Either way, you shouldn't need graphql-yoga. Thanks!

@abernix abernix closed this Jul 5, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 22, 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

Successfully merging this pull request may close these issues.

2 participants