-
-
Notifications
You must be signed in to change notification settings - Fork 796
/
handleList.ts
62 lines (56 loc) · 1.55 KB
/
handleList.ts
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
import {
GraphQLList,
GraphQLSchema,
GraphQLResolveInfo,
getNullableType,
GraphQLType,
isLeafType,
isCompositeType,
isListType,
} from 'graphql';
import { getErrorsByPathSegment, RelativeGraphQLError } from '@graphql-tools/utils';
import { handleNull } from './handleNull';
import { handleObject } from './handleObject';
import { SubschemaConfig } from '../types';
export function handleList(
type: GraphQLList<any>,
list: Array<any>,
errors: Array<RelativeGraphQLError>,
subschema: GraphQLSchema | SubschemaConfig,
context: Record<string, any>,
info: GraphQLResolveInfo,
skipTypeMerging?: boolean
) {
const childErrors = getErrorsByPathSegment(errors);
return list.map((listMember, index) =>
handleListMember(
getNullableType(type.ofType),
listMember,
index in childErrors ? childErrors[index] : [],
subschema,
context,
info,
skipTypeMerging
)
);
}
function handleListMember(
type: GraphQLType,
listMember: any,
errors: Array<RelativeGraphQLError>,
subschema: GraphQLSchema | SubschemaConfig,
context: Record<string, any>,
info: GraphQLResolveInfo,
skipTypeMerging?: boolean
): any {
if (listMember == null) {
return handleNull(errors);
}
if (isLeafType(type)) {
return type.parseValue(listMember);
} else if (isCompositeType(type)) {
return handleObject(type, listMember, errors, subschema, context, info, skipTypeMerging);
} else if (isListType(type)) {
return handleList(type, listMember, errors, subschema, context, info, skipTypeMerging);
}
}