Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c807f6
commit 9d8e7e2
Showing
20 changed files
with
367 additions
and
323 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
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,85 @@ | ||
import { | ||
GraphQLList, | ||
GraphQLSchema, | ||
GraphQLError, | ||
getNullableType, | ||
GraphQLType, | ||
responsePathAsArray, | ||
isLeafType, | ||
isCompositeType, | ||
isListType, | ||
} from 'graphql'; | ||
|
||
import { SubschemaConfig, IGraphQLToolsResolveInfo } from '../../Interfaces'; | ||
import { getErrorsByPathSegment } from '../../stitch/errors'; | ||
|
||
import { handleNull } from './handleNull'; | ||
import { handleObject } from './handleObject'; | ||
|
||
export function handleList( | ||
type: GraphQLList<any>, | ||
list: Array<any>, | ||
errors: ReadonlyArray<GraphQLError>, | ||
subschema: GraphQLSchema | SubschemaConfig, | ||
context: Record<string, any>, | ||
info: IGraphQLToolsResolveInfo, | ||
skipTypeMerging?: boolean, | ||
) { | ||
const childErrors = getErrorsByPathSegment(errors); | ||
|
||
return list.map((listMember, index) => | ||
handleListMember( | ||
getNullableType(type.ofType), | ||
listMember, | ||
index, | ||
childErrors[index] != null ? childErrors[index] : [], | ||
subschema, | ||
context, | ||
info, | ||
skipTypeMerging, | ||
), | ||
); | ||
} | ||
|
||
function handleListMember( | ||
type: GraphQLType, | ||
listMember: any, | ||
index: number, | ||
errors: ReadonlyArray<GraphQLError>, | ||
subschema: GraphQLSchema | SubschemaConfig, | ||
context: Record<string, any>, | ||
info: IGraphQLToolsResolveInfo, | ||
skipTypeMerging?: boolean, | ||
): any { | ||
if (listMember == null) { | ||
return handleNull( | ||
info.fieldNodes, | ||
[...responsePathAsArray(info.path), index], | ||
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, | ||
); | ||
} | ||
} |
Oops, something went wrong.