Custom GraphiQL middleware
See original GitHub issueHi Lee,
I just finished draft version of GraphiQL that supports HTTP headers. I know there are multiple discussions about keeping the original GraphiQL version lean and protocol independent, which makes sense to me.
So the question is what’s the best way to structure the middle ware here, so we can specify our own custom versions.
At the moment I’m using non flexible solution:
graphQLServer.use('/graphiql', express.static('graphiql'));
But I would want to see something like this possible:
import graphiql from 'graphiql-headers';
app.use('/graphql', graphqlHTTP(request => ({
schema: MySessionAwareGraphQLSchema,
context: request.session,
graphiql: graphiql
})));
What would be accepted as PR?
Thanks for your time on this.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:20
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Integrating with Node.js middleware - Apollo GraphQL Docs
When integrating with middleware, first you initialize Apollo Server just like you always do, and then you call applyMiddleware . Here's a basic...
Read more >Middleware in GraphQL Apollo Server | by E.Y. - Medium
A stand-alone GraphQL server, including in a serverless environment; An add-on to your application's existing Node.js middleware (such as ...
Read more >How to write GraphQL middleware (Node, Apollo Server ...
Now you are ready to write your own custom middleware. Have fun! P.S. Interested how to write integration tests using Jest for this...
Read more >graphql-middleware - npm
GraphQL Middleware is a schema wrapper which allows you to manage additional functionality across multiple resolvers efficiently.
Read more >Authentication and Express Middleware - GraphQL
In particular, this is a great pattern for handling authentication. To use middleware with a GraphQL resolver, just use the middleware like you...
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
What’s wrong with just mounting it on a different URL like your example of
graphQLServer.use('/graphiql', express.static('graphiql'));
?Although graphiql itself is generic, I don’t think that the version of graphiql that is exposed by express-graphql when you pass
graphql: true
has to be generic. I think it would make sense for that to include express-specific features, including some knowledge of the transport layer. And in particular doing something sane in conjunction with middleware likeexpress-jwt
orexpress-session
.@lacker that was just a draft to test out the idea. The design of GraphQL aims to keep it lean, and headers or authorisation strategies will make it even more complicated.
As some other developers suggested, it would be great to have that as a middleware on top of GraphQL.
What would be your ideal list of auth strategies here?