Skip to content

Commit 444d64d

Browse files
committed
feat(QueryDSL): Defined all InputTypes for search.body
1 parent 8b8889e commit 444d64d

39 files changed

+1376
-39
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"graphql-compose": "^1.14.0"
3232
},
3333
"devDependencies": {
34-
"babel-cli": "^6.22.2",
34+
"babel-cli": "^6.24.0",
3535
"babel-eslint": "^7.1.1",
3636
"babel-plugin-transform-flow-strip-types": "^6.22.0",
3737
"babel-plugin-transform-object-rest-spread": "^6.22.0",
@@ -48,7 +48,7 @@
4848
"express-graphql": "^0.6.3",
4949
"flow-bin": "^0.41.0",
5050
"graphql": "^0.9.1",
51-
"graphql-compose": "^1.15.0",
51+
"graphql-compose": "^1.17.1",
5252
"jest": "^19.0.2",
5353
"jest-babel": "^1.0.1",
5454
"npm-run-all": "^4.0.1",
@@ -70,7 +70,7 @@
7070
"build": "npm-run-all build:*",
7171
"build:lib": "rimraf lib && babel src --ignore __tests__,__mocks__ -d lib",
7272
"build:flow": "find ./src -name '*.js' -not -path '*/__*' | while read filepath; do cp $filepath `echo $filepath | sed 's/\\/src\\//\\/lib\\//g'`.flow; done",
73-
"example": "nodemon -e js --ignore *test* --exec ./node_modules/.bin/babel-node ./examples/elastic50/index.js",
73+
"dev": "nodemon -e js --ignore *test* --exec ./node_modules/.bin/babel-node ./examples/elastic50/index.js",
7474
"coverage": "jest --coverage",
7575
"lint": "eslint --ext .js ./src",
7676
"test": "jest",

src/ElasticDSL/Query/Bool.js renamed to src/ElasticDSL/Query/Compound/Bool.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* @flow */
22

33
import { InputTypeComposer } from 'graphql-compose';
4-
import { getQueryITC } from './Query';
5-
import { getTypeName, getOrSetType, desc } from "../../utils";
4+
import { getQueryITC } from '../Query';
5+
import { getTypeName, getOrSetType, desc } from "../../../utils";
66

77
export function getBoolITC(opts: mixed = {}): InputTypeComposer {
88
const name = getTypeName('QueryBool', opts);
@@ -11,6 +11,7 @@ export function getBoolITC(opts: mixed = {}): InputTypeComposer {
1111
of other queries. The bool query maps to Lucene BooleanQuery.
1212
It is built using one or more boolean clauses, each clause
1313
with a typed occurrence.
14+
[Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html)
1415
`);
1516

1617
return getOrSetType(name, () =>
@@ -62,9 +63,7 @@ export function getBoolITC(opts: mixed = {}): InputTypeComposer {
6263
is returned.
6364
`),
6465
},
65-
boost: {
66-
type: 'Float',
67-
},
66+
boost: 'Float',
6867
},
6968
})
7069
);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* @flow */
2+
3+
import { InputTypeComposer } from 'graphql-compose';
4+
import { getQueryITC } from '../Query';
5+
import { getTypeName, getOrSetType, desc } from "../../../utils";
6+
7+
export function getBoostingITC(opts: mixed = {}): InputTypeComposer {
8+
const name = getTypeName('QueryBoosting', opts);
9+
const description = desc(`
10+
The boosting query can be used to effectively demote results that match a given query.
11+
[Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-boosting-query.html)
12+
`);
13+
14+
return getOrSetType(name, () =>
15+
// $FlowFixMe
16+
InputTypeComposer.create({
17+
name,
18+
description,
19+
fields: {
20+
positive: () => getQueryITC(opts),
21+
negative: () => getQueryITC(opts),
22+
negative_boost: 'Float',
23+
},
24+
})
25+
);
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* @flow */
2+
3+
import { InputTypeComposer } from 'graphql-compose';
4+
import { getQueryITC } from '../Query';
5+
import { getTypeName, getOrSetType, desc } from "../../../utils";
6+
7+
export function getConstantScoreITC(opts: mixed = {}): InputTypeComposer {
8+
const name = getTypeName('QueryConstantScore', opts);
9+
const description = desc(`
10+
A query that wraps another query and simply returns a constant score equal
11+
to the query boost for every document in the filter.
12+
[Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-constant-score-query.html)
13+
`);
14+
15+
return getOrSetType(name, () =>
16+
// $FlowFixMe
17+
InputTypeComposer.create({
18+
name,
19+
description,
20+
fields: {
21+
filter: () => getQueryITC(opts).getTypeAsRequired(),
22+
boost: 'Float!',
23+
},
24+
})
25+
);
26+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* @flow */
2+
3+
import { InputTypeComposer } from 'graphql-compose';
4+
import { getQueryITC } from '../Query';
5+
import { getTypeName, getOrSetType, desc } from "../../../utils";
6+
7+
export function getDisMaxITC(opts: mixed = {}): InputTypeComposer {
8+
const name = getTypeName('QueryDisMax', opts);
9+
const description = desc(`
10+
A query that generates the union of documents produced by its subqueries,
11+
and that scores each document with the maximum score for that document
12+
as produced by any subquery, plus a tie breaking increment
13+
for any additional matching subqueries.
14+
[Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-dis-max-query.html)
15+
`);
16+
17+
return getOrSetType(name, () =>
18+
// $FlowFixMe
19+
InputTypeComposer.create({
20+
name,
21+
description,
22+
fields: {
23+
queries: () => [getQueryITC(opts)],
24+
boost: 'Float',
25+
tie_breaker: 'Float',
26+
},
27+
})
28+
);
29+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/* @flow */
2+
3+
import { InputTypeComposer } from 'graphql-compose';
4+
import { getQueryITC } from '../Query';
5+
import { getTypeName, getOrSetType, desc } from "../../../utils";
6+
7+
export function getFunctionScoreITC(opts: mixed = {}): InputTypeComposer {
8+
const name = getTypeName('QueryFunctionScore', opts);
9+
const description = desc(`
10+
The function_score allows you to modify the score of documents that
11+
are retrieved by a query. This can be useful if, for example,
12+
a score function is computationally expensive and it is sufficient
13+
to compute the score on a filtered set of documents.
14+
[Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html)
15+
`);
16+
17+
// $FlowFixMe
18+
const RandomScoreType = InputTypeComposer.create({
19+
name: getTypeName('QueryFunctionScoreRandom', opts),
20+
fields: {
21+
seed: 'Float',
22+
},
23+
});
24+
25+
return getOrSetType(name, () =>
26+
// $FlowFixMe
27+
InputTypeComposer.create({
28+
name,
29+
description,
30+
fields: {
31+
query: () => getQueryITC(opts),
32+
boost: 'String',
33+
boost_mode: {
34+
type: 'String',
35+
description: 'Can be: `multiply`, `replace`, `sum`, `avg`, `max`, `min`.',
36+
},
37+
random_score: RandomScoreType,
38+
// $FlowFixMe
39+
functions: [InputTypeComposer.create({
40+
name: getTypeName('QueryFunctionScoreFunction', opts),
41+
fields: {
42+
filter: () => getQueryITC(opts),
43+
random_score: RandomScoreType,
44+
weight: 'Float',
45+
script_score: 'JSON',
46+
field_value_factor: 'JSON',
47+
gauss: 'JSON',
48+
linear: 'JSON',
49+
exp: 'JSON',
50+
},
51+
})],
52+
max_boost: 'Float',
53+
score_mode: {
54+
type: 'String',
55+
description: 'Can be: `multiply`, `sum`, `avg`, `first`, `max`, `min`.',
56+
},
57+
min_score: 'Float',
58+
},
59+
})
60+
);
61+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* @flow */
2+
3+
import { InputTypeComposer } from 'graphql-compose';
4+
import { getTypeName, getOrSetType, desc } from '../../../utils';
5+
6+
export function getCommonITC(opts: mixed = {}): InputTypeComposer {
7+
const name = getTypeName('QueryCommon', opts);
8+
const description = desc(`
9+
The common terms query is a modern alternative to stopwords which improves
10+
the precision and recall of search results (by taking stopwords into account),
11+
without sacrificing performance.
12+
[Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-common-terms-query.html)
13+
`);
14+
15+
if (false) {
16+
return getOrSetType(name, () =>
17+
InputTypeComposer.create({
18+
name,
19+
description,
20+
fields: {},
21+
}));
22+
}
23+
24+
// $FlowFixMe
25+
return {
26+
type: 'JSON',
27+
description,
28+
};
29+
}

src/ElasticDSL/Query/Match.js renamed to src/ElasticDSL/Query/FullText/Match.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/* @flow */
22

33
import { InputTypeComposer } from 'graphql-compose';
4-
import { getTypeName, getOrSetType, desc } from '../../utils';
4+
import { getTypeName, getOrSetType, desc } from '../../../utils';
55

66
export function getMatchITC(opts: mixed = {}): InputTypeComposer {
77
const name = getTypeName('QueryTerm', opts);
88
const description = desc(`
9-
Match Query accept text/numerics/dates, analyzes them, and constructs a query.
9+
Match Query accept text/numerics/dates, analyzes them, and constructs a query.
1010
[Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html)
1111
`);
1212

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* @flow */
2+
3+
import { InputTypeComposer } from 'graphql-compose';
4+
import { getTypeName, getOrSetType, desc } from '../../../utils';
5+
6+
export function getMatchPhraseITC(opts: mixed = {}): InputTypeComposer {
7+
const name = getTypeName('QueryMatchPhrase', opts);
8+
const description = desc(`
9+
The match_phrase query analyzes the text and creates a phrase query out
10+
of the analyzed text.
11+
[Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query-phrase.html)
12+
`);
13+
14+
if (false) {
15+
return getOrSetType(name, () =>
16+
InputTypeComposer.create({
17+
name,
18+
description,
19+
fields: {},
20+
}));
21+
}
22+
23+
// $FlowFixMe
24+
return {
25+
type: 'JSON',
26+
description,
27+
};
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* @flow */
2+
3+
import { InputTypeComposer } from 'graphql-compose';
4+
import { getTypeName, getOrSetType, desc } from '../../../utils';
5+
6+
export function getMatchPhrasePrefixITC(opts: mixed = {}): InputTypeComposer {
7+
const name = getTypeName('QueryMatchPhrasePrefix', opts);
8+
const description = desc(`
9+
The match_phrase_prefix is the same as match_phrase, except that it allows
10+
for prefix matches on the last term in the text. Eg "quick brown f"
11+
[Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query-phrase-prefix.html)
12+
`);
13+
14+
if (false) {
15+
return getOrSetType(name, () =>
16+
InputTypeComposer.create({
17+
name,
18+
description,
19+
fields: {},
20+
}));
21+
}
22+
23+
// $FlowFixMe
24+
return {
25+
type: 'JSON',
26+
description,
27+
};
28+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* @flow */
2+
3+
import { InputTypeComposer } from 'graphql-compose';
4+
import { getTypeName, getOrSetType, desc } from '../../../utils';
5+
6+
export function getMultiMatchITC(opts: mixed = {}): InputTypeComposer {
7+
const name = getTypeName('QueryMultiMatch', opts);
8+
const description = desc(`
9+
The multi_match query builds on the match query to allow multi-field queries.
10+
[Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html)
11+
`);
12+
13+
return getOrSetType(name, () =>
14+
// $FlowFixMe
15+
InputTypeComposer.create({
16+
name,
17+
description,
18+
fields: {
19+
query: 'String!',
20+
fields: {
21+
type: '[String]!',
22+
description: desc(`
23+
Array of fields [ "title", "*_name", "subject^3" ].
24+
You may use wildcards and boosting field.
25+
`),
26+
},
27+
type: `enum ${getTypeName('QueryMultiMatchTypeEnum', opts)} {
28+
best_fields
29+
most_fields
30+
cross_fields
31+
phrase
32+
phrase_prefix
33+
}`,
34+
operator: `enum ${getTypeName('QueryMultiMatchOperatorEnum', opts)} {
35+
and
36+
or
37+
}`,
38+
minimum_should_match: 'String',
39+
analyzer: 'String',
40+
},
41+
}));
42+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/* @flow */
2+
3+
import { InputTypeComposer } from 'graphql-compose';
4+
import { getTypeName, getOrSetType, desc } from '../../../utils';
5+
6+
export function getQueryStringITC(opts: mixed = {}): InputTypeComposer {
7+
const name = getTypeName('QueryQueryString', opts);
8+
const description = desc(`
9+
A query that uses a query parser in order to parse its content.
10+
Eg. "this AND that OR thus" or "(content:this OR name:this) AND (content:that OR name:that)"
11+
[Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html)
12+
`);
13+
14+
return getOrSetType(name, () =>
15+
// $FlowFixMe
16+
InputTypeComposer.create({
17+
name,
18+
description,
19+
fields: {
20+
query: 'String!',
21+
fields: '[String]',
22+
default_field: 'String',
23+
default_operator: `enum ${getTypeName('QueryQueryStringOperatorEnum', opts)} {
24+
and
25+
or
26+
}`,
27+
analyzer: 'String',
28+
allow_leading_wildcard: 'Boolean',
29+
enable_position_increments: 'Boolean',
30+
fuzzy_max_expansions: 'Int',
31+
fuzziness: 'String',
32+
fuzzy_prefix_length: 'Int',
33+
phrase_slop: 'Int',
34+
boost: 'Float',
35+
auto_generate_phrase_queries: 'Boolean',
36+
analyze_wildcard: 'Boolean',
37+
max_determinized_states: 'Int',
38+
minimum_should_match: 'String',
39+
lenient: 'Boolean',
40+
time_zone: 'String',
41+
quote_field_suffix: 'String',
42+
split_on_whitespace: 'Boolean',
43+
use_dis_max: 'Boolean',
44+
tie_breaker: 'Int',
45+
},
46+
}));
47+
}

0 commit comments

Comments
 (0)