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.

Custom GraphiQL middleware

See original GitHub issue

Hi 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:closed
  • Created 7 years ago
  • Reactions:20
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
lackercommented, Aug 25, 2016

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 like express-jwt or express-session.

1reaction
eugenehpcommented, Sep 12, 2016

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

IMO it would be nicer to explicitly support some number of common auth strategies, like setting a JWT token, or using http basic auth, and so on

What would be your ideal list of auth strategies here?

Read more comments on GitHub >

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

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