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.

Add `graphql-middleware` support

See original GitHub issue

Add out of the box support for GraphQL Middleware plugins.

http://github.com/prismagraphql/graphql-middleware

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:19
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

14reactions
maticzavcommented, Sep 17, 2018

Hey @Alvyre 👋

Since we still haven’t implemented this, you could use the alternative approach we mentioned above. Instead of supplying resolvers and typeDefs to server directly you can provide a schema that you build upfront. Something like this;

const schema = makeExecutableSchema({ typeDefs, resolvers })

const schemaWithMiddleware = applyMiddleware(
  schema,
  metricsMiddleware,
  authMiddleware,
  beepMiddleware,
)

const server = new ApolloServer({
  mocks: false,
  schema: schemaWithMiddleware,,
});

You can find even more information about it in the link below. I hope this helps you solve the problem; I will try to make a PR by the end of the week 🤞

https://github.com/prisma/graphql-middleware#standalone-usage

8reactions
maticzavcommented, Sep 9, 2018

@notrab yeah, you can use it with makeExecutableSchema and then applyMiddleware like this;

const schema = makeExecutableSchema({ typeDefs, resolvers })

const schemaWithMiddleware = applyMiddleware(
  schema,
  metricsMiddleware,
  authMiddleware,
  beepMiddleware,
)

I believe it would be a lot more convenient though to have general support for it. I will try to make a PR in the coming days!

https://github.com/prisma/graphql-middleware#standalone-usage

Read more comments on GitHub >

github_iconTop Results From Across the Web

graphql-middleware - npm
GraphQL Middleware lets you run arbitrary code before or after a resolver is invoked. It improves your code structure by enabling code reuse...
Read more >
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 >
Authentication and Express Middleware - GraphQL
To use middleware with a GraphQL resolver, just use the middleware like you would with a normal Express app. The request object is...
Read more >
Treating GraphQL directives as middleware - LogRocket Blog
Being based in Express, graphql-yoga supports field resolver middleware out of the box, implemented through the graphql-middleware package.
Read more >
Use graphql-middleware for cross-cutting concerns | Medium
GraphQL best practices: Use graphql-middleware for cross-cutting concerns · Use a graphql logger middleware to delegate logging, avoid increased maintenance cost ...
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