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

[react-apollo] Misc. react-apollo improvements #2180

Merged

Conversation

budde377
Copy link
Contributor

@budde377 budde377 commented May 7, 2018

Closes #2175

This enables us to annoate subscribeToMore with the following method

...
import { Query, type QueryRenderProps, type SubscribeToMoreOptions } from 'react-apollo'
 
class DoStuff extends React.Component<{}> {
  _subscribeToMoreOptions: SubscribeToMoreOptions<getThangsQuery, subscribeThangsSubscription> = {
    document: SUBSCRIBE_THANGS,
    updateQuery: (prev, {subscriptionData}) => {
      if (!subscriptionData.data) return prev
      ...
    }
  }

  render () {
    return (
      <Query query={GET_THANGS}>
        {({subscribeToMore, loading, error, data}: QueryRenderProps<getThangsQuery>) => {          
          ...
          subscribeToMore(this._subscribeToMoreOptions)           
          ...
        }}
      </Query>
    )
  }
}
...

similar functionality has been added for fetchMore.

@budde377 budde377 force-pushed the feat-improve-react-apollo branch from 963d1ba to 6fd326e Compare May 7, 2018 16:30
UpdateQueryOptions,
FetchMoreQueryOptions,
SubscribeToMoreOptions,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming you're already aware of this, but just to be sure, all of these imports from apollo-client are just resolving to any (both because this import is outside of declare module and because a definition doesn't currently exist).

Started on a PR to add a definition for apollo-client: #2172

Copy link
Contributor Author

@budde377 budde377 May 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did know that they resolved to any, but I wasn't aware that they had to be in declare module. It'll be interesting to see how much we can reuse when your PR is done!

Copy link
Contributor

@TLadd TLadd May 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FAQ for reference: https://github.com/flowtype/flow-typed/wiki/FAQs#how-do-i-build-type-definitions-that-depend-on-other-definitions.

Appreciate your improvements to the libdef by the way!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the link!

@budde377 budde377 force-pushed the feat-improve-react-apollo branch from 6fd326e to 5f1e5cb Compare May 7, 2018 16:52
@budde377 budde377 changed the title [wip][react-apollo] Misc. react-apollo improvements [react-apollo] Misc. react-apollo improvements May 7, 2018
client: ApolloClient
}

declare export type QueryRenderPropFunction<TData, TVariables> = (QueryRenderProps<TData, TVariables>) => React$Node

declare export class Query<TData, TVariables> extends React$Component<{
declare export class Query<TData, TVariables, TSubscriptionData, TSubscriptionVariables> extends React$Component<{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to add defaults for these?

At the moment, I'm extending the Query component and passing in the types, similar to how the apollo typescript docs suggest (https://www.apollographql.com/docs/react/recipes/static-typing.html#typing-components). This change would require going back and adding void, void for each of my Query components.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually adding these was a mistake and they aren't used. I chose not to propagate these type variables because their usability is doubtable. The Query component doesn't "care" about those types, and that is also why the QueryRenderProps doesn't have them.

@budde377 budde377 force-pushed the feat-improve-react-apollo branch from 5f1e5cb to 2f9d63b Compare May 7, 2018 18:15
@AndrewSouthpaw
Copy link
Contributor

I'll wait for @TLadd to sign off.

As part of this PR would you mind adding a CONTRIBUTING.md file in the apollo folder and recording any common reviewers? It's helpful to future contributors.

Copy link
Contributor

@AndrewSouthpaw AndrewSouthpaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waiting on approval.

@budde377
Copy link
Contributor Author

budde377 commented May 8, 2018

I've added the CONTRIBUTING.md file with all contributors to the main spec.

@budde377 budde377 force-pushed the feat-improve-react-apollo branch from 898c43a to a858187 Compare May 8, 2018 10:38
@budde377 budde377 force-pushed the feat-improve-react-apollo branch from a858187 to f77395a Compare May 8, 2018 10:47
@TLadd
Copy link
Contributor

TLadd commented May 8, 2018

@AndrewSouthpaw Looks good to me

@AndrewSouthpaw AndrewSouthpaw merged commit 25d2597 into flow-typed:master May 8, 2018
@mlc
Copy link
Contributor

mlc commented May 9, 2018

This appears to make flow unhappy:

$ flow status
Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ flow-typed/npm/react-apollo_v2.x.x.js:280:68

Cannot use SubscriptionProps [1] with less than 2 type arguments.

 [1] 273│   declare type SubscriptionProps<TData, TVariables> = {
     274│     subscription: DocumentNode,
     275│     variables?: TVariables,
     276│     shouldResubscribe?: boolean | (SubscriptionProps<TData, TVariables>, SubscriptionProps<TData, TVariables>) => boolean,
     277│     children: (result: SubscriptionResult<TData, TVariables>) => React$Node,
     278│   }
     279│
     280│   declare export class Subscription<TData> extends React$Component<SubscriptionProps<TData>> {}
     281│
     282│   declare export type MutationFunction<TVariables> = (options: {
     283│     variables?: TVariables,

@budde377
Copy link
Contributor Author

budde377 commented May 9, 2018

@mic, can you check if #2194 fixes it?

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

Successfully merging this pull request may close these issues.

None yet

4 participants