-
-
Notifications
You must be signed in to change notification settings - Fork 796
/
handleResult.ts
33 lines (27 loc) · 1.02 KB
/
handleResult.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
import { GraphQLResolveInfo, getNullableType, isCompositeType, isLeafType, isListType, GraphQLSchema } from 'graphql';
import { RelativeGraphQLError } from '@graphql-tools/utils';
import { SubschemaConfig } from '../types';
import { handleNull } from './handleNull';
import { handleObject } from './handleObject';
import { handleList } from './handleList';
export function handleResult(
result: any,
errors: Array<RelativeGraphQLError>,
subschema: GraphQLSchema | SubschemaConfig,
context: Record<string, any>,
info: GraphQLResolveInfo,
returnType = info.returnType,
skipTypeMerging?: boolean
): any {
const type = getNullableType(returnType);
if (result == null) {
return handleNull(errors);
}
if (isLeafType(type)) {
return type.parseValue(result);
} else if (isCompositeType(type)) {
return handleObject(type, result, errors, subschema, context, info, skipTypeMerging);
} else if (isListType(type)) {
return handleList(type, result, errors, subschema, context, info, skipTypeMerging);
}
}