I've heard that our Koa support is a bit iffy, and we currently have no-one maintaining it, so I'm proposing that we remove Koa support and instead recommend people use koa-connect or similar. Native Koa support would be better, but with no-one to maintain it, it's a burden.
If anyone wants to step up to maintain the native Koa support in PostGraphQL please do so soon! Otherwise v4 is the perfect time for us to deprecate Koa support such that we can remove it in v5.
Please weigh in below.
I've heard that our Koa support is a bit iffy
Are there open issues we can link here? I haven't come across problems yet
@alexFaunt perhaps you can chime in here?
When i tried it with Koa I had a few issues, but wrapping with koa-connect everything worked fine.
To be honest, I can't remember what went wrong, so it may have been me miss-using it, if I get a chance I can start from scratch again to see if I hit issues - time permitting though!
Either way the koa support that is currently in the lib doesn't interfere with koa-connect so no urgent reason to remove it
Can confirm that postgraphql does not work great with Koa (e.g. on error you get
Error: Can't set headers after they are sent.
); koa-connect seems to solve this.
Guess I hadn't managed to hit an unhandled error. Moved over to koa-connect
Note - we are using this with koa without issue -
https://github.com/fervorous/fervor/blob/master/src/server/server.js#L35
I wish I'd made a note of the error that had caused this.
im using koa withoout issue as well /shrug
I think I'll just denote koa support as experimental rather than remove it π
Koa marked as experimental - it won't be removed, but issues with it will not be treated with the same severity as issues in express/etc.
As a corp. sponsor and user of Koa V2 .. I'd say .. No. :) Although it doesn't have to have level 1 support I guess as long as there is someway to get it done .. maybe "we" could look at a koa-postgraphile module that does the wrapping .. seems like there are quite a few of those out there..
Will I just tried to hook this up to my new Koa V2 (this is V4.0.0-beta.10 .. and .. it doesn't actually work at all for me .. even with c2k .. it just sits and hangs and eventually times out (in GraphiQL desktop app anyway) with a socket hangup ..
I tried without app.use(c2k(xxx)) and with it -- no difference .. :(
Oh c2k == koa-connect .. I guess it's back to express ..
Iβll take a look at this tomorrow; I was under the impression that it mostly worked but that error handling was the issue.
I did start looking into this; more to come hopefully Friday.
@benjie -- No worries. I got an express version up and running for now. Long term I'd like to figure out the Koa side because it is what we standardized on when we can (which so far hasn't been an issue) -- but I haven't exactly dived very deep into the issue either ..
So I think the reason is that the express body parser and the koa body parser don't work well together - the koa one consumes the body but the express one doesn't check for that and tries to decode it again, resulting in a hang.
So basically, it works for people who don't add bodyParser middleware before PostGraphile, and doesn't (always) work for those that do.
This should fix it: https://github.com/graphile/postgraphile/pull/780
Awesome1 Do I still need to use the koa-connect middleware to get this to work (I am assuming yes since the call sig for a Express & Koa middleware are quite different) ??
Theoretically no. I definitely want it to work without that. It works for me without it, but I've barely tested it - I'll be releasing a demo project soon showing usage.
I'll give it a try probably this afternoon (EDT) as well but the above is awesome -- 1st class Koa citizen! :)
Oh and yes, I was for sure using the Koa body parser ahead of postgraphile since we have other routes we need to handle too .. So very interesting!
You'll have to build from source, I've not released it yet π
(But I'd really appreciate you testing it; that would be awesome - thanks! Also if you want to add an automated test for it so we don't get regressions that would be awesome too - we don't have many (any?) koa tests currently.)
Have added a few more fixes; now no more headers warnings (that's what I was getting when I used PostGraphile with Koa) and also the server-sent events now work so schema watching in GraphiQL is live in the Koa version too π
https://github.com/graphile/postgraphile/pull/780
https://github.com/graphile/postgraphile/pull/781
https://github.com/graphile/postgraphile/pull/782
I'm still deeming Koa support experimental; but it's suddenly a lot lot better π
Woohoo! As soon as I can pull a version with this in it (rc2?) I will give it a whirl. And yes, I think a set of Koa tests would be a fine idea. I'll pop it on my to do list for myself or my team ..
It'll be in RC2, yeah. There's lots more stuff required in RC2 though, so it'll probably not be until next week or maybe the week after π
I'm finding GraphiQL static assets hanging with koa, but very intermittently. When I use koa-graphiql as a replacement all is good, but it doesn't load schema docs generated by PostGraphile. Everything else (main /graphql endpoint) is working well. Maybe the fixes that were applied didn't touch GraphiQL parts at all?
Are you able to figure out how to reproduce it? I think itβs an issue with send interacting with Koa. GraphiQL assets serving is changing soon anyway, so this might go away...
it's stably reproducible for me, I just set PostGraphile middleware on /graphiql path and open it in Safari. Most of the time it hangs (just blank page and loading progress never ends), although when I hit "refresh" when it's hanging it loads ok.
Any idea what resource is hanging? Is it the graphiql endpoint itself or the css/js? If you can reliably reproduce it then digging further in devtools would be great.
Are you using any koa middlewares before postgraphile? Does removing them solve/reduce the issue?
Basically every second load of /graphiql in any browser stalls for me. Literally I'm going to /graphiql and it loads, I reload it and it stalls, I reload it again and it loads again.
Removing all other middleware doesn't make any difference. I'm on "koa": "^2.5.3" and "postgraphile": "^4.0.1". Devtools screenshots attached.
Stalled one:

Every second one is loading well:

Cool; so it's definitely the resources. I think it's an interaction with send. I've already got a branch locally that removes send so I think this'll be fixed in 4.1.0 π