-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Do not serialize body values that aren't objects (like FormData) #1316
Do not serialize body values that aren't objects (like FormData) #1316
Conversation
@uosl: 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/ |
I don't think this will work, because a I'd like to avoid a dependency on What is it you're trying to do here exactly? What kind of request body does your server need? If you only require |
It should work. I tested this in the Node REPL. (I also commited a test for it)
The constructor property returns a reference to the function (or ES6 class) that was used to create the instance. Maybe you're thinking of the Our server expects a form-data as the request body, ie. one created like |
Ah, you're absolutely right, I completely missed that. I was indeed thinking of I still want to serialize objects that have a |
The code to detect objects was malformed due to not detecting objects with direct constructors other than `Object`. It was implemented to prevent multipart data to be serialized. This should be prevented by detecting the multipart header and not the object type. This adds another safe guard to skip objects that might not be serializable in the first place. Refs: apollographql#1316 Refs: apollographql#2707 Fixes: https://github.com/apollographql/apollo-server/issues/1539
This approach has caused multiple issues due to ignoring objects with a null prototype. This is done in here and many people complained about the result. The solution would be to check for the header. No multipart header should be stringified and that way it's possible to distinguish these easily. I opened #5070 to fix that. @uosl the solution there is to detect the content-type and to set that up front. That should accommodate your use case, right? |
The code to detect objects was malformed due to not detecting objects with direct constructors other than `Object`. It was implemented to prevent multipart data to be serialized. This should be prevented by detecting the multipart header and not the object type. This adds another safe guard to skip objects that might not be serializable in the first place. Refs: apollographql#1316 Refs: apollographql#2707 Fixes: https://github.com/apollographql/apollo-server/issues/1539
@BridgeAR I apologise for the anguish my change may have caused. My use case doesn't exist anymore as I no longer maintain the code using it, and it's likely been changed since. Please feel free to work out a better approach! Checking the content-type header definitely sounds like a better solution. |
Would love some feedback on this. Not sure if my solution is optimal as I'm not that familiar with this.
When using RESTDataSource while setting up apollo-server and learning GraphQL, I had trouble getting my POST requests to work. Looking through the sources, I saw that the fetch method in RESTDataSource was running JSON.stringify on my FormData, causing our backend server to reject them.
I don't think this should be by design? I saw that there was coded in an exception for ArrayBuffer, but to add FormData would perhaps require pulling in the
form-data
dependency, which isn't very practical. So I thought we might as well only serialize body values that are javascript objects. (constructor === Object
) Does this make sense?