elasticsearch-graphql
Advanced tools
Comparing version 1.1.3 to 2.0.0
39
index.js
var elasticsearch = require('elasticsearch') | ||
function init (opts, cb) { | ||
if (!opts.graphql || !opts.graphql.GraphQLInt) return cb(new Error('Missing graphql option, needed for internal reference')) | ||
if (!opts.elastic.index) return cb(new Error('Missing elastic search index to fetch mapping from')) | ||
if (!opts.elastic.type) return cb(new Error('Missing elastic search type to fetch mapping from')) | ||
function init (opts) { | ||
if (!opts.graphql || !opts.graphql.GraphQLInt) throw new Error('Missing graphql option, needed for internal reference') | ||
if (!opts.elastic.index) throw new Error('Missing elastic search index to fetch mapping from') | ||
if (!opts.elastic.type) throw new Error('Missing elastic search type to fetch mapping from') | ||
if (!opts.mapping) throw new Error('Missing elastic mapping') | ||
@@ -19,31 +20,9 @@ if (opts.elastic.host) { | ||
return new Promise(function (resolve, reject) { | ||
if (opts.elastic.mapping) return resolve(opts.elastic.mapping) | ||
var mapping = opts.mapping.mappings[opts.elastic.type] | ||
var properties = mapping.properties | ||
var transform = mapping.transform | ||
opts.client.indices.getMapping({ | ||
index: opts.elastic.index, | ||
type: opts.elastic.type | ||
}, function (err, res) { | ||
if (err) return reject(err) | ||
resolve(res) | ||
}) | ||
}) | ||
.then(function (response) { | ||
var indexes = Object.keys(response) | ||
var mapping = response[indexes[0]].mappings[opts.elastic.type] | ||
var properties = mapping.properties | ||
var transform = mapping.transform | ||
cb && cb(null, schemaBuilder(opts, properties, transform)) | ||
return schemaBuilder(opts, properties, transform) | ||
}) | ||
.catch(function (err) { | ||
cb && cb(err) | ||
return err | ||
}) | ||
return schemaBuilder(opts, properties, transform) | ||
} | ||
module.exports = init |
@@ -107,3 +107,4 @@ var _ = require('lodash') | ||
var body = { | ||
_source: false | ||
_source: false, | ||
size: params.limit | ||
} | ||
@@ -110,0 +111,0 @@ |
@@ -63,9 +63,3 @@ var aggregations = require('./aggregations') | ||
}, | ||
hits: { | ||
type: new graphql.GraphQLList(opts.hitsSchema.type), | ||
args: opts.hitsSchema.args, | ||
resolve: function (response) { | ||
return opts.hitsSchema.resolve(response.hits.hits) | ||
} | ||
} | ||
hits: opts.hitsSchema | ||
} | ||
@@ -72,0 +66,0 @@ } |
{ | ||
"name": "elasticsearch-graphql", | ||
"version": "1.1.3", | ||
"version": "2.0.0", | ||
"description": "Schema generator and query builder for elasticsearch", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14697
420