-
-
Notifications
You must be signed in to change notification settings - Fork 568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fastify plugins integration #1220
Comments
Just a fyi: We switched back to |
Hi |
Hi @benjie |
Our fastify tests are working with basically this: const { postgraphile } = require('postgraphile');
const fastify = require('fastify');
const middleware = postgraphile(...);
const app = fastify(...);
app.use(middleware);
app.listen(3000); Would you like to set up a more complex example (e.g. with plugins, other middleware, etc) and see if it works? Instructions on how to install a pre-merged PR here: #1361 (comment) It'd be really good to get some more confirmation. |
Standing to fastify docs middlewares in v3 will need an additional plugin to work. I'll test my project with #1361 as soon as possible (hopefully by the end of the week) |
Ah; if middlewares are no longer supported, #1361 also adds a broken down version; I'll have a go at getting that working. Apparently our tests are still on fastify v2! Thanks for the heads up. |
@benjie |
Interesting; I think a Not sure if it helps regarding your issue, but I've created a Fastify v3 adaptor that's working with our tests; but setup for it is a little verbose; see this comment: #1361 (comment) I was considering adding a helper function that does all that boilerplate, so you can basically do something like: const { postgraphile } = require('postgraphile');
const fastify = require('fastify');
const middleware = postgraphile(...);
const app = fastify();
middleware.addToFastify(app);
app.listen(3000); As you can see from the code in the comment above it's pretty much all boilerplate, so abstracting it should be straightforward. However, doing this wouldn't give quite the same flexibility, especially when it comes to installing route handlers under a subpath, so I'm not really sure if it's the right direction. |
The tests now enable compression middleware on express and fastify3 and all the tests still pass; so this specific issue will be closed when that PR is merged 🙌 |
@benjie |
Of course I don't mind! Writing a Fastify-v3 specific plugin seems out of scope of PostGraphile's server so it definitely makes sense to keep separately, I'm just thinking your plugin could wrap the new methods I'm adding to PostGraphile so it makes it easier for you to maintain 👍 |
That's perfect. |
I'm submitting a ...
PostGraphile version: latest
Hi!
This was triggered by: #789 (comment)
Fastify uses a plugin system for registering plugins like fastify-compress or fastify-helmet.
Also there is a Express middleware compatible
use
integration.I mount Postgraphile as a middleware.
Some Fastify plugins seem to work with this setup (
fastify-helmet
) and some do not: for examplefastify-compress
.However - it is possible to achieve compression by use the (Express!)
compression
middleware.This was my testcase:
Hopefully I did everything correct here.
I would aplaude tighter coupling of Fastify (and plugin system) and Postgraphile.
From what I gather is that the Koa compression issues has been fixed my some Koa specific "hacks". Maybe this would suffice for Fastify, too? Or - should just Express middleware used with the Fastify compat layer?
I can provide a PR with a failing test for the
fastify-compress
issue if desired.The text was updated successfully, but these errors were encountered: