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

Commit

Permalink
Flow exports (#919)
Browse files Browse the repository at this point in the history
* update typings

* version bump
  • Loading branch information
James Baxley authored Aug 1, 2017
1 parent 55a7b68 commit 795a9be
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 2,352 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.9
- Fix: fix matching types with exports for flow and ts

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

Expand Down
21 changes: 0 additions & 21 deletions examples/flow/.gitignore

This file was deleted.

2,138 changes: 0 additions & 2,138 deletions examples/flow/README.md

This file was deleted.

20 changes: 0 additions & 20 deletions examples/flow/package.json

This file was deleted.

Binary file removed examples/flow/public/favicon.ico
Binary file not shown.
40 changes: 0 additions & 40 deletions examples/flow/public/index.html

This file was deleted.

15 changes: 0 additions & 15 deletions examples/flow/public/manifest.json

This file was deleted.

56 changes: 0 additions & 56 deletions examples/flow/src/App.js

This file was deleted.

20 changes: 0 additions & 20 deletions examples/flow/src/index.js

This file was deleted.

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.8",
"version": "1.4.9",
"description": "React data container for Apollo Client",
"main": "lib/react-apollo.umd.js",
"module": "./lib/index.js",
Expand Down
77 changes: 45 additions & 32 deletions src/index.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -10,61 +10,68 @@ import type {
FetchMoreQueryOptions,
SubscribeToMoreOptions,
PureQueryOptions,
MutationUpdaterFn
} from "apollo-client";
import type { Store } from "redux";
import type { DocumentNode, VariableDefinitionNode } from "graphql";
MutationUpdaterFn,
} from 'apollo-client';
import type { Store } from 'redux';
import type { DocumentNode, VariableDefinitionNode } from 'graphql';

import type { Component } from "react";
import type { Component } from 'react';

import { compose } from 'redux';
import gql from 'graphql-tag';

// export everything from apollo-client
export * from 'apollo-client';
export { gql, compose };

declare type StatelessComponent<P> = (props: P) => ?React$Element<any>;

export interface ProviderProps {
store?: Store<any>,
client: ApolloClient
client: ApolloClient,
}

declare export class ApolloProvider extends React$Component {
props: ProviderProps,
childContextTypes: {
store: Store,
client: ApolloClient
client: ApolloClient,
},
contextTypes: {
store: Store
store: Store,
},
getChildContext(): {
store: Store,
client: ApolloClient
client: ApolloClient,
},
render(): React$Element<*>
render(): React$Element<*>,
}
export type MutationFunc<TResult> = (
opts: MutationOpts
opts: MutationOpts,
) => Promise<ApolloQueryResult<TResult>>;

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

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

export interface MutationOpts {
variables?: Object,
optimisticResponse?: Object,
updateQueries?: MutationQueryReducersMap<*>,
refetchQueries?: string[] | PureQueryOptions[],
update?: MutationUpdaterFn<*>
update?: MutationUpdaterFn<*>,
}

export interface QueryOpts {
ssr?: boolean,
variables?: Object,
fetchPolicy?: FetchPolicy,
pollInterval?: number,
skip?: boolean
skip?: boolean,
}

export interface QueryProps {
Expand All @@ -73,21 +80,21 @@ export interface QueryProps {
loading: boolean,
variables: Object,
fetchMore: (
fetchMoreOptions: FetchMoreQueryOptions & FetchMoreOptions
fetchMoreOptions: FetchMoreQueryOptions & FetchMoreOptions,
) => Promise<ApolloQueryResult<any>>,
refetch: (variables?: Object) => Promise<ApolloQueryResult<any>>,
startPolling: (pollInterval: number) => void,
stopPolling: () => void,
subscribeToMore: (options: SubscribeToMoreOptions) => () => void,
updateQuery: (
mapFn: (previousQueryResult: any, options: UpdateQueryOptions) => any
) => void
mapFn: (previousQueryResult: any, options: UpdateQueryOptions) => any,
) => void,
}

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

export type OptionDescription<P> = (props: P) => QueryOpts | MutationOpts;
Expand All @@ -99,49 +106,55 @@ export interface OperationOption<TProps: {}, TResult: {}> {
name?: string,
withRef?: boolean,
shouldResubscribe?: (props: TProps, nextProps: TProps) => boolean,
alias?: string
alias?: string,
}

export interface OperationComponent<
TResult: Object = {},
TOwnProps: Object = {},
TMergedProps = ChildProps<TOwnProps, TResult>
TMergedProps = ChildProps<TOwnProps, TResult>,
> {
(
component:
| StatelessComponent<TMergedProps>
| Class<React$Component<void, TMergedProps, void>>
): Class<React$Component<void, TOwnProps, void>>
| Class<React$Component<void, TMergedProps, void>>,
): Class<React$Component<void, TOwnProps, void>>,
}

declare export function graphql<TResult, TProps, TChildProps>(
document: DocumentNode,
operationOptions?: OperationOption<TProps, TResult>
operationOptions?: OperationOption<TProps, TResult>,
): OperationComponent<TResult, TProps, TChildProps>;

declare export function withApollo<TProps>(
component:
| StatelessComponent<TProps & ApolloClient>
| Class<React$Component<void, TProps & ApolloClient, void>>,
): Class<React$Component<void, TProps & ApolloClient, void>>;

export interface IDocumentDefinition {
type: DocumentType,
name: string,
variables: VariableDefinitionNode[]
variables: VariableDefinitionNode[],
}

declare export function parser(document: DocumentNode): IDocumentDefinition;

export interface Context {
client?: ApolloClient,
store?: Store,
[key: string]: any
[key: string]: any,
}

export interface QueryTreeArgument {
rootElement: React$Element<*>,
rootContext?: Context
rootContext?: Context,
}

export interface QueryResult {
query: Promise<ApolloQueryResult<mixed>>,
element: React$Element<*>,
context: Context
context: Context,
}

declare export function walkTree(
Expand All @@ -150,18 +163,18 @@ declare export function walkTree(
visitor: (
element: React$Element<*>,
instance: any,
context: Context
) => boolean | void
context: Context,
) => boolean | void,
): void;

declare export function getDataFromTree(
rootElement: React$Element<*>,
rootContext?: any,
fetchRoot?: boolean
fetchRoot?: boolean,
): Promise<void>;

declare export function renderToStringWithData(
component: React$Element<*>
component: React$Element<*>,
): Promise<string>;

declare export function cleanupApolloState(apolloState: any): void;
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './browser';

export { getDataFromTree, renderToStringWithData } from './server';
export * from './server';
Loading

0 comments on commit 795a9be

Please sign in to comment.