@nestjs/graphql#Query TypeScript Examples

The following examples show how to use @nestjs/graphql#Query. 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: auth.resolver.ts    From svvs with MIT License 6 votes vote down vote up
/**
   * Implement GraphQL Query 'login'
   *
   * @param signInPayload from lib shared-data-access-interfaces
   */
  @Query('login')
  async login(
    @SignIn() signInPayload: ISignAuthPayload
  ): Promise<ISignAuthResponse> {
    return await this.authService.login(signInPayload);
  }
Example #5
Source File: app.resolver.ts    From amplication with Apache License 2.0 6 votes vote down vote up
@Query(() => [App], {
    nullable: false,
    description: undefined
  })
  @Roles('ORGANIZATION_ADMIN')
  @InjectContextValue(
    InjectableResourceParameter.WorkspaceId,
    'where.workspace.id'
  )
  async apps(@Args() args: FindManyAppArgs): Promise<App[]> {
    return this.appService.apps(args);
  }
Example #6
Source File: extension.resolver.ts    From relate with GNU General Public License v3.0 6 votes vote down vote up
@Query(() => AppLaunchData)
    async [PUBLIC_GRAPHQL_METHODS.APP_LAUNCH_DATA](
        @Context('environment') environment: Environment,
        @Args() {appName, launchToken}: LaunchDataArgs,
    ): Promise<AppLaunchData> {
        const {dbmsId, projectId, ...rest} = await environment.extensions.parseAppLaunchToken(appName, launchToken);
        const dbms = await environment.dbmss.get(dbmsId);
        const appLaunchData: AppLaunchData = {
            ...rest,
            dbms,
            environmentId: environment.id,
        };

        if (projectId) {
            appLaunchData.project = {
                ...(await environment.projects.get(projectId)),
                files: [],
            };
        }

        return appLaunchData;
    }
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: form.list.query.ts    From api with GNU Affero General Public License v3.0 6 votes vote down vote up
@Query(() => FormPagerModel)
  @Roles('user')
  async listForms(
    @User() user: UserEntity,
    @Args('start', {type: () => Int, defaultValue: 0, nullable: true}) start: number,
    @Args('limit', {type: () => Int, defaultValue: 50, nullable: true}) limit: number,
    @Context('cache') cache: ContextCache,
  ): Promise<FormPagerModel> {
    const [forms, total] = await this.formService.find(
      start,
      limit,
      {},
      user.roles.includes('superuser') ? null : user,
    )

    forms.forEach(form => cache.add(cache.getCacheKey(FormEntity.name, form.id), form))

    return new FormPagerModel(
      forms.map(form => new FormModel(this.idService.encode(form.id), form)),
      total,
      limit,
      start,
    )
  }
Example #9
Source File: node-field.resolver.ts    From nestjs-relay with MIT License 6 votes vote down vote up
@Query(returnsNodeInterface, {
    name: 'node',
    description: 'Fetches an object given its ID',
    nullable: true,
  })
  node(
    @Args({
      name: 'id',
      nullable: false,
      description: 'The ID of an object',
      type: typeResolvedGlobalId,
    })
    id: ResolvedGlobalId,
  ): ResolvedNode {
    return this.resolveNode(id);
  }
Example #10
Source File: dummy.resolver.ts    From prisma-nestjs-graphql with MIT License 6 votes vote down vote up
/**
   * Query for single user.
   */
  @Query(() => [Dummy])
  dummies() {
    const dummy = new Dummy();
    dummy.json = {
      a: 1,
    };
    dummy.decimal = new Prisma.Decimal(1.002);
    return [dummy];
  }
Example #11
Source File: animal.resolver.ts    From nestjs-mercurius with MIT License 5 votes vote down vote up
@Query(() => [Animal])
  animals() {
    return [...this.dogService.dogs(), ...this.catService.cats()];
  }
Example #12
Source File: tag.resolver.ts    From whispr with MIT License 5 votes vote down vote up
/**
   * Queries
   */

  @Query(() => [Tag], { nullable: true })
  async tags(@Args('tag') tagFilter: TagInputType): Promise<ITag[]> {
    return this.tagService.findAll(tagFilter);
  }
Example #13
Source File: auth.resolver.ts    From svvs with MIT License 5 votes vote down vote up
/**
   * Implement GraphQL Query 'logout'
   */
  @Query('logout')
  async logout(): Promise<boolean> {
    return true;
  }
Example #14
Source File: auth.resolver.ts    From amplication with Apache License 2.0 5 votes vote down vote up
@Query(() => UserInfo)
  @common.UseGuards(GqlDefaultAuthGuard, gqlACGuard.GqlACGuard)
  async userInfo(@UserData() userInfo: UserInfo): Promise<UserInfo> {
    return userInfo;
  }
Example #15
Source File: app.resolver.ts    From nestjs-jaeger-tracing with MIT License 5 votes vote down vote up
@Query('getHello')
  hello(@Tracing() tracing: TracingData): string {
    Logger.log({ getHello: tracing });
    return this.appService.getHello();
  }
Example #16
Source File: post.resolver.ts    From nest-casl with MIT License 5 votes vote down vote up
@Query(() => Post)
  @UseGuards(AccessGuard)
  @UseAbility(Actions.read, Post)
  async post(@Args('id') id: string) {
    return this.postService.findById(id);
  }
Example #17
Source File: notification.resolver.ts    From aws-nestjs-starter with The Unlicense 5 votes vote down vote up
@Query(/* istanbul ignore next */ () => Notification)
  notification(
    @Args('id', { type: /* istanbul ignore next */ () => ID }) id: string,
  ) {
    return this.notificationService.findOne({ id });
  }
Example #18
Source File: db.resolver.ts    From relate with GNU General Public License v3.0 5 votes vote down vote up
@Query(() => [Db]!)
    async [PUBLIC_GRAPHQL_METHODS.LIST_DBS](
        @Context('environment') environment: Environment,
        @Args() {dbmsId, user, accessToken}: ListDbArgs,
    ): Promise<List<IDb>> {
        return environment.dbs.list(dbmsId, user, accessToken);
    }
Example #19
Source File: form.statistic.query.ts    From api with GNU Affero General Public License v3.0 5 votes vote down vote up
@Query(() => FormStatisticModel)
  getFormStatistic(): FormStatisticModel {
    return new FormStatisticModel()
  }