# bluerain-apollo-plugin

A fully-featured, production ready caching GraphQL client for every server or UI framework. <https://blueeast.gitbook.io/bluerain-plugin-apollo>

* [Github Repo](http://dev.apollodata.com/react/)

| 🌏 Web | 🖥 Electron | 📱 React Native |
| ------ | ----------- | --------------- |
| ✔️     | ✔️          | TBD             |

### Screenshots

**NA**

## Components

This plugin registers following components in the Component registry, so they can be reused later by other apps and plugins;

* **Apollo Consumer**

  <https://www.apollographql.com/docs/react/api/react-apollo.html#apollo-consumer>
* **GraphqlQuery**

  <https://www.apollographql.com/docs/react/essentials/queries.html#basic>
* **GraphqlMutation**

  <https://www.apollographql.com/docs/react/essentials/mutations.html>
* **GraphqlSubscription**

  <https://www.apollographql.com/docs/apollo-server/v2/features/subscriptions.html>

## Hooks

This plugin provides complete flexibility to modify the apollo client. This is done by providing various filter hooks at different stages of store initialization.

### bluerain.system.app

This hook gives the ability to modify the main System App component that gets wrapped in Redux's Provider.

#### **Parameters:**

| Name      | Type            | Description                    |
| --------- | --------------- | ------------------------------ |
| SystemApp | React.Component | The main system app component. |

#### **Returns:**

| Name      | Type            | Description                    |
| --------- | --------------- | ------------------------------ |
| SystemApp | React.Component | The main system app component. |

#### **Example:**

This example wraps the System App with a Apollo provider by using a `replaceReduxProvider` higher order component (HOC).

```javascript
  import BR from '@blueeast/bluerain-os';
  import withApolloProvider from './withApolloProvider';

  'bluerain.system.app': App => {
              return withApolloProvider(App, client);
          }
```

### plugin.apollo.config

This hook gives the ability to modify the plugin configurations.

**Parameters:**

| Name   | Type   | Description           |
| ------ | ------ | --------------------- |
| config | Object | Plugin configurations |

**Returns:**

| Name   | Type   | Description           |
| ------ | ------ | --------------------- |
| config | Object | Plugin configurations |

**Example:**

This example activates subscriptions in apollo client.

```javascript
  import BR from '@blueeast/bluerain-os';

  BR.Filters.add(
      'plugin.apollo.config',
      function ActivateApolloSubscriptions(configs) {
          return Object.assign({}, configs, {
              subscriptions: true
          })
      }
  );
```

### plugin.apollo.links

This hook gives the ability to provide uri for websocket server

**Parameters:**

| Name | Type  | Description              |
| ---- | ----- | ------------------------ |
| link | Array | uri for websocket server |

**Returns:**

| Name | Type  | Description              |
| ---- | ----- | ------------------------ |
| link | Array | uri for websocket server |

**Example:**

```javascript
  'plugin.apollo.links': (links) => {
              return links;
          }
```

### plugin.apollo.cache:

This Hook clears cache of the of Apollo store

### plugin.system.initialized:

This Hook Create apollo client when all plugins and apps are initialized

## API

* **ApolloPluginConfigs**

  This is the default configuration set that is used at boot time.

  **Properties**

  * httpLinkOptions  **HttpLinks** URI link of websocket server
  * `clientOptions` **ApolloClientOptions** Apollo client params

  **ApolloPlugin**

  **Extends Plugin**

  Main Apollo Plugin class.

  **Plugin Properties**

  * `pluginName` [**string**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) "ApolloPlugin"
  * `slug` [**string**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) "apollo"

  **getClient**

  Returns Apollo client
