-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
/
defaultGraphQLTypes.js
1375 lines (1256 loc) · 38.4 KB
/
defaultGraphQLTypes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import {
Kind,
GraphQLNonNull,
GraphQLScalarType,
GraphQLID,
GraphQLString,
GraphQLObjectType,
GraphQLInterfaceType,
GraphQLEnumType,
GraphQLInt,
GraphQLFloat,
GraphQLList,
GraphQLInputObjectType,
GraphQLBoolean,
GraphQLUnionType,
} from 'graphql';
import { GraphQLUpload } from 'graphql-upload';
class TypeValidationError extends Error {
constructor(value, type) {
super(`${value} is not a valid ${type}`);
}
}
const parseStringValue = value => {
if (typeof value === 'string') {
return value;
}
throw new TypeValidationError(value, 'String');
};
const parseIntValue = value => {
if (typeof value === 'string') {
const int = Number(value);
if (Number.isInteger(int)) {
return int;
}
}
throw new TypeValidationError(value, 'Int');
};
const parseFloatValue = value => {
if (typeof value === 'string') {
const float = Number(value);
if (!isNaN(float)) {
return float;
}
}
throw new TypeValidationError(value, 'Float');
};
const parseBooleanValue = value => {
if (typeof value === 'boolean') {
return value;
}
throw new TypeValidationError(value, 'Boolean');
};
const parseValue = value => {
switch (value.kind) {
case Kind.STRING:
return parseStringValue(value.value);
case Kind.INT:
return parseIntValue(value.value);
case Kind.FLOAT:
return parseFloatValue(value.value);
case Kind.BOOLEAN:
return parseBooleanValue(value.value);
case Kind.LIST:
return parseListValues(value.values);
case Kind.OBJECT:
return parseObjectFields(value.fields);
default:
return value.value;
}
};
const parseListValues = values => {
if (Array.isArray(values)) {
return values.map(value => parseValue(value));
}
throw new TypeValidationError(values, 'List');
};
const parseObjectFields = fields => {
if (Array.isArray(fields)) {
return fields.reduce(
(object, field) => ({
...object,
[field.name.value]: parseValue(field.value),
}),
{}
);
}
throw new TypeValidationError(fields, 'Object');
};
const ANY = new GraphQLScalarType({
name: 'Any',
description:
'The Any scalar type is used in operations and types that involve any type of value.',
parseValue: value => value,
serialize: value => value,
parseLiteral: ast => parseValue(ast),
});
const OBJECT = new GraphQLScalarType({
name: 'Object',
description:
'The Object scalar type is used in operations and types that involve objects.',
parseValue(value) {
if (typeof value === 'object') {
return value;
}
throw new TypeValidationError(value, 'Object');
},
serialize(value) {
if (typeof value === 'object') {
return value;
}
throw new TypeValidationError(value, 'Object');
},
parseLiteral(ast) {
if (ast.kind === Kind.OBJECT) {
return parseObjectFields(ast.fields);
}
throw new TypeValidationError(ast.kind, 'Object');
},
});
const parseDateIsoValue = value => {
if (typeof value === 'string') {
const date = new Date(value);
if (!isNaN(date)) {
return date;
}
} else if (value instanceof Date) {
return value;
}
throw new TypeValidationError(value, 'Date');
};
const serializeDateIso = value => {
if (typeof value === 'string') {
return value;
}
if (value instanceof Date) {
return value.toUTCString();
}
throw new TypeValidationError(value, 'Date');
};
const parseDateIsoLiteral = ast => {
if (ast.kind === Kind.STRING) {
return parseDateIsoValue(ast.value);
}
throw new TypeValidationError(ast.kind, 'Date');
};
const DATE = new GraphQLScalarType({
name: 'Date',
description:
'The Date scalar type is used in operations and types that involve dates.',
parseValue(value) {
if (typeof value === 'string' || value instanceof Date) {
return {
__type: 'Date',
iso: parseDateIsoValue(value),
};
} else if (
typeof value === 'object' &&
value.__type === 'Date' &&
value.iso
) {
return {
__type: value.__type,
iso: parseDateIsoValue(value.iso),
};
}
throw new TypeValidationError(value, 'Date');
},
serialize(value) {
if (typeof value === 'string' || value instanceof Date) {
return serializeDateIso(value);
} else if (
typeof value === 'object' &&
value.__type === 'Date' &&
value.iso
) {
return serializeDateIso(value.iso);
}
throw new TypeValidationError(value, 'Date');
},
parseLiteral(ast) {
if (ast.kind === Kind.STRING) {
return {
__type: 'Date',
iso: parseDateIsoLiteral(ast),
};
} else if (ast.kind === Kind.OBJECT) {
const __type = ast.fields.find(field => field.name.value === '__type');
const iso = ast.fields.find(field => field.name.value === 'iso');
if (__type && __type.value && __type.value.value === 'Date' && iso) {
return {
__type: __type.value.value,
iso: parseDateIsoLiteral(iso.value),
};
}
}
throw new TypeValidationError(ast.kind, 'Date');
},
});
const BYTES = new GraphQLScalarType({
name: 'Bytes',
description:
'The Bytes scalar type is used in operations and types that involve base 64 binary data.',
parseValue(value) {
if (typeof value === 'string') {
return {
__type: 'Bytes',
base64: value,
};
} else if (
typeof value === 'object' &&
value.__type === 'Bytes' &&
typeof value.base64 === 'string'
) {
return value;
}
throw new TypeValidationError(value, 'Bytes');
},
serialize(value) {
if (typeof value === 'string') {
return value;
} else if (
typeof value === 'object' &&
value.__type === 'Bytes' &&
typeof value.base64 === 'string'
) {
return value.base64;
}
throw new TypeValidationError(value, 'Bytes');
},
parseLiteral(ast) {
if (ast.kind === Kind.STRING) {
return {
__type: 'Bytes',
base64: ast.value,
};
} else if (ast.kind === Kind.OBJECT) {
const __type = ast.fields.find(field => field.name.value === '__type');
const base64 = ast.fields.find(field => field.name.value === 'base64');
if (
__type &&
__type.value &&
__type.value.value === 'Bytes' &&
base64 &&
base64.value &&
typeof base64.value.value === 'string'
) {
return {
__type: __type.value.value,
base64: base64.value.value,
};
}
}
throw new TypeValidationError(ast.kind, 'Bytes');
},
});
const parseFileValue = value => {
if (typeof value === 'string') {
return {
__type: 'File',
name: value,
};
} else if (
typeof value === 'object' &&
value.__type === 'File' &&
typeof value.name === 'string' &&
(value.url === undefined || typeof value.url === 'string')
) {
return value;
}
throw new TypeValidationError(value, 'File');
};
const FILE = new GraphQLScalarType({
name: 'File',
description:
'The File scalar type is used in operations and types that involve files.',
parseValue: parseFileValue,
serialize: value => {
if (typeof value === 'string') {
return value;
} else if (
typeof value === 'object' &&
value.__type === 'File' &&
typeof value.name === 'string' &&
(value.url === undefined || typeof value.url === 'string')
) {
return value.name;
}
throw new TypeValidationError(value, 'File');
},
parseLiteral(ast) {
if (ast.kind === Kind.STRING) {
return parseFileValue(ast.value);
} else if (ast.kind === Kind.OBJECT) {
const __type = ast.fields.find(field => field.name.value === '__type');
const name = ast.fields.find(field => field.name.value === 'name');
const url = ast.fields.find(field => field.name.value === 'url');
if (__type && __type.value && name && name.value) {
return parseFileValue({
__type: __type.value.value,
name: name.value.value,
url: url && url.value ? url.value.value : undefined,
});
}
}
throw new TypeValidationError(ast.kind, 'File');
},
});
const FILE_INFO = new GraphQLObjectType({
name: 'FileInfo',
description:
'The FileInfo object type is used to return the information about files.',
fields: {
name: {
description: 'This is the file name.',
type: new GraphQLNonNull(GraphQLString),
},
url: {
description: 'This is the url in which the file can be downloaded.',
type: new GraphQLNonNull(GraphQLString),
},
},
});
const GEO_POINT_FIELDS = {
latitude: {
description: 'This is the latitude.',
type: new GraphQLNonNull(GraphQLFloat),
},
longitude: {
description: 'This is the longitude.',
type: new GraphQLNonNull(GraphQLFloat),
},
};
const GEO_POINT_INPUT = new GraphQLInputObjectType({
name: 'GeoPointInput',
description:
'The GeoPointInput type is used in operations that involve inputting fields of type geo point.',
fields: GEO_POINT_FIELDS,
});
const GEO_POINT = new GraphQLObjectType({
name: 'GeoPoint',
description:
'The GeoPoint object type is used to return the information about geo point fields.',
fields: GEO_POINT_FIELDS,
});
const POLYGON_INPUT = new GraphQLList(new GraphQLNonNull(GEO_POINT_INPUT));
const POLYGON = new GraphQLList(new GraphQLNonNull(GEO_POINT));
const USER_ACL_INPUT = new GraphQLInputObjectType({
name: 'UserACLInput',
description: 'Allow to manage users in ACL.',
fields: {
userId: {
description: 'ID of the targetted User.',
type: new GraphQLNonNull(GraphQLID),
},
read: {
description: 'Allow the user to read the current object.',
type: new GraphQLNonNull(GraphQLBoolean),
},
write: {
description: 'Allow the user to write on the current object.',
type: new GraphQLNonNull(GraphQLBoolean),
},
},
});
const ROLE_ACL_INPUT = new GraphQLInputObjectType({
name: 'RoleACLInput',
description: 'Allow to manage roles in ACL.',
fields: {
roleName: {
description: 'Name of the targetted Role.',
type: new GraphQLNonNull(GraphQLString),
},
read: {
description:
'Allow users who are members of the role to read the current object.',
type: new GraphQLNonNull(GraphQLBoolean),
},
write: {
description:
'Allow users who are members of the role to write on the current object.',
type: new GraphQLNonNull(GraphQLBoolean),
},
},
});
const PUBLIC_ACL_INPUT = new GraphQLInputObjectType({
name: 'PublicACLInput',
description: 'Allow to manage public rights.',
fields: {
read: {
description: 'Allow anyone to read the current object.',
type: new GraphQLNonNull(GraphQLBoolean),
},
write: {
description: 'Allow anyone to write on the current object.',
type: new GraphQLNonNull(GraphQLBoolean),
},
},
});
const ACL_INPUT = new GraphQLInputObjectType({
name: 'ACLInput',
description:
'Allow to manage access rights. If not provided object will be publicly readable and writable',
fields: {
users: {
description: 'Access control list for users.',
type: new GraphQLList(new GraphQLNonNull(USER_ACL_INPUT)),
},
roles: {
description: 'Access control list for roles.',
type: new GraphQLList(new GraphQLNonNull(ROLE_ACL_INPUT)),
},
public: {
description: 'Public access control list.',
type: PUBLIC_ACL_INPUT,
},
},
});
const USER_ACL = new GraphQLObjectType({
name: 'UserACL',
description:
'Allow to manage users in ACL. If read and write are null the users have read and write rights.',
fields: {
userId: {
description: 'ID of the targetted User.',
type: new GraphQLNonNull(GraphQLID),
},
read: {
description: 'Allow the user to read the current object.',
type: new GraphQLNonNull(GraphQLBoolean),
},
write: {
description: 'Allow the user to write on the current object.',
type: new GraphQLNonNull(GraphQLBoolean),
},
},
});
const ROLE_ACL = new GraphQLObjectType({
name: 'RoleACL',
description:
'Allow to manage roles in ACL. If read and write are null the role have read and write rights.',
fields: {
roleName: {
description: 'Name of the targetted Role.',
type: new GraphQLNonNull(GraphQLID),
},
read: {
description:
'Allow users who are members of the role to read the current object.',
type: new GraphQLNonNull(GraphQLBoolean),
},
write: {
description:
'Allow users who are members of the role to write on the current object.',
type: new GraphQLNonNull(GraphQLBoolean),
},
},
});
const PUBLIC_ACL = new GraphQLObjectType({
name: 'PublicACL',
description: 'Allow to manage public rights.',
fields: {
read: {
description: 'Allow anyone to read the current object.',
type: GraphQLBoolean,
},
write: {
description: 'Allow anyone to write on the current object.',
type: GraphQLBoolean,
},
},
});
const ACL = new GraphQLObjectType({
name: 'ACL',
description: 'Current access control list of the current object.',
fields: {
users: {
description: 'Access control list for users.',
type: new GraphQLList(new GraphQLNonNull(USER_ACL)),
resolve(p) {
const users = [];
Object.keys(p).forEach(rule => {
if (rule !== '*' && rule.indexOf('role:') !== 0) {
users.push({
userId: rule,
read: p[rule].read ? true : false,
write: p[rule].write ? true : false,
});
}
});
return users.length ? users : null;
},
},
roles: {
description: 'Access control list for roles.',
type: new GraphQLList(new GraphQLNonNull(ROLE_ACL)),
resolve(p) {
const roles = [];
Object.keys(p).forEach(rule => {
if (rule.indexOf('role:') === 0) {
roles.push({
roleName: rule.replace('role:', ''),
read: p[rule].read ? true : false,
write: p[rule].write ? true : false,
});
}
});
return roles.length ? roles : null;
},
},
public: {
description: 'Public access control list.',
type: PUBLIC_ACL,
resolve(p) {
/* eslint-disable */
return p['*']
? {
read: p['*'].read ? true : false,
write: p['*'].write ? true : false,
}
: null;
},
},
},
});
const OBJECT_ID = new GraphQLNonNull(GraphQLID);
const CLASS_NAME_ATT = {
description: 'This is the class name of the object.',
type: new GraphQLNonNull(GraphQLString),
};
const GLOBAL_OR_OBJECT_ID_ATT = {
description:
'This is the object id. You can use either the global or the object id.',
type: OBJECT_ID,
};
const OBJECT_ID_ATT = {
description: 'This is the object id.',
type: OBJECT_ID,
};
const CREATED_AT_ATT = {
description: 'This is the date in which the object was created.',
type: new GraphQLNonNull(DATE),
};
const UPDATED_AT_ATT = {
description: 'This is the date in which the object was las updated.',
type: new GraphQLNonNull(DATE),
};
const INPUT_FIELDS = {
ACL: {
type: ACL,
},
};
const CREATE_RESULT_FIELDS = {
objectId: OBJECT_ID_ATT,
createdAt: CREATED_AT_ATT,
};
const UPDATE_RESULT_FIELDS = {
updatedAt: UPDATED_AT_ATT,
};
const PARSE_OBJECT_FIELDS = {
...CREATE_RESULT_FIELDS,
...UPDATE_RESULT_FIELDS,
...INPUT_FIELDS,
ACL: {
type: new GraphQLNonNull(ACL),
resolve: ({ ACL }) => (ACL ? ACL : { '*': { read: true, write: true } }),
},
};
const PARSE_OBJECT = new GraphQLInterfaceType({
name: 'ParseObject',
description:
'The ParseObject interface type is used as a base type for the auto generated object types.',
fields: PARSE_OBJECT_FIELDS,
});
const SESSION_TOKEN_ATT = {
description: 'The current user session token.',
type: new GraphQLNonNull(GraphQLString),
};
const READ_PREFERENCE = new GraphQLEnumType({
name: 'ReadPreference',
description:
'The ReadPreference enum type is used in queries in order to select in which database replica the operation must run.',
values: {
PRIMARY: { value: 'PRIMARY' },
PRIMARY_PREFERRED: { value: 'PRIMARY_PREFERRED' },
SECONDARY: { value: 'SECONDARY' },
SECONDARY_PREFERRED: { value: 'SECONDARY_PREFERRED' },
NEAREST: { value: 'NEAREST' },
},
});
const READ_PREFERENCE_ATT = {
description: 'The read preference for the main query to be executed.',
type: READ_PREFERENCE,
};
const INCLUDE_READ_PREFERENCE_ATT = {
description:
'The read preference for the queries to be executed to include fields.',
type: READ_PREFERENCE,
};
const SUBQUERY_READ_PREFERENCE_ATT = {
description: 'The read preference for the subqueries that may be required.',
type: READ_PREFERENCE,
};
const READ_OPTIONS_INPUT = new GraphQLInputObjectType({
name: 'ReadOptionsInput',
description:
'The ReadOptionsInputt type is used in queries in order to set the read preferences.',
fields: {
readPreference: READ_PREFERENCE_ATT,
includeReadPreference: INCLUDE_READ_PREFERENCE_ATT,
subqueryReadPreference: SUBQUERY_READ_PREFERENCE_ATT,
},
});
const READ_OPTIONS_ATT = {
description: 'The read options for the query to be executed.',
type: READ_OPTIONS_INPUT,
};
const WHERE_ATT = {
description:
'These are the conditions that the objects need to match in order to be found',
type: OBJECT,
};
const SKIP_ATT = {
description: 'This is the number of objects that must be skipped to return.',
type: GraphQLInt,
};
const LIMIT_ATT = {
description: 'This is the limit number of objects that must be returned.',
type: GraphQLInt,
};
const COUNT_ATT = {
description:
'This is the total matched objecs count that is returned when the count flag is set.',
type: new GraphQLNonNull(GraphQLInt),
};
const SEARCH_INPUT = new GraphQLInputObjectType({
name: 'SearchInput',
description:
'The SearchInput type is used to specifiy a search operation on a full text search.',
fields: {
term: {
description: 'This is the term to be searched.',
type: new GraphQLNonNull(GraphQLString),
},
language: {
description:
'This is the language to tetermine the list of stop words and the rules for tokenizer.',
type: GraphQLString,
},
caseSensitive: {
description:
'This is the flag to enable or disable case sensitive search.',
type: GraphQLBoolean,
},
diacriticSensitive: {
description:
'This is the flag to enable or disable diacritic sensitive search.',
type: GraphQLBoolean,
},
},
});
const TEXT_INPUT = new GraphQLInputObjectType({
name: 'TextInput',
description:
'The TextInput type is used to specify a text operation on a constraint.',
fields: {
search: {
description: 'This is the search to be executed.',
type: new GraphQLNonNull(SEARCH_INPUT),
},
},
});
const BOX_INPUT = new GraphQLInputObjectType({
name: 'BoxInput',
description:
'The BoxInput type is used to specifiy a box operation on a within geo query.',
fields: {
bottomLeft: {
description: 'This is the bottom left coordinates of the box.',
type: new GraphQLNonNull(GEO_POINT_INPUT),
},
upperRight: {
description: 'This is the upper right coordinates of the box.',
type: new GraphQLNonNull(GEO_POINT_INPUT),
},
},
});
const WITHIN_INPUT = new GraphQLInputObjectType({
name: 'WithinInput',
description:
'The WithinInput type is used to specify a within operation on a constraint.',
fields: {
box: {
description: 'This is the box to be specified.',
type: new GraphQLNonNull(BOX_INPUT),
},
},
});
const CENTER_SPHERE_INPUT = new GraphQLInputObjectType({
name: 'CenterSphereInput',
description:
'The CenterSphereInput type is used to specifiy a centerSphere operation on a geoWithin query.',
fields: {
center: {
description: 'This is the center of the sphere.',
type: new GraphQLNonNull(GEO_POINT_INPUT),
},
distance: {
description: 'This is the radius of the sphere.',
type: new GraphQLNonNull(GraphQLFloat),
},
},
});
const GEO_WITHIN_INPUT = new GraphQLInputObjectType({
name: 'GeoWithinInput',
description:
'The GeoWithinInput type is used to specify a geoWithin operation on a constraint.',
fields: {
polygon: {
description: 'This is the polygon to be specified.',
type: POLYGON_INPUT,
},
centerSphere: {
description: 'This is the sphere to be specified.',
type: CENTER_SPHERE_INPUT,
},
},
});
const GEO_INTERSECTS_INPUT = new GraphQLInputObjectType({
name: 'GeoIntersectsInput',
description:
'The GeoIntersectsInput type is used to specify a geoIntersects operation on a constraint.',
fields: {
point: {
description: 'This is the point to be specified.',
type: GEO_POINT_INPUT,
},
},
});
const equalTo = type => ({
description:
'This is the equalTo operator to specify a constraint to select the objects where the value of a field equals to a specified value.',
type,
});
const notEqualTo = type => ({
description:
'This is the notEqualTo operator to specify a constraint to select the objects where the value of a field do not equal to a specified value.',
type,
});
const lessThan = type => ({
description:
'This is the lessThan operator to specify a constraint to select the objects where the value of a field is less than a specified value.',
type,
});
const lessThanOrEqualTo = type => ({
description:
'This is the lessThanOrEqualTo operator to specify a constraint to select the objects where the value of a field is less than or equal to a specified value.',
type,
});
const greaterThan = type => ({
description:
'This is the greaterThan operator to specify a constraint to select the objects where the value of a field is greater than a specified value.',
type,
});
const greaterThanOrEqualTo = type => ({
description:
'This is the greaterThanOrEqualTo operator to specify a constraint to select the objects where the value of a field is greater than or equal to a specified value.',
type,
});
const inOp = type => ({
description:
'This is the in operator to specify a constraint to select the objects where the value of a field equals any value in the specified array.',
type: new GraphQLList(type),
});
const notIn = type => ({
description:
'This is the notIn operator to specify a constraint to select the objects where the value of a field do not equal any value in the specified array.',
type: new GraphQLList(type),
});
const exists = {
description:
'This is the exists operator to specify a constraint to select the objects where a field exists (or do not exist).',
type: GraphQLBoolean,
};
const matchesRegex = {
description:
'This is the matchesRegex operator to specify a constraint to select the objects where the value of a field matches a specified regular expression.',
type: GraphQLString,
};
const options = {
description:
'This is the options operator to specify optional flags (such as "i" and "m") to be added to a matchesRegex operation in the same set of constraints.',
type: GraphQLString,
};
const SUBQUERY_INPUT = new GraphQLInputObjectType({
name: 'SubqueryInput',
description:
'The SubqueryInput type is used to specify a sub query to another class.',
fields: {
className: CLASS_NAME_ATT,
where: Object.assign({}, WHERE_ATT, {
type: new GraphQLNonNull(WHERE_ATT.type),
}),
},
});
const SELECT_INPUT = new GraphQLInputObjectType({
name: 'SelectInput',
description:
'The SelectInput type is used to specify an inQueryKey or a notInQueryKey operation on a constraint.',
fields: {
query: {
description: 'This is the subquery to be executed.',
type: new GraphQLNonNull(SUBQUERY_INPUT),
},
key: {
description:
'This is the key in the result of the subquery that must match (not match) the field.',
type: new GraphQLNonNull(GraphQLString),
},
},
});
const inQueryKey = {
description:
'This is the inQueryKey operator to specify a constraint to select the objects where a field equals to a key in the result of a different query.',
type: SELECT_INPUT,
};
const notInQueryKey = {
description:
'This is the notInQueryKey operator to specify a constraint to select the objects where a field do not equal to a key in the result of a different query.',
type: SELECT_INPUT,
};
const ID_WHERE_INPUT = new GraphQLInputObjectType({
name: 'IdWhereInput',
description:
'The IdWhereInput input type is used in operations that involve filtering objects by an id.',
fields: {
equalTo: equalTo(GraphQLID),
notEqualTo: notEqualTo(GraphQLID),
lessThan: lessThan(GraphQLID),
lessThanOrEqualTo: lessThanOrEqualTo(GraphQLID),
greaterThan: greaterThan(GraphQLID),
greaterThanOrEqualTo: greaterThanOrEqualTo(GraphQLID),
in: inOp(GraphQLID),
notIn: notIn(GraphQLID),
exists,
inQueryKey,
notInQueryKey,
},
});
const STRING_WHERE_INPUT = new GraphQLInputObjectType({
name: 'StringWhereInput',
description:
'The StringWhereInput input type is used in operations that involve filtering objects by a field of type String.',
fields: {
equalTo: equalTo(GraphQLString),
notEqualTo: notEqualTo(GraphQLString),
lessThan: lessThan(GraphQLString),
lessThanOrEqualTo: lessThanOrEqualTo(GraphQLString),
greaterThan: greaterThan(GraphQLString),
greaterThanOrEqualTo: greaterThanOrEqualTo(GraphQLString),
in: inOp(GraphQLString),
notIn: notIn(GraphQLString),
exists,
matchesRegex,
options,
text: {
description:
'This is the $text operator to specify a full text search constraint.',
type: TEXT_INPUT,
},
inQueryKey,
notInQueryKey,
},
});
const NUMBER_WHERE_INPUT = new GraphQLInputObjectType({
name: 'NumberWhereInput',
description:
'The NumberWhereInput input type is used in operations that involve filtering objects by a field of type Number.',
fields: {
equalTo: equalTo(GraphQLFloat),
notEqualTo: notEqualTo(GraphQLFloat),
lessThan: lessThan(GraphQLFloat),
lessThanOrEqualTo: lessThanOrEqualTo(GraphQLFloat),
greaterThan: greaterThan(GraphQLFloat),
greaterThanOrEqualTo: greaterThanOrEqualTo(GraphQLFloat),
in: inOp(GraphQLFloat),
notIn: notIn(GraphQLFloat),
exists,
inQueryKey,
notInQueryKey,
},
});
const BOOLEAN_WHERE_INPUT = new GraphQLInputObjectType({
name: 'BooleanWhereInput',
description: