-
Notifications
You must be signed in to change notification settings - Fork 537
Express example misuses promises #757
Comments
I noticed the same thing. Did a little bit of digging and I found this:
https://expressjs.com/en/guide/writing-middleware.html While it doesn't say so explicitly, I think the idea is that if a middleware function returns a promise that resolves rather than rejects, it's equivalent to calling Line 189 in 28e4c29
So, it looks like express-graphql is designed for this new behavior in Express 5, while I'm still on Express 4 (as are you, I'm guessing). Perhaps they can release two separate versions for use with Express 4 and 5. In the meantime, you could wrap it and call
but that feels kind of clunky so perhaps it's easier to just suppress the eslint warning |
Thinking about this a little more, I don't really understand why this package is designed to be used as middleware rather than as a handler. |
Just pointing out that the handler itself doesn't need to app.use("/graphql", (req, res, next) => {
graphqlHTTP({
schema,
rootValue,
})(req, res).catch(next);
}); |
I have a project which follows the "Simple Setup" example given in this project's README: https://github.com/mastertinner/graphql-jsonplaceholder/blob/master/src/index.ts#L19
I have configured eslint to run the recommended TypeScript linting rues. The code throws a linting error because the
graphqlHTTP
function returns a promise which is not expected by express at that point because they are expected to returnvoid
as can be seen here:Is this expected or am I doing something wrong? Do we need to update the TypeScript definitons respectively?
The text was updated successfully, but these errors were encountered: