Skip to content

Commit dd489a2

Browse files
committed
feat(withQueryData): with query data
1 parent ac709c1 commit dd489a2

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ a utility belt for higher-order components in `apollo`. Recompose utilities for
44

55
## Higher-order components
66

7+
### `withQueryData()`
8+
9+
```js
10+
withQueryData(
11+
queryDocument: DocumentNode,
12+
optionsObject: { options: (props) => { variables } } | { options: Object }
13+
): HigherOrderComponent
14+
```
15+
16+
Same functionality as `react-apollo` `graphql` HOC, except the `data` prop or named data prop is flattened.
17+
718
### `withSubscribe()`
819

920
```js

src/withQueryData.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { compose, flattenProp } from 'recompose';
2+
import { graphql } from 'react-apollo';
3+
4+
export default function withQueryData(queryDocument, optionsObject = {}) {
5+
const flattenKey = (optionsObject && optionsObject.name) || 'data';
6+
7+
return compose(
8+
graphql(queryDocument, optionsObject),
9+
flattenProp(flattenKey)
10+
);
11+
}

0 commit comments

Comments
 (0)