# ej2-graphql-adaptor

> GraphQL Data Adaptor for EJ2 DataManager

Latest version **1.4.0** (published 2018-01-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install ej2-graphql-adaptor
pnpm add ej2-graphql-adaptor
yarn add ej2-graphql-adaptor
bun add ej2-graphql-adaptor
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.4.0 |
| Published | 2018-01-11 |
| First published | 2017-09-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Madhu Sudhanan P |
| Maintainers | madhust |
| Keywords | ej2-data, ej2, graphql, graphql-adaptor, custom-adaptor, adaptor |

## Links

- npm: https://www.npmjs.com/package/ej2-graphql-adaptor
- Repository: https://github.com/Madhust/ej2-graphql-adaptor
- Homepage: https://github.com/Madhust/ej2-graphql-adaptor#readme
- Issues: https://github.com/Madhust/ej2-graphql-adaptor/issues
- npm.io page: https://npm.io/package/ej2-graphql-adaptor

## Dependencies (1)

- [@syncfusion/ej2-data](https://npm.io/package/@syncfusion/ej2-data.md) *

## 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.4.0 (latest) — 2018-01-11
- 1.1.0 (next) — 2017-09-17
- 1.3.0 — 2017-09-24
- 1.2.0 — 2017-09-18
- 1.0.0 — 2017-09-17

## README

# GraphQL Data Adaptor for EJ2 DataManager

GraphQL Data Adaptor for EJ2 DataManager

![Build](https://travis-ci.org/Madhust/ej2-graphql-adaptor.svg?branch=master)

## Usage

### Query

This adaptor helps EJ2 [`DataManager`](https://www.npmjs.com/package/@syncfusion/ej2-data) to interact with GraphQL endpoint. The simple `GraphQLAdaptor` initialization will look like below.

```typescript
import { GraphQLAdaptor } from 'ej2-graphql-adaptor';

let adaptor: GraphQLAdaptor = new GraphQLAdaptor({
            response: {
                result: 'orders',
                count: 'count'
            },
            query: `query Order($datamanager: DataManager) {
                orders(datamanager: $datamanager) {
                    CustomerID,
                    Freight,
                    ShipName
                }
            }`
        })
```

### Mutation

Mutation query can be provided using `getMutation` option. This method will be invoked with
action name (like `insert`, `update` & `remote`) on mutation opertations.

```typescript
import { GraphQLAdaptor } from 'ej2-graphql-adaptor';

let adaptor: GraphQLAdaptor = new GraphQLAdaptor({
            response: {
                result: 'orders',
                count: 'count'
            },
            query: `query Order($datamanager: DataManager) {
                orders(datamanager: $datamanager) {
                    CustomerID,
                    Freight,
                    ShipName
                }
            }`,
            getMutation: (action: string) => {
                if (action === 'insert') {
                    return `mutation Create($value: OrderInput){
                                createOrder(value: $value) {
                                    CustomerID,
                                    Freight,
                                    ShipName
                                }
                            }`
                }

                if (action === 'update') {
                    return `mutation Update($value: OrderInput){
                                updateOrder(value: $value) {
                                    CustomerID,
                                    Freight,
                                    ShipName
                                }
                            }`
                }

                if (action === 'remove') {
                    return `mutation Remove($key: String, $keyColumn: String $value: OrderInput){
                                removeOrder(key: $key, keyColumn: $keyColumn, value: $value) {
                                    CustomerID,
                                    Freight,
                                    ShipName
                                }
                            }`
                }
            }
        })
```

## Schema

To include the [`DataManager`](https://www.npmjs.com/package/@syncfusion/ej2-data) schema at the GraphQL server, use the below code example.

```typescript
import { schema } from 'ej2-graphql-adaptor/schema/schema';

module.exports =
`${scheme}
type Order {
    CustomerID: String!
    Freight: Float!
    ShipName: String!
}

type Query {
    orders(datamanager: DataManager): [Order]
}
`
```

## API

`GraphQLAdaptor` will accept the following options while initialization.

| Name | Type | Comments |
|-------------------|-----------------|-----------------|
| response -> result | string | Specifies the response schema. Helps to find the collection from result |
| response -> count | string | Specifies the response schema. Helps to find the count value |
| query | string | Specifies the GraphQL query string |
| getMutation | (action: string) => string | Invoked every time when CRUD operation initiated |

## Variables

`GraphQLAdaptor` sends various variable names which can be used in query. Below table provides the variable name and their description.

| Variable name | Description |
|-------------------|-----------------|
| $datamanager | Holds the datamanager query such as page, sort etc. |
| $keyColumn | Specifies the primary column name |
| $key | Specifies the primary key value |
| $value | Holds the new, edit or removed data |
| $action | Specifies CRUD operation performed |

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