type-graphql#Root TypeScript Examples

The following examples show how to use type-graphql#Root. 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 vote down vote up
@FieldResolver(type => [Log])
    @Authorized(Role.ADMIN)
    @LimitEstimated(100)
    async logs(@Root() pupil: Required<Pupil>) {
        return await prisma.log.findMany({
            where: { user: pupil.wix_id },
            orderBy: { createdAt: "asc" }
        });
    }
Example #2
Source File: CompanyResolver.ts    From type-graphql-dataloader with MIT License 6 votes vote down vote up
@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 #3
Source File: fields.ts    From backend with MIT License 6 votes vote down vote up
@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 vote down vote up
@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: user.ts    From lireddit with MIT License 6 votes vote down vote up
@FieldResolver(() => String)
  email(@Root() user: User, @Ctx() { req }: MyContext) {
    // this is the current user and its ok to show them their own email
    if (req.session.userId === user.id) {
      return user.email;
    }
    // current user wants to see someone elses email
    return "";
  }
Example #6
Source File: message-subscriptions.ts    From convoychat with GNU General Public License v3.0 6 votes vote down vote up
@Subscription(returns => Message, {
    topics: CONSTANTS.NEW_MESSAGE,
    filter: filterRoom,
  })
  onNewMessage(
    @Root() message: Message,
    @Arg("roomId") roomId: ObjectID
  ): Message {
    return message;
  }
Example #7
Source File: fields.ts    From backend with MIT License 6 votes vote down vote up
@FieldResolver(type => [Subcourse])
    @Authorized(Role.ADMIN, Role.OWNER)
    @LimitEstimated(10)
    async subcoursesJoined(@Root() pupil: Pupil) {
        return await prisma.subcourse.findMany({
            where: {
                subcourse_participants_pupil: {
                    some: {
                        pupilId: pupil.id
                    }
                }
            }
        });
    }
Example #8
Source File: topic.resolver.ts    From hakka with MIT License 6 votes vote down vote up
@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 vote down vote up
@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 vote down vote up
@FieldResolver((returns) => Int)
  async commentsCount(@Root() topic: Topic) {
    const count = await prisma.comment.count({
      where: {
        topicId: topic.id,
      },
    })
    return count
  }
Example #11
Source File: fields.ts    From backend with MIT License 6 votes vote down vote up
@FieldResolver(returns => [Subject])
    @Authorized(Role.ADMIN)
    @LimitEstimated(1)
    async subjectsFormatted(@Root() match: Match) {
        const student = await getStudent(match.studentId);
        const pupil = await getPupil(match.pupilId);

        return getOverlappingSubjects(pupil, student);
    }
Example #12
Source File: comment.resolver.ts    From hakka with MIT License 5 votes vote down vote up
@FieldResolver((returns) => String)
  html(@Root() comment: Comment) {
    const html = renderMarkdown(comment.content)
    return html
  }
Example #13
Source File: product-category.resolver.ts    From Cromwell with MIT License 5 votes vote down vote up
@FieldResolver(() => ProductCategory, { nullable: true })
    async [parentKey](@Root() productCategory: ProductCategory): Promise<TProductCategory | undefined | null> {
        return await this.repository.getParentCategory(productCategory);
    }
Example #14
Source File: resolver.ts    From typegraphql-nestjs with MIT License 5 votes vote down vote up
@FieldResolver(returns => [Review])
  async reviews(@Root() user: User): Promise<Review[]> {
    return reviews.filter(review => review.author.id === user.id);
  }
Example #15
Source File: fields.ts    From backend with MIT License 5 votes vote down vote up
@FieldResolver(returns => Int)
    @Authorized(Role.ADMIN)
    async studentsToMatchCount(@Root() matchPool: MatchPoolType, @Arg("toggles", _type => [String], { nullable: true }) toggles?: string[]) {
        return await getStudentCount(matchPool, toggles ?? []);
    }
Example #16
Source File: attribute.resolver.ts    From Cromwell with MIT License 5 votes vote down vote up
@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 #17
Source File: fields.ts    From backend with MIT License 5 votes vote down vote up
@FieldResolver(returns => Notification)
    @Authorized(Role.UNAUTHENTICATED)
    async notification(@Root() concreteNotification: ConcreteNotification) {
        return await prisma.notification.findUnique({ where: { id: concreteNotification.notificationID }});
    }
Example #18
Source File: post.ts    From lireddit with MIT License 5 votes vote down vote up
@FieldResolver(() => User)
  creator(@Root() post: Post, @Ctx() { userLoader }: MyContext) {
    return userLoader.load(post.creatorId);
  }
Example #19
Source File: fields.ts    From backend with MIT License 5 votes vote down vote up
@FieldResolver(returns => Int)
    @Authorized(Role.ADMIN)
    async pupilsToMatchCount(@Root() matchPool: MatchPoolType, @Arg("toggles", _type => [String], { nullable: true }) toggles?: string[]) {
        return await getPupilCount(matchPool, toggles ?? []);
    }
Example #20
Source File: resolver.ts    From typegraphql-nestjs with MIT License 5 votes vote down vote up
@FieldResolver(() => [Review])
  async reviews(@Root() product: Product): Promise<Review[]> {
    return reviews.filter(review => review.product.upc === product.upc);
  }
Example #21
Source File: SerialMonitor.resolver.ts    From ExpressLRS-Configurator with GNU General Public License v3.0 5 votes vote down vote up
@Subscription(() => SerialMonitorEvent, {
    topics: [PubSubTopic.SerialMonitorEvents],
  })
  serialMonitorEvents(
    @Root() n: SerialMonitorEventPayload
  ): SerialMonitorEvent {
    return new SerialMonitorEvent(n.type);
  }
Example #22
Source File: user.resolver.ts    From Cromwell with MIT License 5 votes vote down vote up
@FieldResolver(() => GraphQLJSONObject, { nullable: true })
    async customMeta(@Root() entity: User, @Arg("keys", () => [String]) fields: string[]): Promise<any> {
        return entityMetaRepository.getEntityMetaByKeys(EDBEntity.User, entity.id, fields);
    }