1.4.0 • Published 6 years ago

ej2-graphql-adaptor v1.4.0

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

GraphQL Data Adaptor for EJ2 DataManager

GraphQL Data Adaptor for EJ2 DataManager

Build

Usage

Query

This adaptor helps EJ2 DataManager to interact with GraphQL endpoint. The simple GraphQLAdaptor initialization will look like below.

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.

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 schema at the GraphQL server, use the below code example.

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.

NameTypeComments
response -> resultstringSpecifies the response schema. Helps to find the collection from result
response -> countstringSpecifies the response schema. Helps to find the count value
querystringSpecifies the GraphQL query string
getMutation(action: string) => stringInvoked 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 nameDescription
$datamanagerHolds the datamanager query such as page, sort etc.
$keyColumnSpecifies the primary column name
$keySpecifies the primary key value
$valueHolds the new, edit or removed data
$actionSpecifies CRUD operation performed