Order in express middleware
See original GitHub issueHello,
I currently use apollo-server-express
with next.js
. I REALLY want to replace apollo-server
with graphql-yoga
but it does not work.
In graphql-yoga
, middlewares are triggered before endpoint and playground createHttpServer
next’s router is a catch all that returns 404 if there is no matching route. run
As next’s router is triggered before yoga’s endpoints, when I try to reach ‘/graphql’ I get 404.
With apollo-server-express
, I don’t have that problem because I have a way to order express middleware applyMiddleware
Could you change middleware order so that endpoint, playground are before middlewares ? Thanks
Here is my code with graphql-yoga :
import next from 'next';
import routes from 'next-routes';
import { GraphQLServer } from 'graphql-yoga';
import schema from './models/schema';
const nextApp = next();
const handler = routes()
.add('home', '/', 'Home')
.getRequestHandler(nextApp);
nextApp.prepare().then(() => {
const server = new GraphQLServer({ schema }).use(handler);
server.start({
endpoint: '/graphql',
playground: '/graphql',
getEndpoint: true
});
});
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:5
Top Results From Across the Web
Ordering of Express JS Middleware - Stack Overflow
All Express route handlers (whether app.use() , app.get() , app.post() or anything else) are checked for a route match in the order they...
Read more >Writing middleware for use in Express apps
The order of middleware loading is important: middleware functions that are loaded first are also executed first. If myLogger is loaded after the...
Read more >Complete Guide to Express Middleware - Reflectoring
Middleware in Express are functions that come into play after the server receives the request and before the response is sent to the...
Read more >Confused about middleware order in Express : r/node - Reddit
The order is first come first serve. You should also be careful with route parameters, for example with routes defined in order of...
Read more >Node.js / Express.js - middleware calls order - Dirask
The order is one of the most important things about middleware. The order in which they are written or included in the file...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@kevinya Wrap the next handler in a middleware that checks the request is not for the /graphql route.
Just adding this to the pool. Below, working example that combines
next
andgraphql-yoga
(along with some integration of Prisma’s newly-released PhotonJS)