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

Added prop-types validation to unchecked components. #1587

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### vNext

* Added `prop-types` validation to the `<Query />`, `<Subscription />` and `<ApolloConsumer />` component [#1587](https://github.com/apollographql/react-apollo/pull/1587)
* Added `<Mutation />` component [#1520](https://github.com/apollographql/react-apollo/pull/1520)
* HoC `props` result-mapping function now receives prior return value as second argument.
* Fix errorPolicy when 'all' not passing data and errors
Expand Down
38 changes: 27 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@
"postcompile": "rollup -c && ./scripts/prepare-package.sh",
"watch": "tsc -w",
"lint": "tslint --project tsconfig.json --config tslint.json",
"lint:fix":
"npm run prettier && tslint 'src/*.ts*' --project tsconfig.json --fix",
"lint:fix": "npm run prettier && tslint 'src/*.ts*' --project tsconfig.json --fix",
"lint-staged": "lint-staged",
"prettier":
"prettier --write \"{,!(node_modules|lib|coverage|npm)/**/}*.{ts*,js*,json,md}\""
"prettier": "prettier --write \"{,!(node_modules|lib|coverage|npm)/**/}*.{ts*,js*,json,md}\""
},
"bundlesize": [
{
Expand All @@ -45,8 +43,15 @@
}
],
"lint-staged": {
"*.{ts*}": ["prettier --write", "npm run lint", "git add"],
"*.{js*,json,md}": ["prettier --write", "git add"]
"*.{ts*}": [
"prettier --write",
"npm run lint",
"git add"
],
"*.{js*,json,md}": [
"prettier --write",
"git add"
]
},
"repository": {
"type": "git",
Expand All @@ -63,7 +68,9 @@
],
"author": "James Baxley <[email protected]>",
"babel": {
"presets": ["env"]
"presets": [
"env"
]
},
"jest": {
"testEnvironment": "jsdom",
Expand All @@ -72,16 +79,25 @@
"^.+\\.jsx?$": "babel-jest"
},
"mapCoverage": true,
"moduleFileExtensions": ["ts", "tsx", "js", "json"],
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"json"
],
"modulePathIgnorePatterns": [
"<rootDir>/examples",
"<rootDir>/test/flow-usage.js",
"<rootDir>/test/typescript-usage.tsx",
"<rootDir>/test/fail-no-entry-point.js"
],
"projects": ["<rootDir>"],
"projects": [
"<rootDir>"
],
"testRegex": "(/test/(?!test-utils\b)\b.*|\\.(test|spec))\\.(ts|tsx|js)$",
"setupFiles": ["<rootDir>/test/test-utils/setup.ts"]
"setupFiles": [
"<rootDir>/test/test-utils/setup.ts"
]
},
"license": "MIT",
"peerDependencies": {
Expand Down Expand Up @@ -148,4 +164,4 @@
"lodash": "4.17.5",
"prop-types": "^15.6.0"
}
}
}
4 changes: 4 additions & 0 deletions src/ApolloConsumer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ ApolloConsumer.contextTypes = {
client: PropTypes.object.isRequired,
};

ApolloConsumer.propTypes = {
children: PropTypes.func.isRequired,
};

export default ApolloConsumer;
11 changes: 11 additions & 0 deletions src/Query.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@ class Query<
static contextTypes = {
client: PropTypes.object.isRequired,
};

static propTypes = {
children: PropTypes.func.isRequired,
fetchPolicy: PropTypes.string,
notifyOnNetworkStatusChange: PropTypes.bool,
pollInterval: PropTypes.number,
query: PropTypes.object.isRequired,
variables: PropTypes.object,
ssr: PropTypes.bool,
};

context: QueryContext;

private client: ApolloClient<Object>;
Expand Down
6 changes: 6 additions & 0 deletions src/Subscriptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ class Subscription<TData = any, TVariables = any> extends React.Component<
client: PropTypes.object.isRequired,
};

static propTypes = {
query: PropTypes.object.isRequired,
variables: PropTypes.object,
children: PropTypes.func.isRequired,
};

private client: ApolloClient<any>;
private queryObservable: Observable<any>;
private querySubscription: ZenObservable.Subscription;
Expand Down