@nestjs/graphql#ResolveField TypeScript Examples

The following examples show how to use @nestjs/graphql#ResolveField. 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: form.field.resolver.ts    From api with GNU Affero General Public License v3.0 7 votes vote down vote up
@ResolveField(() => [FormFieldOptionModel])
  async options(
    @Parent() parent: FormFieldModel,
    @Context('cache') cache: ContextCache,
  ): Promise<FormFieldOptionModel[]> {
    const field = await cache.get<FormFieldEntity>(cache.getCacheKey(
      FormFieldEntity.name,
      parent._id
    ))

    if (!field.options) {
      return []
    }

    return field.options.map(option => new FormFieldOptionModel(
      this.idService.encode(option.id),
      option,
    ))
  }
Example #2
Source File: block.resolver.ts    From amplication with Apache License 2.0 6 votes vote down vote up
@ResolveField(() => [User])
  async lockedByUser(@Parent() block: Block): Promise<User> {
    if (block.lockedByUserId) {
      return this.userService.findUser({
        where: {
          id: block.lockedByUserId
        }
      });
    } else {
      return null;
    }
  }
Example #3
Source File: form.field.resolver.ts    From api with GNU Affero General Public License v3.0 6 votes vote down vote up
@ResolveField(() => [FormFieldLogicModel])
  async logic(
    @Parent() parent: FormFieldModel,
    @Context('cache') cache: ContextCache,
  ): Promise<FormFieldLogicModel[]> {
    const field = await cache.get<FormFieldEntity>(cache.getCacheKey(
      FormFieldEntity.name,
      parent._id
    ))

    if (!field.logic) {
      return []
    }

    return field.logic.map(logic => new FormFieldLogicModel(
      this.idService.encode(logic.id),
      logic,
    ))
  }
Example #4
Source File: block.resolver.ts    From amplication with Apache License 2.0 6 votes vote down vote up
@ResolveField(() => [BlockVersion])
  async versions(
    @Parent() entity: Block,
    @Args() args: FindManyBlockVersionArgs
  ): Promise<BlockVersion[]> {
    return this.blockService.getVersions({
      ...args,
      where: {
        ...args.where,
        block: { id: entity.id }
      }
    });
  }
Example #5
Source File: form.resolver.ts    From api with GNU Affero General Public License v3.0 6 votes vote down vote up
@ResolveField(() => DesignModel)
  async design(
    @User() user: UserEntity,
    @Parent() parent: FormModel,
    @Context('cache') cache: ContextCache,
  ): Promise<DesignModel> {
    const form = await cache.get<FormEntity>(cache.getCacheKey(FormEntity.name, parent._id))

    return new DesignModel(form.design)
  }
Example #6
Source File: resolve-connection-field.decorator.ts    From nestjs-relay with MIT License 6 votes vote down vote up
export function ResolveConnectionField(
  nodeTypeFunc: ReturnTypeFunc,
  options?: ResolveConnectionFieldOptions,
): MethodDecorator {
  return (target: Record<string, any>, key: string | symbol, descriptor: PropertyDescriptor) => {
    // eslint-disable-next-line @typescript-eslint/ban-types
    const nodeType = nodeTypeFunc() as Function;
    const typeMetadata = MetadataStorage.getClassMetadata({ target: nodeType });

    const connection = ConnectionTypeFactory.create({
      nodeTypeFunc,
      nodeTypeName: typeMetadata.name,
    });

    const resolveFieldOptions = { ...options, nullable: true };
    ResolveField(() => connection, resolveFieldOptions)(target, key, descriptor);
  };
}
Example #7
Source File: user.resolver.ts    From api with GNU Affero General Public License v3.0 6 votes vote down vote up
@ResolveField(() => [String])
  @Roles('user')
  async roles(
    @User() user: UserEntity,
    @Parent() parent: UserModel,
    @Context('cache') cache: ContextCache,
  ): Promise<string[]> {
    return this.returnFieldForSuperuser(
      await cache.get<UserEntity>(cache.getCacheKey(UserEntity.name, parent._id)),
      user,
      c => c.roles
    )
  }
