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

Commit

Permalink
increased strictness of types (#695)
Browse files Browse the repository at this point in the history
* increased strictness of typescript types

* add mutation to default child props

* lock ts version to greater than 2.3.0 and set state to be {}

* fix lint error

* lock jest to 19 for now

* added flow typings! TODO remove AC typings after they are tested and merged

* more strict types for server code and a few flow tweaks

* support bundled flow types

* change options name to fix AC collision and add flow smoke test

* lock RN versions

* version bump uglify

* fix uglify command
  • Loading branch information
James Baxley authored May 30, 2017
1 parent 516f67b commit 7cc8d22
Show file tree
Hide file tree
Showing 12 changed files with 359 additions and 84 deletions.
12 changes: 12 additions & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[ignore]
.*/examples/**/.*
.*/node_modules/art/.*
.*/node_modules/react-native/**/.*

[include]

[libs]
./index.js.flow

[options]
suppress_comment= \\(.\\|\n\\)*\\$ExpectError
8 changes: 6 additions & 2 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# Change log

Expect active development and potentially significant breaking changes in the `0.x` track. We'll try to be diligent about releasing a `1.0` version in a timely fashion (ideally within 1 or 2 months), so that we can take advantage of SemVer to signify breaking changes from that point on.

### vNext

### 1.4.0
#### BREAKING FOR TYPESCRIPT USERS
- Feature: Enhanced typescript definitions to allow for more valid type checking of graphql HOC [PR #695](https://github.com/apollographql/react-apollo/pull/695)
- Feature: Flow types: [PR #695](https://github.com/apollographql/react-apollo/pull/695)


### 1.3.0
- Feature: Support tree shaking and smaller (marginally) bundles via rollup [PR #691](https://github.com/apollographql/react-apollo/pull/691)
- Fix: Render full markup on the server when using the `cache-and-network` fetchPolicy [PR #688](https://github.com/apollographql/react-apollo/pull/688)
Expand Down
165 changes: 165 additions & 0 deletions index.js.flow
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
import type {
ApolloClient,
MutationQueryReducersMap,
ApolloQueryResult,
ApolloError,
FetchPolicy,
FetchMoreOptions,
UpdateQueryOptions,
FetchMoreQueryOptions,
SubscribeToMoreOptions,
} from "apollo-client";
import type { Store } from "redux";
import type { DocumentNode, VariableDefinitionNode } from "graphql";

declare module "react-apollo" {
declare type StatelessComponent<P> = (props: P) => ?React$Element<any>;

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

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

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

declare export interface MutationOpts {
variables?: { [key: string]: mixed },
optimisticResponse?: Object,
updateQueries?: MutationQueryReducersMap,
}

declare export interface QueryOpts {
ssr?: boolean,
variables?: {
[key: string]: mixed,
},
fetchPolicy?: FetchPolicy,
pollInterval?: number,
skip?: boolean,
}

declare export interface QueryProps {
error?: ApolloError,
networkStatus: number,
loading: boolean,
variables: {
[variable: string]: any,
},
fetchMore: (
fetchMoreOptions: FetchMoreQueryOptions & FetchMoreOptions
) => Promise<ApolloQueryResult<any>>,
refetch: (variables?: any) => Promise<ApolloQueryResult<any>>,
startPolling: (pollInterval: number) => void,
stopPolling: () => void,
subscribeToMore: (options: SubscribeToMoreOptions) => () => void,
updateQuery: (
mapFn: (previousQueryResult: any, options: UpdateQueryOptions) => any
) => void,
}

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

declare export type OptionDescription<P> = (
props: P
) => QueryOpts | MutationOpts;

declare export interface OperationOption<TProps: {}, TResult: {}> {
options?: OptionDescription<TProps>,
props?: (props: OptionProps<TProps, TResult>) => any,
skip?: boolean | ((props: any) => boolean),
name?: string,
withRef?: boolean,
shouldResubscribe?: (props: TProps, nextProps: TProps) => boolean,
alias?: string,
}

declare export interface OperationComponent<
TResult: Object = {},
TOwnProps: Object = {},
TMergedProps = DefaultChildProps<TOwnProps, TResult>
> {
(
component:
| StatelessComponent<TMergedProps>
| React$Component<*, TMergedProps, *>
): React$Component<*, TOwnProps, *>,
}

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

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

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

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

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

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

declare export function walkTree(
element: React$Element<*>,
context: Context,
visitor: (
element: React$Element<*>,
instance: any,
context: Context
) => boolean | void
): void;

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

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

declare export function cleanupApolloState(apolloState: any): void;
}
22 changes: 12 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-apollo",
"version": "1.3.0",
"version": "1.4.0",
"description": "React data container for Apollo Client",
"main": "lib/react-apollo.umd.js",
"module": "./lib/index.js",
Expand All @@ -14,10 +14,11 @@
"test-watch": "jest --watch",
"posttest": "npm run lint",
"filesize": "npm run compile:browser && ./scripts/filesize.js --file=./dist/index.min.js --maxGzip=20",
"flow-check": "flow check",
"compile": "tsc",
"bundle": "rollup -c && rollup -c rollup.browser.config.js && rollup -c rollup.test-utils.config.js",
"bundle": "rollup -c && rollup -c rollup.browser.config.js && rollup -c rollup.test-utils.config.js && cp ./index.js.flow ./lib",
"compile:browser": "rm -rf ./dist && mkdir ./dist && browserify ./lib/react-apollo.browser.umd.js --i graphql-tag --i react --i apollo-client -o=./dist/index.js && npm run minify:browser && npm run compress:browser",
"minify:browser": "uglifyjs --compress --mangle --screw-ie8 -o=./dist/index.min.js -- ./dist/index.js",
"minify:browser": "uglifyjs -c -m -o ./dist/index.min.js -- ./dist/index.js",
"compress:browser": "./scripts/gzip.js --file=./dist/index.min.js",
"watch": "tsc -w",
"lint": "tslint 'src/*.ts*' && tslint 'test/*.ts*'"
Expand Down Expand Up @@ -54,9 +55,10 @@
"json"
],
"modulePathIgnorePatterns": [
"<rootDir>/examples"
"<rootDir>/examples",
"<rootDir>/test/flow.js"
],
"testRegex": "<rootDir>/test/.*.test.(ts|tsx|js)$",
"testRegex": "(/test/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"collectCoverage": true
},
"license": "MIT",
Expand Down Expand Up @@ -92,7 +94,7 @@
"@types/redux-form": "^6.3.2",
"@types/redux-immutable": "^3.0.30",
"@types/sinon": "^2.1.1",
"babel-jest": "^20.0.0",
"babel-jest": "^19.0.0",
"babel-preset-react-native": "^1.9.0",
"browserify": "^14.1.0",
"cheerio": "^0.22.0",
Expand All @@ -103,7 +105,7 @@
"graphql": "^0.9.1",
"immutable": "^3.8.1",
"isomorphic-fetch": "^2.2.1",
"jest": "^20.0.0",
"jest": "^19.0.0",
"jest-react-native": "^18.0.0",
"jsdom": "^11.0.0",
"lodash": "^4.16.6",
Expand All @@ -114,7 +116,7 @@
"react": "^15.5.4",
"react-addons-test-utils": "^15.5.1",
"react-dom": "^15.5.4",
"react-native": "^0.44.1",
"react-native": "^0.42.3",
"react-redux": "^5.0.3",
"react-test-renderer": "^15.5.4",
"recompose": "^0.23.0",
Expand All @@ -127,10 +129,10 @@
"swapi-graphql": "0.0.6",
"travis-weigh-in": "^1.0.2",
"tslint": "^5.1.0",
"typescript": "^2.2.0",
"typescript": "^2.3.0",
"typescript-require": "^0.2.9-1",
"typings": "^2.1.0",
"uglify-js": "^2.6.2"
"uglify-js": "^3.0.13"
},
"dependencies": {
"apollo-client": "^1.2.2",
Expand Down
11 changes: 10 additions & 1 deletion src/browser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
export { default as ApolloProvider } from './ApolloProvider';
export { default as graphql, InjectedGraphQLProps } from './graphql';
export {
default as graphql,
MutationOpts,
QueryOpts,
QueryProps,
MutationFunc,
OptionProps,
DefaultChildProps,
OperationOption,
} from './graphql';
export { withApollo } from './withApollo';

// expose easy way to join queries from redux
Expand Down
Loading

1 comment on commit 7cc8d22

@madhavajay
Copy link

Choose a reason for hiding this comment

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

nice!

Please sign in to comment.