question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Proposal] Split into multiple middlewares

See original GitHub issue

Just 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.

Relative issue: #101 #102 #107

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:21
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
wincentcommented, Jan 25, 2017

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:

I think there’s clearly a demand for this (as evidenced by this issue, and #113 and #101). In essence, all of these are about the same thing: making express-graphql more extensible and reusable. The actual mechanism we use to do that needs to be decided (whether it be splitting it out into smaller libraries that can be recomposed, or creating a structure that makes it easy for other libraries to insert themselves in some way), but I think there’s value in the core, abstract idea independently of any implementation details.

We should centralize the discussion in a single place though, so I am going to close this issue and request that we concentrate further discussion in issue #113.

Let’s carry on from here.

3reactions
lackercommented, Aug 25, 2016

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 want app.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, and errorHandler?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found