Skip to content
This repository has been archived by the owner on Apr 15, 2020. It is now read-only.

Commit

Permalink
fix(stitching): support stitching unions of types with enums
Browse files Browse the repository at this point in the history
Closes #13.
  • Loading branch information
yaacovCR committed Sep 22, 2019
1 parent a367edf commit faae86a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/stitching/checkResultAndHandleErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import {
GraphQLResolveInfo,
responsePathAsArray,
getNullableType,
isObjectType,
isCompositeType,
isLeafType,
isListType,
isEnumType,
isScalarType,
ExecutionResult,
GraphQLError,
GraphQLType,
Expand Down Expand Up @@ -60,7 +59,7 @@ export function handleResult(

const nullableType = getNullableType(info.returnType);

if (isObjectType(nullableType) || isListType(nullableType)) {
if (isCompositeType(nullableType) || isListType(nullableType)) {
annotateWithChildrenErrors(result, errors);
}

Expand All @@ -70,7 +69,7 @@ export function handleResult(
function parseOutputValue(type: GraphQLType, value: any) {
if (isListType(type)) {
return value.map((v: any) => parseOutputValue(getNullableType(type.ofType), v));
} else if (isEnumType(type) || isScalarType(type)) {
} else if (isLeafType(type)) {
return type.parseValue(value);
}
return value;
Expand Down
28 changes: 28 additions & 0 deletions src/test/testMergeSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ let enumTest = `
numericEnum: NumericEnum
}
union UnionWithEnum = EnumWrapper
schema {
query: Query
}
Expand All @@ -139,6 +141,7 @@ let enumTest = `
numericEnum: NumericEnum
listNumericEnum: [NumericEnum]
wrappedEnum: EnumWrapper
unionWithEnum: UnionWithEnum
}
`;

Expand All @@ -153,6 +156,9 @@ enumSchema = makeExecutableSchema({
NumericEnum: {
TEST: 1,
},
UnionWithEnum: {
__resolveType: () => 'EnumWrapper'
},
Query: {
color(parent, args) {
return args.input === '#EA3232' ? args.input : null;
Expand All @@ -169,6 +175,12 @@ enumSchema = makeExecutableSchema({
numericEnum: 1
};
},
unionWithEnum() {
return {
color: '#EA3232',
numericEnum: 1
};
},
},
},
});
Expand Down Expand Up @@ -643,6 +655,12 @@ testCombinations.forEach(async combination => {
color
numericEnum
}
unionWithEnum {
... on EnumWrapper {
color
numericEnum
}
}
}
`,
);
Expand Down Expand Up @@ -672,6 +690,12 @@ testCombinations.forEach(async combination => {
color
numericEnum
}
unionWithEnum {
... on EnumWrapper {
color
numericEnum
}
}
}
`,
);
Expand Down Expand Up @@ -703,6 +727,10 @@ testCombinations.forEach(async combination => {
color: 'RED',
numericEnum: 'TEST',
},
unionWithEnum: {
color: 'RED',
numericEnum: 'TEST',
},
},
});
expect(mergedResult).to.deep.equal(enumResult);
Expand Down

0 comments on commit faae86a

Please sign in to comment.