Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

359
Visualizações
Why isn't Apollo Server a middleware for Express, rather than being a server that accepts Express as a middleware?

I'm just wondering what's the reason for this seemingly awkward configuration (from Getting Started w/ Apollo Server),

const server = new ApolloServer({
  // These will be defined for both new or existing servers
  typeDefs,
  resolvers,
});

server.applyMiddleware({ app }); // app is from an existing express app

Why is that I'm calling .applyMiddleware() and feeding it my app rather than using app.use(), it even seems from the docs that Apollo is only answering requests on /graphql wouldn't it be better to follow the Express API of,

let apollo = require('apollo-server').ApolloMiddleware
app.use( '/graphql', apollo({ typeDefs, resolvers }) );

It seems like Apollo is inverting the normal middleware flow of Express? What is the advantage of doing it the Apollo way?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I don't work with those guys, but based on the code that's there, I'm assuming it has to do with the fact that you add body parser, payload, websockets (if you opt for this) to the app, as well as a known configuration for engine health checks. The known would have to be at the root according to that specification. Also, if you use subscriptions and websockets, they listen httpServer.once('listening') , so they must have access to your application. If you were simply given one that you could mount, don't app.listen on it, since you app.listen it on your own.

Just from the inside, this is what I would expect, at least.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda