11/* @flow */
22
3- import { TypeComposer , InputTypeComposer , GraphQLJSON } from 'graphql-compose' ;
3+ import { TypeComposer , GraphQLJSON } from 'graphql-compose' ;
44
55import {
66 GraphQLString ,
@@ -14,10 +14,7 @@ import {
1414import {
1515 convertToSourceTC ,
1616 propertyToSourceGraphQLType ,
17- convertToAggregatableITC ,
1817 inputPropertiesToGraphQLTypes ,
19- convertToSearchableITC ,
20- convertToAnalyzedITC ,
2118 getSubFields ,
2219} from '../mappingConverter' ;
2320
@@ -173,7 +170,7 @@ describe('PropertiesConverter', () => {
173170 describe ( 'inputPropertiesToGraphQLTypes()' , ( ) => {
174171 it ( 'should throw error on incorrect prop' , ( ) => {
175172 expect ( ( ) => {
176- inputPropertiesToGraphQLTypes ( { } , ( ) => true ) ;
173+ inputPropertiesToGraphQLTypes ( { } ) ;
177174 } ) . toThrowError ( 'incorrect Elastic property config' ) ;
178175 } ) ;
179176
@@ -182,35 +179,31 @@ describe('PropertiesConverter', () => {
182179 {
183180 type : 'text' ,
184181 } ,
185- ( ) => true ,
186182 'lastname'
187183 ) ;
188184 expect ( fields . _all . lastname ) . toEqual ( GraphQLString ) ;
189185 expect ( fields . text . lastname ) . toEqual ( GraphQLString ) ;
190186 } ) ;
191187
192188 it ( 'should accept mapping' , ( ) => {
193- const fields = inputPropertiesToGraphQLTypes ( mapping , ( ) => true ) ;
189+ const fields = inputPropertiesToGraphQLTypes ( mapping ) ;
194190 expect ( Object . keys ( fields . _all ) . length ) . toBeGreaterThan ( 2 ) ;
195191 } ) ;
196192
197193 it ( 'should convert nested fields' , ( ) => {
198- const fields = inputPropertiesToGraphQLTypes (
199- {
200- properties : {
201- name : {
202- type : 'text' ,
203- fields : {
204- keyword : {
205- type : 'keyword' ,
206- ignore_above : 256 ,
207- } ,
194+ const fields = inputPropertiesToGraphQLTypes ( {
195+ properties : {
196+ name : {
197+ type : 'text' ,
198+ fields : {
199+ keyword : {
200+ type : 'keyword' ,
201+ ignore_above : 256 ,
208202 } ,
209203 } ,
210204 } ,
211205 } ,
212- ( ) => true
213- ) ;
206+ } ) ;
214207 expect ( Object . keys ( fields . _all ) . length ) . toEqual ( 2 ) ;
215208 expect ( Object . keys ( fields . _all ) ) . toEqual (
216209 expect . arrayContaining ( [ 'name' , 'name__keyword' ] )
@@ -223,53 +216,18 @@ describe('PropertiesConverter', () => {
223216 ) ;
224217 } ) ;
225218
226- it ( 'should use filterFn' , ( ) => {
227- const fields = inputPropertiesToGraphQLTypes (
228- {
229- properties : {
230- name : {
231- type : 'text' ,
232- fields : {
233- keyword : {
234- type : 'keyword' ,
235- ignore_above : 256 ,
236- } ,
237- } ,
238- } ,
239- } ,
240- } ,
241- prop => prop . type !== 'text'
242- ) ;
243- expect ( Object . keys ( fields . _all ) . length ) . toEqual ( 1 ) ;
244- expect ( Object . keys ( fields . _all ) ) . toEqual (
245- expect . arrayContaining ( [ 'name__keyword' ] )
246- ) ;
247- expect ( Object . keys ( fields . keyword ) . length ) . toEqual ( 1 ) ;
248- expect ( Object . keys ( fields . keyword ) ) . toEqual (
249- expect . arrayContaining ( [ 'name__keyword' ] )
250- ) ;
251- } ) ;
252-
253219 it ( 'should not return index:false fields' , ( ) => {
254- const itc = convertToSearchableITC ( mapping , 'SearchInput' ) ;
255- expect ( itc . getFieldNames ( ) ) . not . toEqual (
256- expect . arrayContaining ( [ 'noIndex' ] )
257- ) ;
258-
259- const fields = inputPropertiesToGraphQLTypes (
260- {
261- properties : {
262- name : {
263- type : 'text' ,
264- index : false ,
265- } ,
266- date : {
267- type : 'date' ,
268- } ,
220+ const fields = inputPropertiesToGraphQLTypes ( {
221+ properties : {
222+ name : {
223+ type : 'text' ,
224+ index : false ,
225+ } ,
226+ date : {
227+ type : 'date' ,
269228 } ,
270229 } ,
271- prop => prop . type !== 'text'
272- ) ;
230+ } ) ;
273231 expect ( Object . keys ( fields . _all ) . length ) . toEqual ( 1 ) ;
274232 expect ( Object . keys ( fields . _all ) ) . toEqual (
275233 expect . arrayContaining ( [ 'date' ] )
@@ -281,116 +239,6 @@ describe('PropertiesConverter', () => {
281239 } ) ;
282240 } ) ;
283241
284- describe ( 'convertToAggregatableITC()' , ( ) => {
285- it ( 'should throw error on empty mapping' , ( ) => {
286- // $FlowFixMe
287- expect ( ( ) => convertToAggregatableITC ( ) ) . toThrowError (
288- 'incorrect mapping'
289- ) ;
290- } ) ;
291-
292- it ( 'should throw error on empty typeName' , ( ) => {
293- expect ( ( ) => {
294- // $FlowFixMe
295- convertToAggregatableITC ( mapping ) ;
296- } ) . toThrowError ( 'empty name' ) ;
297- } ) ;
298-
299- it ( 'should return InputTypeComposer' , ( ) => {
300- const itc = convertToAggregatableITC ( mapping , 'AggsInput' ) ;
301- expect ( itc ) . toBeInstanceOf ( InputTypeComposer ) ;
302- expect ( itc . getTypeName ( ) ) . toBe ( 'AggsInput' ) ;
303- expect ( itc . getFieldNames ( ) . length ) . toBeGreaterThan ( 1 ) ;
304- } ) ;
305-
306- it ( 'should return array of aggregatable fields' , ( ) => {
307- const itc = convertToAggregatableITC ( mapping , 'AggsInput' ) ;
308- expect ( itc . getFieldNames ( ) ) . toEqual (
309- expect . arrayContaining ( [
310- 'name__keyword' ,
311- 'birthday' ,
312- 'avatarUrl__thumb__keyword' ,
313- ] )
314- ) ;
315- } ) ;
316-
317- it ( 'should not return text fields' , ( ) => {
318- const itc = convertToAggregatableITC ( mapping , 'AggsInput' ) ;
319- expect ( itc . getFieldNames ( ) ) . not . toEqual (
320- expect . arrayContaining ( [ 'lastname' ] )
321- ) ;
322- } ) ;
323- } ) ;
324-
325- describe ( 'convertToSearchableITC()' , ( ) => {
326- it ( 'should throw error on empty mapping' , ( ) => {
327- // $FlowFixMe
328- expect ( ( ) => convertToSearchableITC ( ) ) . toThrowError ( 'incorrect mapping' ) ;
329- } ) ;
330-
331- it ( 'should throw error on empty typeName' , ( ) => {
332- expect ( ( ) => {
333- // $FlowFixMe
334- convertToSearchableITC ( mapping ) ;
335- } ) . toThrowError ( 'empty name' ) ;
336- } ) ;
337-
338- it ( 'should return InputTypeComposer' , ( ) => {
339- const itc = convertToSearchableITC ( mapping , 'SearchInput' ) ;
340- expect ( itc ) . toBeInstanceOf ( InputTypeComposer ) ;
341- expect ( itc . getTypeName ( ) ) . toBe ( 'SearchInput' ) ;
342- expect ( itc . getFieldNames ( ) . length ) . toBeGreaterThan ( 1 ) ;
343- } ) ;
344-
345- it ( 'should return array of searchable fields' , ( ) => {
346- const itc = convertToSearchableITC ( mapping , 'SearchInput' ) ;
347- expect ( itc . getFieldNames ( ) ) . toEqual (
348- expect . arrayContaining ( [
349- 'name__keyword' ,
350- 'name' ,
351- 'avatarUrl__big' ,
352- 'avatarUrl__thumb__keyword' ,
353- 'avatarUrl__thumb' ,
354- 'lastname' ,
355- 'birthday' ,
356- ] )
357- ) ;
358- } ) ;
359- } ) ;
360-
361- describe ( 'convertToAnalyzedITC()' , ( ) => {
362- it ( 'should throw error on empty mapping' , ( ) => {
363- // $FlowFixMe
364- expect ( ( ) => convertToAnalyzedITC ( ) ) . toThrowError ( 'incorrect mapping' ) ;
365- } ) ;
366-
367- it ( 'should throw error on empty typeName' , ( ) => {
368- expect ( ( ) => {
369- // $FlowFixMe
370- convertToAnalyzedITC ( mapping ) ;
371- } ) . toThrowError ( 'empty name' ) ;
372- } ) ;
373-
374- it ( 'should return InputTypeComposer' , ( ) => {
375- const itc = convertToAnalyzedITC ( mapping , 'AnalyzedInput' ) ;
376- expect ( itc ) . toBeInstanceOf ( InputTypeComposer ) ;
377- expect ( itc . getTypeName ( ) ) . toBe ( 'AnalyzedInput' ) ;
378- expect ( itc . getFieldNames ( ) . length ) . toBeGreaterThan ( 1 ) ;
379- } ) ;
380-
381- it ( 'should return array of searchable fields' , ( ) => {
382- const itc = convertToAnalyzedITC ( mapping , 'AnalyzedInput' ) ;
383- expect ( itc . getFieldNames ( ) ) . toEqual (
384- expect . arrayContaining ( [
385- 'name' ,
386- 'avatarUrl__big' ,
387- 'avatarUrl__thumb' ,
388- 'lastname' ,
389- ] )
390- ) ;
391- } ) ;
392- } ) ;
393-
394242 describe ( 'getSubFields()' , ( ) => {
395243 it ( 'should return array of sub fields' , ( ) => {
396244 expect (
0 commit comments