Skip to content
This repository was archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
Flow to ts (#877)
Browse files Browse the repository at this point in the history
* change type name to match ts

* update version

* back compat types

* update signature for classes and include a test
  • Loading branch information
James Baxley authored Jul 21, 2017
1 parent 71c47b8 commit 14121ea
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

### vNext

### 1.4.8
- Fix: Ensure typescript and flow type definitions match in name

### 1.4.7
- Feature: Add support for flow typecheck to work out of the box (without any configuration)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-apollo",
"version": "1.4.7",
"version": "1.4.8",
"description": "React data container for Apollo Client",
"main": "lib/react-apollo.umd.js",
"module": "./lib/index.js",
Expand Down
13 changes: 8 additions & 5 deletions src/index.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@ export type MutationFunc<TResult> = (
opts: MutationOpts
) => Promise<ApolloQueryResult<TResult>>;

export type DefaultChildProps<P, R> = {
export type ChildProps<P, R> = {
data: QueryProps & R,
mutate: MutationFunc<R>
} & P;

// back compat
export type DefaultChildProps<P, R> = ChildProps<P, R>

export interface MutationOpts {
variables?: Object,
optimisticResponse?: Object,
Expand Down Expand Up @@ -83,8 +86,8 @@ export interface QueryProps {

export interface OptionProps<TProps, TResult> {
ownProps: TProps,
data?: QueryProps & TResult,
mutate?: MutationFunc<TResult>
data: QueryProps & TResult,
mutate: MutationFunc<TResult>
}

export type OptionDescription<P> = (props: P) => QueryOpts | MutationOpts;
Expand All @@ -102,12 +105,12 @@ export interface OperationOption<TProps: {}, TResult: {}> {
export interface OperationComponent<
TResult: Object = {},
TOwnProps: Object = {},
TMergedProps = DefaultChildProps<TOwnProps, TResult>
TMergedProps = ChildProps<TOwnProps, TResult>
> {
(
component:
| StatelessComponent<TMergedProps>
| React$Component<void, TMergedProps, void>
| Class<React$Component<void, TMergedProps, void>>
): Class<React$Component<void, TOwnProps, void>>
}

Expand Down
14 changes: 13 additions & 1 deletion test/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
*/

// @flow
import { Component } from "react";
import { graphql } from "../src";
import type { OperationComponent, QueryProps } from "../src";
import type { OperationComponent, QueryProps, ChildProps } from "../src";
import gql from "graphql-tag";

const query = gql`
Expand Down Expand Up @@ -94,3 +95,14 @@ export default withCharacter(({ loading, hero, error }) => {
if (error) return <h1>ERROR</h1>;
return null;
});

export class Character extends Component {
render(){
const { loading, hero, error } = this.props;
if (loading) return <div>Loading</div>;
if (error) return <h1>ERROR</h1>;
return null// actual component with data;
}
}

const CharacterWithData = withCharacter(Character);

0 comments on commit 14121ea

Please sign in to comment.