# aor-apollo-client

> Apollo client builder for AOR (Admin On Rest)

Latest version **1.0.1** (published 2018-04-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install aor-apollo-client
pnpm add aor-apollo-client
yarn add aor-apollo-client
bun add aor-apollo-client
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2018-04-30 |
| First published | 2018-04-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 9 |
| Unpacked size | 82.2 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Evan Corl |
| Maintainers | evancorl |
| Keywords | admin, admin-on-rest, apollo, graphql |

## Links

- npm: https://www.npmjs.com/package/aor-apollo-client
- Repository: https://github.com/evancorl/aor-apollo-client
- Homepage: https://github.com/evancorl/aor-apollo-client#readme
- Issues: https://github.com/evancorl/aor-apollo-client/issues
- npm.io page: https://npm.io/package/aor-apollo-client

## Dependencies (9)

- [graphql](https://npm.io/package/graphql.md) 0.13.0
- [pluralize](https://npm.io/package/pluralize.md) ^7.0.0
- [graphql-tag](https://npm.io/package/graphql-tag.md) ^2.8.0
- [lodash.omit](https://npm.io/package/lodash.omit.md) ^4.5.0
- [lodash.pick](https://npm.io/package/lodash.pick.md) ^4.4.0
- [lodash.camelcase](https://npm.io/package/lodash.camelcase.md) ^4.3.0
- [lodash.clonedeep](https://npm.io/package/lodash.clonedeep.md) ^4.5.0
- [lodash.upperfirst](https://npm.io/package/lodash.upperfirst.md) ^4.3.1
- [lodash.defaultsdeep](https://npm.io/package/lodash.defaultsdeep.md) ^4.6.0

## Alternatives

- [apollo-link-http-common](https://npm.io/package/apollo-link-http-common.md) — 879.0K weekly downloads
- [react-relay](https://npm.io/package/react-relay.md) — 336.8K weekly downloads
- [relay-test-utils](https://npm.io/package/relay-test-utils.md) — 181.6K weekly downloads
- [@vendure/core](https://npm.io/package/@vendure/core.md) — 14.8K weekly downloads
- [@pnpm/deps.graph-sequencer](https://npm.io/package/@pnpm/deps.graph-sequencer.md) — 13.4K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2018-04-30
- 1.0.0 — 2018-04-30

## README

# aor-apollo-client

A [custom REST client](https://marmelab.com/admin-on-rest/RestClients.html) for [AOR (Admin On Rest)](https://www.npmjs.com/package/admin-on-rest) using [Apollo client](https://www.apollographql.com/client).

The goal of this package is to write as few lines of code as possible to set up an Apollo client with AOR. You can do so by following certain conventions in your server's [GraphQL schema](docs/configuration.md#graphql-schema), but any of these conventions can also be overridden in favor of [full customization](docs/configuration.md#request-config).

## Installation

```sh
yarn add aor-apollo-client
```
or
```sh
npm install aor-apollo-client
```

## Configuration

See full docs on configuration [here](docs/configuration.md).

## Quick Start

Assuming your server's [GraphQL schema](docs/configuration.md#graphql-schema) is already set up, there are only three steps to implement the AOR Apollo client:

1. Create an Apollo client. By design, this step isn't done for you. That way you can create/configure the client any way you'd like. The quickest way is with [apollo-boost](https://www.npmjs.com/package/apollo-boost):

```js
import ApolloClient from 'apollo-boost';

// Pass your GraphQL endpoint to uri
export default new ApolloClient({ uri: 'http://localhost:4000/graphql' });
```

2. Create a [resource map](docs/configuration.md#resource-map). This is an object that maps your [AOR Resource](https://marmelab.com/admin-on-rest/Resource.html) names to configuration used by AOR Apollo client to send respective queries/mutations:

```js
export default {
  // AOR resource name
  posts: {
    // AOR request type
    GET_ONE: {
      // Fields returned from Apollo request
      fields: `
        _id
        title
        authorId
        content
      `,
    },
    GET_LIST: {
      fields: `
        data {
          _id
          title
          authorId
        }
        total
      `,
    },
  },
};
```

3. Lastly, build the AOR Apollo client and pass it to the [AOR Admin component](https://marmelab.com/admin-on-rest/Admin.html). 
The default builder function exported from the package expects a single object parameter with the following fields: `apolloClient`, [resourceMap](docs/configuration.md#resource-map), and [defaultResourceConfig](docs/configuration.md#defaultresourceconfig) (optional):

```jsx
import React from 'react';
import { Admin, Resource } from 'admin-on-rest';
import { PostCreate, PostEdit, PostList } from './posts'; // Your AOR CRUD components
import buildAorApolloClient from 'aor-apollo-client';
import apolloClient from './apolloClient';
import resourceMap from './resourceMap';

const aorApolloClient = buildAorApolloClient({
  apolloClient,
  resourceMap,
  defaultResourceConfig: {
    primaryKey: '_id',
    paginationInput: 'PaginationInput',
    sortInput: 'SortInput',
  },
});

const App = () => (
  <Admin restClient={aorApolloClient}>
    <Resource
      name="posts"
      create={PostCreate}
      edit={PostEdit}
      list={PostList}
    />
  </Admin>
);

export default App;
```

## Under the Hood

There are three main steps that the client does for each AOR request under the hood:

1. Formats AOR params into Apollo variables
2. Sends the Apollo request
3. Parses Apollo result as AOR response

Each of these steps can be [overridden for any request](docs/configuration.md#request-config) on any resource. If you follow the package's conventions in your GraphQL schema, however, the AOR Apollo client can handle most of the work for you.

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