-
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
defaultFieldResolver should bind source #980
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed. If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
src/execution/execute.js
Outdated
@@ -1247,7 +1247,8 @@ function (source, args, context, info) { | |||
if (typeof source === 'object' || typeof source === 'function') { | |||
const property = source[info.fieldName]; | |||
if (typeof property === 'function') { | |||
return source[info.fieldName](args, context, info); | |||
/* eslint-disable no-useless-call */ | |||
return source[info.fieldName].apply(source, [ args, context, info ]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function#call is usually faster than Function#apply, and since you're not passing varargs here, it'd probably be better to go:
return source[info.fieldName].call(source, args, context, info);
Fair enough, there we go with call instead of apply |
@papandreou Any more changes needed or is this PR ready to be merged? |
@dimitri-koenig, I'm not in charge here, so I don't know :) |
Thanks for your patience - could you please add unit tests for this? I think this was always the intent, and was assuming that the Adding a test for this may help either confirm that the existing code does this, or if it failed with the existing code that this solution is the right fix. Either way, the test would be really valuable. |
I found the real issue, though I don't have an explanation for it: In graphql-tools the same code is being used though an old version, where the call of the class method is being made like this: return property(args, context); Changing this to the code used right now works: return source[info.fieldName](args, context, info); So no need to change anything. |
PR for this issue: defaultFieldResolver should bind source #979