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

Allow defaultResolveFn to call methods on classes and bind source as "this" #367

Closed
dimitri-koenig opened this issue Jul 28, 2017 · 1 comment

Comments

@dimitri-koenig
Copy link
Contributor

I have an issue with classes being compiled back to es5 using babel, where I have the default resolver call a method without having the source being bound to it.

E.x.:

class FooBar {
  get myFirstProperty() {
    return 'this works';
  }
  get mySecondProperty() {
    return this.someOtherProperty + ' works too';
  }
  myMethod({param1, param2}) {
    return this.someOtherProperty + ' somehow does not work because calling "someOtherProperty" on undefined';
  }
}

I found the issue in the implementation of "defaultResolveFn" where the "method" is called directly:

    const property = source[fieldName];
    if (typeof property === 'function') {
      return property(args, context);
    }

A change to this and everything works fine:

    const property = source[fieldName];
    if (typeof property === 'function') {
      return property.apply(source, [args, context]);
    }

I also tried to write a test for it but somehow with typescript it works without this change.

Is this an implementation issue, which could be fixed through this referenced PR or something else?

Thx
Best
Dimitri

@dimitri-koenig
Copy link
Contributor Author

Should be fixed with this PR: graphql/graphql-js#980

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant