@nestjs/graphql#Args TypeScript Examples

The following examples show how to use @nestjs/graphql#Args. 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 vote down vote up
@Query(() => [DomesticAnimal])
  domesticAnimals(
    @Args({ name: 'species', type: () => Species, nullable: true })
    species?: Species,
  ) {
    switch (species) {
      case Species.DOG:
        return this.dogService.dogs();
      case Species.CAT:
        return this.catService.cats();
      default:
        return [...this.dogService.dogs(), ...this.catService.cats()];
    }
  }
Example #2
Source File: find-users.graphql-resolver.ts    From domain-driven-hexagon with MIT License 6 votes vote down vote up
@Query(() => [UserResponse])
  async findUsers(
    @Args('input') input: FindUsersRequest,
  ): Promise<UserResponse[]> {
    const query = new FindUsersQuery(input);
    const users = await this.userRepo.findUsers(query);

    return users.map(user => new UserResponse(user));
  }
Example #3
Source File: whisp.resolver.ts    From whispr with MIT License 6 votes vote down vote up
@Query(() => [Whisp], { nullable: true })
  async whisps(
    @Args('filter', { type: () => GraphQLJSONObject, nullable: true })
      filter?: Record<string, unknown>,
    @Args('sort', { type: () => GraphQLJSONObject, nullable: true })
      sort?: Record<string, unknown>,
    @Args('limit', { type: () => Int, nullable: true }) limit?: number,
  ): Promise<IWhisp[]> {
    return this.whispService.findAll(filter, sort, limit);
  }
Example #4
Source File: account.resolver.ts    From amplication with Apache License 2.0 6 votes vote down vote up
@Mutation(() => Account)
  async updateAccount(
    @UserEntity() user: User,
    @Args('data') newAccountData: UpdateAccountInput
  ): Promise<Account> {
    return this.accountService.updateAccount({
      where: { id: user.account.id },
      data: newAccountData
    });
  }
Example #5
Source File: post.resolver.ts    From nest-casl with MIT License 6 votes vote down vote up
@Mutation(() => Post)
  @UseGuards(AccessGuard)
  @UseAbility<Post>(Actions.update, Post, [
    PostService,
    (service: PostService, { params }) => service.findById(params.input.id),
  ])
  async updatePostTupleHook(@Args('input') input: UpdatePostInput) {
    return this.postService.update(input);
  }
Example #6
Source File: dbms-plugins.resolver.ts    From relate with GNU General Public License v3.0 6 votes vote down vote up
@Mutation(() => UninstallDbmsPluginReturn, {nullable: true})
    async [PUBLIC_GRAPHQL_METHODS.UNINSTALL_DBMS_PLUGIN](
        @Context('environment') environment: Environment,
        @Args() {dbmsIds}: DbmssArgs,
        @Args() {pluginName}: PluginNameArgs,
    ): Promise<UninstallDbmsPluginReturn> {
        await environment.dbmsPlugins.uninstall(dbmsIds, pluginName);
        return {
            dbmsIds,
            pluginName,
        };
    }
Example #7
Source File: games.resolver.ts    From game-store-monorepo-app with MIT License 6 votes vote down vote up
@Query(() => RawgGameResponse, {
    name: 'allGames',
  })
  async getAllGames(
    @Args('page', { nullable: true, type: () => Int }) page?: number,
    @Args('pageSize', { nullable: true, type: () => Int }) pageSize?: number,
    @Args('dates', { nullable: true }) dates?: string,
    @Args('ordering', { nullable: true }) ordering?: string,
    @Args('tags', { nullable: true }) tags?: string,
    @Args('genres', { nullable: true }) genres?: string,
    @Args('publishers', { nullable: true }) publishers?: string,
    @Args('search', { nullable: true }) search?: string,
  ): Promise<RawgGameResponse> {
    const params = {
      key: this.apiKey,
      page,
      page_size: pageSize || 10,
      search,
      genres,
      tags,
      publishers,
      dates,
      ordering,
    };
    this.logger.debug('getAllGames called with params', params);
    const res = await this.httpService
      .get<RawgGameResponse>(`${this.host}/games?${stringifyQueryObject(params)}`)
      .toPromise();
    const rawgResponse = plainToClass(RawgGameResponse, res.data);
    return rawgResponse;
  }
Example #8
Source File: auth.login.mutation.ts    From api with GNU Affero General Public License v3.0 6 votes vote down vote up
@Mutation(() => AuthJwtModel)
  async authLogin(
    @Args({ name: 'username', type: () => String }) username: string,
    @Args({ name: 'password', type: () => String }) password: string,
  ): Promise<AuthJwtModel> {
    const user = await this.auth.validateUser(username, password)

    if (!user) {
      throw new Error('invalid user / password')
    }

    return this.auth.login(user)
  }