@nestjs/graphql#createUnionType TypeScript Examples
The following examples show how to use
@nestjs/graphql#createUnionType.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: animal.resolver.ts From nestjs-mercurius with MIT License | 6 votes |
DomesticAnimal = createUnionType({
name: 'DomesticAnimal',
types: () => [Dog, Cat],
resolveType: (value: Dog | Cat) => {
switch (value.species) {
case Species.CAT:
return Cat;
case Species.DOG:
return Dog;
default:
return null;
}
},
})
Example #2
Source File: search.resolver.ts From nestjs-mercurius with MIT License | 6 votes |
SearchUnion = createUnionType({
name: 'SearchUnion',
types: () => [PostType, UserType],
resolveType: (value: PostType | UserType) => {
if (isUser(value)) {
return UserType;
}
if (isPost(value)) {
return PostType;
}
return null;
},
})
Example #3
Source File: PendingChangeResource.ts From amplication with Apache License 2.0 | 6 votes |
PendingChangeResource = createUnionType({
name: 'PendingChangeResource',
types: () => [Entity, Block],
resolveType(value) {
if (value.blockType) {
return Block;
}
return Entity;
}
})
Example #4
Source File: WorkspaceMemberType.ts From amplication with Apache License 2.0 | 6 votes |
WorkspaceMemberType = createUnionType({
name: 'WorkspaceMemberType',
types: () => [User, Invitation],
resolveType(value) {
if (value.hasOwnProperty('email')) {
return Invitation;
}
return User;
}
})