-
-
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.
fix(QueryDSL): Beautifying and small refactoring
- Loading branch information
Showing
9 changed files
with
218 additions
and
86 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* @flow */ | ||
|
||
import { InputTypeComposer } from 'graphql-compose'; | ||
import { getTypeName, getOrSetType, desc } from '../../utils'; | ||
|
||
export function getMatchITC(opts: mixed = {}): InputTypeComposer { | ||
const name = getTypeName('QueryTerm', opts); | ||
const description = desc(` | ||
Match Query accept text/numerics/dates, analyzes them, and constructs a query. | ||
[Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html) | ||
`); | ||
|
||
if (false) { | ||
return getOrSetType(name, () => | ||
InputTypeComposer.create({ | ||
name, | ||
description, | ||
fields: {}, | ||
})); | ||
} | ||
|
||
// $FlowFixMe | ||
return { | ||
type: 'JSON', | ||
description, | ||
}; | ||
} |
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 |
---|---|---|
@@ -1,20 +1,25 @@ | ||
/* @flow */ | ||
|
||
import { InputTypeComposer } from 'graphql-compose'; | ||
import { getTypeName, getOrSetType } from '../../utils'; | ||
import { getTypeName, getOrSetType, desc } from '../../utils'; | ||
|
||
export function getMatchAllITC(opts = {}): InputTypeComposer { | ||
const typeName = getTypeName('QueryMatchAll', opts); | ||
export function getMatchAllITC(opts: mixed = {}): InputTypeComposer { | ||
const name = getTypeName('QueryMatchAll', opts); | ||
const description = desc(` | ||
The most simple query, which matches all documents, | ||
giving them all a _score of 1.0. | ||
`); | ||
|
||
return getOrSetType(typeName, () => { | ||
const MatchAllITC = InputTypeComposer.create(typeName); | ||
MatchAllITC.setDescription('The most simple query, which matches all documents, giving them all a _score of 1.0.'); | ||
MatchAllITC.setFields({ | ||
boost: { | ||
type: 'Float', | ||
return getOrSetType(name, () => | ||
// $FlowFixMe | ||
InputTypeComposer.create({ | ||
name, | ||
description, | ||
fields: { | ||
boost: { | ||
type: 'Float', | ||
}, | ||
}, | ||
}); | ||
|
||
return MatchAllITC; | ||
}); | ||
}) | ||
); | ||
} |
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,29 @@ | ||
/* @flow */ | ||
|
||
import { InputTypeComposer } from 'graphql-compose'; | ||
import { getTypeName, getOrSetType, desc } from '../../utils'; | ||
|
||
export function getTermITC(opts: mixed = {}): InputTypeComposer { | ||
const name = getTypeName('QueryTerm', opts); | ||
const description = desc(` | ||
Find documents which contain the exact term specified | ||
in the field specified. | ||
{ fieldName: value } or { fieldName: { value: value, boost: 2.0 } } | ||
[Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html) | ||
`); | ||
|
||
if (false) { | ||
return getOrSetType(name, () => | ||
InputTypeComposer.create({ | ||
name, | ||
description, | ||
fields: {}, | ||
})); | ||
} | ||
|
||
// $FlowFixMe | ||
return { | ||
type: 'JSON', | ||
description, | ||
}; | ||
} |
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,28 @@ | ||
/* @flow */ | ||
|
||
import { InputTypeComposer } from 'graphql-compose'; | ||
import { getTypeName, getOrSetType, desc } from '../../utils'; | ||
|
||
export function getTermsITC(opts: mixed = {}): InputTypeComposer { | ||
const name = getTypeName('QueryTerms', opts); | ||
const description = desc(` | ||
Filters documents that have fields that match any of | ||
the provided terms (not analyzed). { fieldName: [values] } | ||
[Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html) | ||
`); | ||
|
||
if (false) { | ||
return getOrSetType(name, () => | ||
InputTypeComposer.create({ | ||
name, | ||
description, | ||
fields: {}, | ||
})); | ||
} | ||
|
||
// $FlowFixMe | ||
return { | ||
type: 'JSON', | ||
description, | ||
}; | ||
} |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
/* @flow */ | ||
|
||
import { isFunction } from 'graphql-compose'; | ||
|
||
class TypeStorage extends Map { | ||
|
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 |
---|---|---|
@@ -1,9 +1,18 @@ | ||
/* @flow */ | ||
|
||
import typeStorage from './typeStorage'; | ||
|
||
export function getTypeName(name: string, opts: any): string { | ||
return `${opts && opts.prefix || 'Elastic'}${name}${opts && opts.postfix || ''}`; | ||
return `${(opts && opts.prefix) || 'Elastic'}${name}${(opts && opts.postfix) || ''}`; | ||
} | ||
|
||
export function getOrSetType<T>(typeName: string, typeOrThunk: (() => T) | T): T { | ||
// $FlowFixMe | ||
const type: T = typeStorage.getOrSet(typeName, typeOrThunk); | ||
return type; | ||
} | ||
|
||
export function getOrSetType<T>(typeName: string, typeOrThunk: T | () => T): T { | ||
return typeStorage.getOrSet(typeName, typeOrThunk); | ||
// Remove newline multiline in descriptions | ||
export function desc(str: string): string { | ||
return str.replace(/\n\s+/, ' '); | ||
} |