Coder Social home page Coder Social logo

isabella232 / graphqltoelasticsearchtranslator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from atlassian-labs/graphqltoelasticsearchtranslator

0.0 0.0 0.0 198 KB

This package translates graphQL filer query to Elasticsearch query

License: Apache License 2.0

TypeScript 100.00%

graphqltoelasticsearchtranslator's Introduction

GraphQL to ElasticSearch Library

This is an implementation for translating GraphQL Queries to Elasticsearch DSL

Usage guide

Install the library:

npm install --save graphql-elasticsearch

Development guide

Install dependencies

npm install

Useful commands

# Run all checks
npm test

How to use the filter

import { QueryGenerator } from 'graphql-elasticsearch';

let args = {email:'[email protected]'};  // Graphql query args
const testFilterConfig: any  = {
    filter: {
        isNull: ['id'],
        isNotNull: ['email'],
        arguments: {
            id: {
                description: 'Unique Identifier',
                db_field_name: 'id',
                db_type: 'keyword',
                type: 'string'
            },
            email: {
                description:
                    'This endpoint takes a contact (email) and returns all link documents for that contact.',
                db_field_name: 'email.raw',
                db_type: 'keyword',
                type: 'string'
            },
            and: {
                description: 'AND operator',
                db_field_name: 'None',
                db_type: 'None',
                type: 'array'
            },
            or: {
                description: 'OR operator',
                db_field_name: 'None',
                db_type: 'None',
                type: 'array'
            },
            not: {
                description: 'NOT operator',
                db_field_name: 'None',
                db_type: 'None',
                type: 'array'
            },
            isNotNull: {
                description: 'field name is not null',
                db_field_name: 'None',
                db_type: 'None',
                type: 'string'
            },
            isNull: {
                description: 'field name is null',
                db_field_name: 'None',
                db_type: 'None',
                type: 'string'
            }
        }
    }
};

let query = bodybuilder();
query = new QueryGenerator().getFilterQuery(query,args,filterConfig);

ES query: 
"query": {
    "bool": {
      "must": [{
            "term": {
                "email.raw": "[email protected]"
            }
        }]   
    }
}

graphqltoelasticsearchtranslator's People

Contributors

riddhi77 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.