Example #8
Source File: app.resolver.ts    From amplication with Apache License 2.0 6 votes vote down vote up
@ResolveField(() => [Entity])
  async entities(
    @Parent() app: App,
    @Args() args: FindManyEntityArgs
  ): Promise<Entity[]> {
    return this.entityService.entities({
      ...args,
      where: { ...args.where, app: { id: app.id } }
    });
  }
Example #9
Source File: form.resolver.ts    From api with GNU Affero General Public License v3.0 6 votes vote down vote up
@ResolveField(() => UserModel, { nullable: true })
  @Roles('admin')
  async admin(
    @Parent() parent: FormModel,
    @Context('cache') cache: ContextCache,
  ): Promise<UserModel> {
    const form = await cache.get<FormEntity>(cache.getCacheKey(FormEntity.name, parent._id))

    if (!form.admin) {
      return null
    }

    return new UserModel(this.idService.encode(form.admin.id), form.admin)
  }
Example #10
Source File: users.resolver.ts    From knests with MIT License 5 votes vote down vote up
@ResolveField()
  async roles(@Parent() user) {
    return user.roles || [];
  }
Example #11
Source File: submission.statistic.resolver.ts    From api with GNU Affero General Public License v3.0 5 votes vote down vote up
@ResolveField(() => GraphQLInt)
  @Roles('admin')
  total(): Promise<number> {
    return this.statisticService.getTotal()
  }
Example #12
Source File: project.resolver.ts    From relate with GNU General Public License v3.0 5 votes vote down vote up
@ResolveField()
    dbmss(
        @Context('environment') environment: Environment,
        @Parent() project: Project,
        @Args() {filters}: FilterArgs,
    ): Promise<List<ProjectDbms>> {
        return environment.projects.listDbmss(project.name, filters);
    }
Example #13
Source File: workspace.resolver.ts    From amplication with Apache License 2.0 5 votes vote down vote up
@ResolveField(() => [GitOrganization])
  async gitOrganizations(
    @Parent() workspace: Workspace
  ): Promise<GitOrganization[]> {
    return this.workspaceService.findManyGitOrganizations(workspace.id);
  }
Example #14
Source File: user.statistic.resolver.ts    From api with GNU Affero General Public License v3.0 5 votes vote down vote up
@ResolveField(() => Int)
  @Roles('admin')
  total(): Promise<number> {
    return this.statisticService.getTotal()
  }
Example #15
Source File: user.resolver.ts    From amplication with Apache License 2.0 5 votes vote down vote up
@ResolveField(() => Account)
  async account(@Parent() user: User) {
    return await this.userService.getAccount(user.id);
  }
Example #16
Source File: global-id-field.decorator.ts    From nestjs-relay with MIT License 5 votes vote down vote up
GlobalIdField = (options?: GlobalIdFieldOptions) =>
  ResolveField(typeResolvedGlobalId, {
    name: 'id',
    nullable: false,
    ...options,
  })
Example #17
Source File: animal.resolver.ts    From nestjs-mercurius with MIT License 5 votes vote down vote up
@ResolveField(() => Boolean)
  hasPaws(@Parent() animal: Animal) {
    return true;
  }
Example #18
Source File: block.resolver.ts    From amplication with Apache License 2.0 5 votes vote down vote up
//resolve the parentBlock property as a generic block
  @ResolveField(() => Block, { nullable: true })
  async parentBlock(@Parent() block: Block): Promise<Block> {
    return this.blockService.getParentBlock(block);
  }
Example #19
Source File: person.resolver.ts    From nestjs-mercurius with MIT License 5 votes vote down vote up
@ResolveField(() => String)
  uniqueName(@Parent() person: Person) {
    return `${person.id}__${person.name}`;
  }
Example #20
Source File: tag.resolver.ts    From whispr with MIT License 5 votes vote down vote up
/**
   * Field resolver
   */
  @ResolveField()
  async tagGroup(@Root() tag: Tag): Promise<ITagGroup> {
    // eslint-disable-next-line no-underscore-dangle
    return this.tagGroupService.findOne(tag.tagGroup._id);
  }
Example #21
Source File: action.resolver.ts    From amplication with Apache License 2.0 5 votes vote down vote up
@ResolveField(() => [ActionStep])
  async steps(@Parent() action: Action) {
    return this.service.getSteps(action.id);
  }