Skip to content
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

Restify: Fix for calling next() #285

Merged
merged 2 commits into from
Jan 28, 2017
Merged

Conversation

jadkap
Copy link
Contributor

@jadkap jadkap commented Jan 26, 2017

Follow up to #189

  • Added next() calls and type annotation for restify.Next. In order for restify’s "after" event to fire (like triggering a call to auditLogger), next() needs to be called after sending a response. From http://restify.com/#routing: "Note the use of next(). You are responsible for calling next() in order to run the next handler in the chain."

  • I also discovered something with Restify’s bodyParser that results in an inconsistent response in a particular scenario vs. Koa and Express (didn’t check Hapi). Restify’s bodyParser returns undefined (vs. Express & Koa returning {}) if body parser is used but no request body is sent. This test https://github.com/apollostack/graphql-server/blob/master/packages/graphql-server-integration-testsuite/src/index.ts#L212-L221) passes because it’s not specifying any body parser, so all server variants return undefined. What’s happening is that in the case of Restify, if you use bodyParser, but don't send body, GraphQL is responding with 500 ‘POST body missing. Did you forget use body-parser middleware?’ whereas the same scenario in Koa and Express variants return 400 "Cannot read property 'definitions' of undefined" in nested error response. I started fixing it in the graphql restify code, but then that breaks the above test for Restify. Workaround is to either add validation middleware before calling graphqlRestify() or add a server.pre() handler to convert the body to {} if it’s undefined and content-type is application/json.

@apollo-cla
Copy link

@jadkap: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Meteor Contributor Agreement here: https://contribute.meteor.com/

@jadkap jadkap changed the title Add next() calls Restify: Fix for calling next() Jan 26, 2017
@joelgriffith
Copy link

Good catch on the omission of the post body... I'll have to stew on that one.

The next stuff looks good, probably good to merge

@DxCx
Copy link
Contributor

DxCx commented Jan 28, 2017

Thanks!

@DxCx DxCx merged commit dff367a into apollographql:master Jan 28, 2017
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants