-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(SearchResolver): Add SearchResolver generated from mapping
- Loading branch information
Showing
7 changed files
with
139 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* @flow */ | ||
|
||
import { InputTypeComposer } from 'graphql-compose'; | ||
import { GraphQLEnumType } from 'graphql'; | ||
import { getTypeName, getOrSetType } from '../utils'; | ||
import { getFieldNamesByElasticType } from './Commons/FieldNames'; | ||
|
||
const sortableTypes = [ | ||
'byte', | ||
'short', | ||
'integer', | ||
'long', | ||
'double', | ||
'float', | ||
'half_float', | ||
'scaled_float', | ||
'token_count', | ||
'date', | ||
'boolean', | ||
'ip', | ||
'keyword', | ||
]; | ||
|
||
export function getSortITC(opts: any = {}): InputTypeComposer | string { | ||
const name = getTypeName('SortEnum', opts); | ||
const description = 'Sortable fields from mapping'; | ||
|
||
if (!opts.fieldMap) { | ||
return 'JSON'; | ||
} | ||
|
||
return getOrSetType(name, () => { | ||
const sortableFields = getFieldNamesByElasticType( | ||
opts.fieldMap, | ||
sortableTypes | ||
); | ||
if (sortableFields.length === 0) { | ||
return 'JSON'; | ||
} | ||
|
||
const values = { | ||
_score: { | ||
value: '_score', | ||
}, | ||
}; | ||
sortableFields.forEach(fieldName => { | ||
const dottedName = fieldName.replace('__', '.'); | ||
values[`${fieldName}__asc`] = { | ||
value: { [dottedName]: 'asc' }, | ||
}; | ||
values[`${fieldName}__desc`] = { | ||
value: { [dottedName]: 'desc' }, | ||
}; | ||
}); | ||
|
||
return new GraphQLEnumType({ | ||
name, | ||
description, | ||
values, | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -314,15 +314,15 @@ babel-core@^6.0.0, babel-core@^6.24.0: | |
slash "^1.0.0" | ||
source-map "^0.5.0" | ||
|
||
babel-eslint@^7.1.1: | ||
version "7.1.1" | ||
resolved "https://registry.yarnpkg.com/babel-eslint/-/babel-eslint-7.1.1.tgz#8a6a884f085aa7060af69cfc77341c2f99370fb2" | ||
babel-eslint@^7.2.0: | ||
version "7.2.0" | ||
resolved "https://registry.yarnpkg.com/babel-eslint/-/babel-eslint-7.2.0.tgz#8941514b9dead06f0df71b29d5d5b193a92ee0ae" | ||
dependencies: | ||
babel-code-frame "^6.16.0" | ||
babel-traverse "^6.15.0" | ||
babel-types "^6.15.0" | ||
babylon "^6.13.0" | ||
lodash.pickby "^4.6.0" | ||
babel-code-frame "^6.22.0" | ||
babel-traverse "^6.23.1" | ||
babel-types "^6.23.0" | ||
babylon "^6.16.1" | ||
lodash "^4.17.4" | ||
|
||
babel-generator@^6.18.0, babel-generator@^6.24.0: | ||
version "6.24.0" | ||
|
@@ -796,7 +796,7 @@ babel-template@^6.16.0, babel-template@^6.22.0, babel-template@^6.23.0: | |
babylon "^6.11.0" | ||
lodash "^4.2.0" | ||
|
||
babel-traverse@^6.15.0, babel-traverse@^6.18.0, babel-traverse@^6.22.0, babel-traverse@^6.23.0, babel-traverse@^6.23.1: | ||
babel-traverse@^6.18.0, babel-traverse@^6.22.0, babel-traverse@^6.23.0, babel-traverse@^6.23.1: | ||
version "6.23.1" | ||
resolved "https://registry.yarnpkg.com/babel-traverse/-/babel-traverse-6.23.1.tgz#d3cb59010ecd06a97d81310065f966b699e14f48" | ||
dependencies: | ||
|
@@ -810,7 +810,7 @@ babel-traverse@^6.15.0, babel-traverse@^6.18.0, babel-traverse@^6.22.0, babel-tr | |
invariant "^2.2.0" | ||
lodash "^4.2.0" | ||
|
||
babel-types@^6.15.0, babel-types@^6.18.0, babel-types@^6.19.0, babel-types@^6.22.0, babel-types@^6.23.0: | ||
babel-types@^6.18.0, babel-types@^6.19.0, babel-types@^6.22.0, babel-types@^6.23.0: | ||
version "6.23.0" | ||
resolved "https://registry.yarnpkg.com/babel-types/-/babel-types-6.23.0.tgz#bb17179d7538bad38cd0c9e115d340f77e7e9acf" | ||
dependencies: | ||
|
@@ -819,11 +819,11 @@ babel-types@^6.15.0, babel-types@^6.18.0, babel-types@^6.19.0, babel-types@^6.22 | |
lodash "^4.2.0" | ||
to-fast-properties "^1.0.1" | ||
|
||
[email protected]: | ||
[email protected], babylon@^6.11.0, babylon@^6.13.0, babylon@^6.15.0: | ||
version "6.15.0" | ||
resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.15.0.tgz#ba65cfa1a80e1759b0e89fb562e27dccae70348e" | ||
|
||
babylon@^6.11.0, babylon@^6.13.0, babylon@^6.15.0: | ||
babylon@^6.16.1: | ||
version "6.16.1" | ||
resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.16.1.tgz#30c5a22f481978a9e7f8cdfdf496b11d94b404d3" | ||
|
||
|
@@ -2001,9 +2001,9 @@ graceful-fs@^4.1.2, graceful-fs@^4.1.4, graceful-fs@^4.1.6: | |
version "1.0.1" | ||
resolved "https://registry.yarnpkg.com/graceful-readlink/-/graceful-readlink-1.0.1.tgz#4cafad76bc62f02fa039b2f94e9a3dd3a391a725" | ||
|
||
graphql-compose@^1.17.3: | ||
version "1.17.3" | ||
resolved "https://registry.yarnpkg.com/graphql-compose/-/graphql-compose-1.17.3.tgz#ad4f19570aedc6647d6addb43d6f52d3804029b9" | ||
graphql-compose@^1.18.0: | ||
version "1.18.0" | ||
resolved "https://registry.yarnpkg.com/graphql-compose/-/graphql-compose-1.18.0.tgz#bb28c2336bb0e4fdd87efeb92747e781a8691752" | ||
dependencies: | ||
babel-runtime "^6.23.0" | ||
object-path "^0.11.4" | ||
|
@@ -2865,10 +2865,6 @@ lodash.padstart@^4.1.0: | |
version "4.6.1" | ||
resolved "https://registry.yarnpkg.com/lodash.padstart/-/lodash.padstart-4.6.1.tgz#d2e3eebff0d9d39ad50f5cbd1b52a7bce6bb611b" | ||
|
||
lodash.pickby@^4.6.0: | ||
version "4.6.0" | ||
resolved "https://registry.yarnpkg.com/lodash.pickby/-/lodash.pickby-4.6.0.tgz#7dea21d8c18d7703a27c704c15d3b84a67e33aff" | ||
|
||
lodash.restparam@^3.0.0: | ||
version "3.6.1" | ||
resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805" | ||
|
@@ -2877,7 +2873,7 @@ lodash@^3.6.0, lodash@^3.7.0: | |
version "3.10.1" | ||
resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6" | ||
|
||
lodash@^4.0.0, lodash@^4.12.0, lodash@^4.13.1, lodash@^4.14.0, lodash@^4.15.0, lodash@^4.2.0, lodash@^4.3.0: | ||
lodash@^4.0.0, lodash@^4.12.0, lodash@^4.13.1, lodash@^4.14.0, lodash@^4.15.0, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.3.0: | ||
version "4.17.4" | ||
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae" | ||
|
||
|