apollographql / react-apollo

:recycle: React integration for Apollo Client
https://www.apollographql.com/docs/react/
MIT License
6.85k stars 787 forks source link

ownContext in options.update #1379

Closed qthen closed 5 years ago

qthen commented 6 years ago

This is not a super serious issue and far from a feature request, but in using react-apollo, I have found the options property provided to graphql to be extremely useful.

Typically, for many options (like variables), logic is derived from props of the wrapped component, so it makes sense for ownProps to be made available to the callback function to options. However, I found that ownContext is not made available to the callback function. While this is not a major problem, I want to avoid a wrapper of a wrapper to make context available through a roundabout way and was wondering if there is anyway the this.context of a wrapped React component can be made available to graphl(query, options), specifically:

export default graphql(gql`mutation { ... }`, {
  options: (props, context) => ({
    // Options are computed from `props` here.
   // Context available
  }),
})(MyComponent);

A few examples I have run into where this is an issue is global variables like the currentUser which would be useful to have, especially on mutation.

danilobuerger commented 5 years ago

Feature requests and non-bug related discussions are no longer managed in this repo. Feature requests should be opened in https://github.com/apollographql/apollo-feature-requests.