# recompose-apollo

> Recompose HOCs utils for Apollo

Latest version **0.3.1** (published 2018-01-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install recompose-apollo
pnpm add recompose-apollo
yarn add recompose-apollo
bun add recompose-apollo
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.1 |
| Published | 2018-01-24 |
| First published | 2018-01-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Abhi Aiyer |
| Maintainers | abhiaiyer |
| Keywords | ecmascript, es2015, jsnext, javascript, relay, npm, react |

## Links

- npm: https://www.npmjs.com/package/recompose-apollo
- npm.io page: https://npm.io/package/recompose-apollo

## Dependencies (1)

- [rollup-plugin-node-resolve](https://npm.io/package/rollup-plugin-node-resolve.md) ^3.0.2

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.3.1 (latest) — 2018-01-24
- 0.3.0 — 2018-01-21
- 0.2.0 — 2018-01-17
- 0.1.3 — 2018-01-15
- 0.1.2 — 2018-01-15
- 0.1.1 — 2018-01-15
- 0.1.0 — 2018-01-15

## README

# Recompose Apollo

a utility belt for higher-order components in `apollo`. Recompose utilities for `react-apollo`.

## Higher-order components

### `withQueryData()`

```js
withQueryData(
  queryDocument: DocumentNode,
  optionsObject: { options: (props) => { variables } } | { options: Object }
): HigherOrderComponent
```

Same functionality as `react-apollo` `graphql` HOC, except the `data` prop or named data prop is flattened.

### `withQueryComponent()`

```js
withQueryComponent(
  queryDocument: DocumentNode,
  optionsObject: { options: (props) => { variables } } | { options: Object }
): Component
```

Return a query component given a GraphQL document and options. What's returned is a Component
with a render `child` that has the data object from `react-apollo`, see below.

Query Components outlined:
https://dev-blog.apollodata.com/query-components-with-apollo-ec603188c157

```js
const CitiesQuery = withQueryComponent(cityQuery);

function Sample() {
  return (
    <CitiesQuery>
      {
        (data) => {
          return (
            <p> I am loading {data.loading ? 'Yes' : 'No'} </p>
          );
        }
      }
    </CitiesQuery>
  );
}
```

### `withFragment()`

```js
withFragment(
  fragmentDocument: DocumentNode,
  optionsObject: {
    name: string,
    getFragmentId: (props) => string,
  }
): HigherOrderComponent
```

After a query has been made with the `graphql` HOC, use this HOC to read fragments from the Apollo Client cache. Based on the options `name`, the fragment data will be returned to the component as props under that key or `data`.


### `withSubscribe()`

```js
withSubscribe(
  subscriptionDocument: DocumentNode,
  optionsObject: { options: (props) => { variables } }
): HigherOrderComponent
```
Create a GraphQL subscription that subscribes on `componentDidMount`. By providing a
`onResult` prop to the Component, every time the subscription yields `next`, `onResult` will be called with the result of the subscription.


### `withLoadingState()`

```js
withLoadingState(
  Component: Function,
): HigherOrderComponent
```

Render a Component if the `networkStatus` from `apollo-client` is loading, otherwise return props for `networkStatus`:

* `activelyRefetching`
* `passivelyRefetching`
* `fetchingMore`

### `withErrorState()`

```js
withErrorState(
  Component: Function,
): HigherOrderComponent
```

Render a Component if the `networkStatus` from `apollo-client` is `error`.

---
_Source: https://npm.io/package/recompose-apollo · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
