[Proposal] Split into multiple middlewares
See original GitHub issueJust a idea, but I think we should embrace express middleware system.
Maybe something like below:
import { parser, validate, execute, errorHandler, graphiql } from 'express-graphql';
import logger from 'graphql-third-party-query-param-logger';
const app = express();
app.use('/graphql', parser(...));
app.use('/graphql', logger(...));
app.use('/graphql', validate(...));
app.use('/graphql', execute(...));
app.use('/graphql', errorHander(...));
app.use('/graphql', graphiql(...));
app.listen(3000);
And then we can use middlewares at any points to log and measure performance, even have more control on input, output and errors.
Eventually, more reasonable, extendable middlewares will born and enrich the whole graphql ecosystem.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:21
- Comments:14 (5 by maintainers)
Top Results From Across the Web
expressjs write multiple middleware and import it to the main file
I am learning express and got stuck here :) it's generally not a good idea to have multiple middleware in a file. Create...
Read more >A Middleware Framework for Supporting Application Use of ...
propose to build and demonstrate a layer of middleware capable of bringing the benefits of active networks to applications that are not active-network ......
Read more >Proposal: Creator Contests - a Nounish Funding Middleware
How does it work? ; Submitter Rewards. Define 1 or more winning ranks (1st, 2nd, … nth place); Define 1 or more rewards...
Read more >Proposal: Asynchronous Ring with Continuations
The same middleware can transparently have synchronous and asynchronous versions. Middleware and handlers can be programmatically upgraded to have a two-arity ...
Read more >PSR-15 compatibility issues and proposal - Contributors
That package was then split into two, http-interop/http-server-handler and http-interop/http-server-middleware; the two combined provide the ...
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
FYI, just closed a couple of other related issues in the interests of centralizing the discussion here. For context, this is the comment I made on #178:
Let’s carry on from here.
I think something like this could be useful. What are the important use cases here?
For performance logging it does seem useful to be able to insert some middleware after the query is parsed, but before it is executed. You might also want to do things like rejecting a query that was too complicated at the same point.
It does seem like it is useful to mount graphiql separately but that doesn’t seem like it should work like
app.use('/graphql', graphiql(...));
- it seems more like you would wantapp.use('/graphql/graphiql', graphiql(...));
but then I don’t really see how separating out the middleware buys you anything over just mounting graphiql on a different URL.What is the benefit of separating
validate
,execute
, anderrorHandler
?