type-graphql#FieldResolver TypeScript Examples
The following examples show how to use
type-graphql#FieldResolver.
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: fields.ts From backend with MIT License | 6 votes |
@FieldResolver(returns => [Subcourse])
@Authorized(Role.ADMIN)
async subcourses(@Root() course: Course) {
return await prisma.subcourse.findMany({
where: {
courseId: course.id
}
});
}
Example #2
Source File: post.ts From lireddit with MIT License | 6 votes |
@FieldResolver(() => Int, { nullable: true })
async voteStatus(
@Root() post: Post,
@Ctx() { updootLoader, req }: MyContext
) {
if (!req.session.userId) {
return null;
}
const updoot = await updootLoader.load({
postId: post.id,
userId: req.session.userId,
});
return updoot ? updoot.value : null;
}
Example #3
Source File: fields.ts From backend with MIT License | 6 votes |
@FieldResolver(returns => [Student])
@Authorized(Role.ADMIN)
// eslint-disable-next-line camelcase
async student(@Root() certificate: Certificate_of_conduct) {
return await prisma.student.findUnique({
where: {
id: certificate.studentId
}
});
}
Example #4
Source File: resolver.ts From typegraphql-nestjs with MIT License | 6 votes |
@Directive(`@requires(fields: "price weight")`)
@FieldResolver(returns => Number)
async shippingEstimate(@Root() product: Product): Promise<number> {
// free for expensive items
if (product.price > 1000) {
return 0;
}
// estimate is based on weight
return product.weight * 0.5;
}
Example #5
Source File: fields.ts From backend with MIT License | 6 votes |
@FieldResolver(returns => String, { nullable: true })
@Authorized(Role.ADMIN)
image(@Root() course: Course) {
if (!course.imageKey) {
return null;
}
return accessURLForKey(course.imageKey);
}
Example #6
Source File: topic.resolver.ts From hakka with MIT License | 6 votes |
@FieldResolver((returns) => TopicAuthor)
async author(@Root() topic: Topic) {
const author = await prisma.user.findUnique({
where: {
id: topic.authorId,
},
})
return author
}
Example #7
Source File: CompanyResolver.ts From type-graphql-dataloader with MIT License | 6 votes |
@FieldResolver()
@Loader<string, Chair[]>(async (ids) => {
const chairs = await getRepository(Chair).find({
where: { company: { id: In([...ids]) } },
});
const chairsById = groupBy(chairs, "companyId");
return ids.map((id) => chairsById[id] ?? []);
})
chairs(@Root() root: Company) {
return (dataloader: DataLoader<string, Chair[]>) =>
dataloader.load(root.id);
}
Example #8
Source File: topic.resolver.ts From hakka with MIT License | 6 votes |
@FieldResolver((returns) => TopicExternalLink, { nullable: true })
externalLink(@Root() topic: Topic) {
if (!topic.url) return null
const url = new URL(topic.url)
return {
url: url.href,
domain: url.hostname.replace(/^www\./, ''),
}
}
Example #9
Source File: post.resolver.ts From Cromwell with MIT License | 6 votes |
@FieldResolver(() => User, { nullable: true })
async [authorKey](@Root() post: Post): Promise<TUser | undefined> {
try {
if (post.authorId)
return await this.userRepository.getUserById(post.authorId);
} catch (e) {
logger.error(e);
}
}
Example #10
Source File: topic.resolver.ts From hakka with MIT License | 6 votes |
@FieldResolver((returns) => Int)
async likesCount(@Root() topic: Topic) {
const count = await prisma.userTopicLike.count({
where: {
topicId: topic.id,
},
})
return count
}
Example #11
Source File: fields.ts From backend with MIT License | 5 votes |
@FieldResolver(type => [ParticipationCertificate])
@Authorized(Role.ADMIN, Role.OWNER)
@LimitEstimated(10)
async participationCertificatesToSign(@Root() pupil: Required<Pupil>) {
return await prisma.participation_certificate.findMany({
where: { pupilId: pupil.id }
});
}
Example #12
Source File: testSchemaTypeGraphql.ts From ra-data-prisma with MIT License | 5 votes |
@FieldResolver((type) => Address, { nullable: true })
address(user: User): Address | undefined {
return user.address as unknown as Address;
}
Example #13
Source File: fields.ts From backend with MIT License | 5 votes |
@FieldResolver(returns => [Secret])
@Authorized(Role.USER)
async secrets(@Ctx() context: GraphQLContext) {
return await getSecrets(getSessionUser(context));
}
Example #14
Source File: topic.resolver.ts From hakka with MIT License | 5 votes |
@FieldResolver((returns) => Comment, { nullable: true })
async lastComment(@Root() topic: Topic) {
return (
topic.lastCommentId &&
prisma.comment.findUnique({ where: { id: topic.lastCommentId } })
)
}
Example #15
Source File: fields.ts From backend with MIT License | 5 votes |
@FieldResolver(returns => Number)
@Authorized(Role.UNAUTHENTICATED)
@PublicCache()
async participantsCount(@Root() subcourse: Subcourse) {
return await prisma.subcourse_participants_pupil.count({
where: { subcourseId: subcourse.id }
});
}
Example #16
Source File: topic.resolver.ts From hakka with MIT License | 5 votes |
@FieldResolver((returns) => String)
html(@Root() topic: Topic) {
const html = renderMarkdown(topic.content)
return html
}
Example #17
Source File: fields.ts From backend with MIT License | 5 votes |
@FieldResolver(type => [Match])
@Authorized(Role.ADMIN, Role.OWNER)
@LimitEstimated(10)
async matches(@Root() pupil: Required<Pupil>) {
return await prisma.match.findMany({
where: { pupilId: pupil.id }
});
}
Example #18
Source File: comment.resolver.ts From hakka with MIT License | 5 votes |
@FieldResolver((returns) => String)
html(@Root() comment: Comment) {
const html = renderMarkdown(comment.content)
return html
}
Example #19
Source File: fields.ts From backend with MIT License | 5 votes |
@FieldResolver(type => Int)
@Authorized(Role.ADMIN, Role.OWNER)
gradeAsInt(@Root() pupil: Required<Pupil>) {
return gradeAsInt(pupil.grade);
}
Example #20
Source File: current-user.resolver.ts From hakka with MIT License | 5 votes |
@FieldResolver((returns) => Boolean)
isAdmin(@Root() user: CurrentUser) {
return isAdmin(user)
}
Example #21
Source File: fields.ts From backend with MIT License | 5 votes |
@FieldResolver(type => Decision)
@Authorized(Role.ADMIN, Role.OWNER)
async canRequestMatch(@Root() pupil: Required<Pupil>) {
return await canPupilRequestMatch(pupil);
}
Example #22
Source File: product-category.resolver.ts From Cromwell with MIT License | 5 votes |
@FieldResolver(() => ProductCategory, { nullable: true })
async [parentKey](@Root() productCategory: ProductCategory): Promise<TProductCategory | undefined | null> {
return await this.repository.getParentCategory(productCategory);
}
Example #23
Source File: fields.ts From backend with MIT License | 5 votes |
@FieldResolver(returns => [String])
@Authorized(Role.ADMIN, Role.STUDENT)
subjectsFormatted(@Root() certificate: ParticipationCertificate) {
return certificate.subjects.split(",");
}
Example #24
Source File: attribute.resolver.ts From Cromwell with MIT License | 5 votes |
@FieldResolver(() => GraphQLJSONObject, { nullable: true })
async customMeta(@Root() entity: Attribute, @Arg("keys", () => [String]) fields: string[]): Promise<any> {
return entityMetaRepository.getEntityMetaByKeys(EDBEntity.Attribute, entity.id, fields);
}
Example #25
Source File: fields.ts From backend with MIT License | 5 votes |
@FieldResolver(returns => [MatchPoolRun])
@Authorized(Role.ADMIN)
async runs(@Root() matchPool: MatchPoolType) {
return await getPoolRuns(matchPool);
}
Example #26
Source File: post.ts From lireddit with MIT License | 5 votes |
@FieldResolver(() => User)
creator(@Root() post: Post, @Ctx() { userLoader }: MyContext) {
return userLoader.load(post.creatorId);
}
Example #27
Source File: resolver.ts From typegraphql-nestjs with MIT License | 5 votes |
@FieldResolver(returns => [Review])
async reviews(@Root() user: User): Promise<Review[]> {
return reviews.filter(review => review.author.id === user.id);
}
Example #28
Source File: user.resolver.ts From Cromwell with MIT License | 5 votes |
@FieldResolver(() => GraphQLJSONObject, { nullable: true })
async customMeta(@Root() entity: User, @Arg("keys", () => [String]) fields: string[]): Promise<any> {
return entityMetaRepository.getEntityMetaByKeys(EDBEntity.User, entity.id, fields);
}