Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

elasticsearch-graphql

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

elasticsearch-graphql - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

graphql.js

7

index.js
var elasticsearch = require('elasticsearch')
var query = require('./lib/query')

@@ -14,2 +13,6 @@ function init (opts, cb) {

require('./graphql').set(opts.graphql)
var schemaBuilder = require('./lib/schemaBuilder')
return opts.client.indices.getMapping({

@@ -26,3 +29,3 @@ index: opts.elastic.index,

cb(null, query(opts, properties, transform))
cb(null, schemaBuilder(opts, properties, transform))
})

@@ -29,0 +32,0 @@ }

@@ -0,1 +1,5 @@

var OrderByEnum = require('../types/OrderByEnum')
var DirectionEnum = require('../types/DirectionEnum')
var Bucket = require('../types/Bucket')
var camelCase = require('lodash').camelCase

@@ -5,76 +9,8 @@ var _ = require('lodash')

var bucketFields = function (keyType, countType) {
return {
key: {
type: keyType,
resolve: function (bucket) {
return bucket.key
}
},
count: {
type: countType,
resolve: function (bucket) {
return bucket.doc_count
}
}
}
}
function convertType (opts, type) {
switch (type) {
case 'boolean':
return new opts.graphql.GraphQLObjectType({
name: 'Bucket_' + _.uniqueId(),
description: 'Bucket for string',
fields: bucketFields(opts.graphql.GraphQLBoolean, opts.graphql.GraphQLInt)
})
case 'long':
return new opts.graphql.GraphQLObjectType({
name: 'Bucket_' + _.uniqueId(),
description: 'Bucket for string',
fields: bucketFields(opts.graphql.GraphQLFloat, opts.graphql.GraphQLInt)
})
case 'date':
case 'string':
default:
return new opts.graphql.GraphQLObjectType({
name: 'Bucket_' + _.uniqueId(),
description: 'Bucket for string',
fields: bucketFields(opts.graphql.GraphQLString, opts.graphql.GraphQLInt)
})
}
}
function convertFields (opts, current, properties) {
var orderByType = new opts.graphql.GraphQLEnumType({
name: 'OrderBy_' + _.uniqueId(),
description: 'Different order alternatives',
values: {
TERM: {
value: '_term',
description: 'Order values by term'
},
COUNT: {
value: '_count',
description: 'Order values by count'
}
}
})
var directionType = new opts.graphql.GraphQLEnumType({
name: 'OrderBy_' + _.uniqueId(),
description: 'Different order alternatives',
values: {
ASC: {
value: 'asc'
},
DESC: {
value: 'desc'
}
}
})
Object.keys(properties).forEach(function (prop) {
var p = properties[prop]
var fields = {}
var type = camelCase(prop)
var name = [type, _.uniqueId()].join('_')

@@ -93,8 +29,4 @@ if (p.properties) {

var bucketType = convertType(opts, p.type)
if (!bucketType) return
fields.buckets = {
type: new opts.graphql.GraphQLList(bucketType),
type: new opts.graphql.GraphQLList(Bucket(p.type)),
resolve: function (data) {

@@ -108,8 +40,5 @@ if (!data.aggs) return

var type = camelCase(prop)
var name = camelCase(prop) + '_' + _.uniqueId()
if (!Object.keys(fields).length) return
current[camelCase(prop)] = {
current[type] = {
name: name,

@@ -128,10 +57,10 @@ resolve: function (data) {

order: {
type: orderByType
type: OrderByEnum()
},
direction: {
type: directionType
type: DirectionEnum()
}
},
type: new opts.graphql.GraphQLObjectType({
name: camelCase(prop) + '_' + _.uniqueId(),
name: name,
description: 'None',

@@ -153,3 +82,3 @@ fields: function (aggregations) {

return new opts.graphql.GraphQLObjectType({
name: 'Aggregations_' + _.uniqueId(),
name: ['Aggregations', opts.name].join('_'),
description: 'aggs',

@@ -156,0 +85,0 @@ fields: function () {

var camelCase = require('lodash').camelCase
var _ = require('lodash')
var Filter = require('../types/Filter')
function convertType (opts, type) {
var graphql = opts.graphql
var filterType = new opts.graphql.GraphQLEnumType({
name: 'FilterType_' + _.uniqueId(),
description: 'Different filter types',
values: {
AND: {
value: 'must'
},
OR: {
value: 'should'
},
NOT: {
value: 'must_not'
}
}
})
switch (type) {
case 'boolean':
return new graphql.GraphQLInputObjectType({
name: 'filter_' + _.uniqueId(),
fields: {
operator: { type: filterType },
value: { type: graphql.GraphQLBoolean },
values: { type: new graphql.GraphQLList(graphql.GraphQLBoolean) }
}
})
case 'long':
return new graphql.GraphQLInputObjectType({
name: 'filter_' + _.uniqueId(),
fields: {
operator: { type: filterType },
value: { type: graphql.GraphQLFloat },
values: { type: new graphql.GraphQLList(graphql.GraphQLFloat) }
}
})
case 'date':
case 'string':
default:
return new graphql.GraphQLInputObjectType({
name: 'filter_' + _.uniqueId(),
fields: {
operator: { type: filterType },
value: { type: graphql.GraphQLString },
values: { type: new graphql.GraphQLList(graphql.GraphQLString) }
}
})
}
}
function convertFields (opts, current, properties) {

@@ -61,3 +10,3 @@ Object.keys(properties).forEach(function (prop) {

var propName = camelCase(prop)
var name = propName + '_' + _.uniqueId()
var name = [propName, _.uniqueId()].join('_')

@@ -74,8 +23,4 @@ if (p.properties) {

} else {
var type = convertType(opts, p.type, p)
if (!type) return
current[propName] = {
type: type
type: Filter(p.type)
}

@@ -82,0 +27,0 @@ }

{
"name": "elasticsearch-graphql",
"version": "1.1.0",
"version": "1.1.1",
"description": "Schema generator and query builder for elasticsearch",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc