How to use the type-graphql.Query function in type-graphql

To help you get started, weโ€™ve selected a few type-graphql examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github goldcaddy77 / warthog / examples / 07-feature-flags / src / feature-flag / feature-flag.resolver.ts View on Github external
featureFlagSegments(
    @Root() featureFlag: FeatureFlag,
    @Ctx() ctx: BaseContext
  ): Promise {
    return ctx.dataLoader.loaders.FeatureFlag.featureFlagSegments.load(featureFlag);
  }

  @FieldResolver(() => [FeatureFlagUser])
  featureFlagUsers(
    @Root() featureFlag: FeatureFlag,
    @Ctx() ctx: BaseContext
  ): Promise {
    return ctx.dataLoader.loaders.FeatureFlag.featureFlagUsers.load(featureFlag);
  }

  @Query(() => [FeatureFlag])
  async featureFlags(@Args() { where, orderBy, limit, offset }: FeatureFlagWhereArgs): Promise<
    FeatureFlag[]
  > {
    return this.service.find(where, orderBy, limit, offset);
  }

  // Custom resolver that has it's own InputType and calls into custom service method
  @Query(() => [String])
  async featureFlagsForUser(@Arg('where') where: FeatureFlagsForUserInput): Promise {
    return this.service.flagsForUser(where);
  }

  @Query(() => FeatureFlag)
  async featureFlag(@Arg('where') where: FeatureFlagWhereUniqueInput): Promise {
    return this.service.findOne(where);
  }
github babichjacob / sapper-firebase-typescript-graphql-tailwindcss-actions-template / src / graphql / index.ts View on Github external
import "reflect-metadata";
import {Query, Resolver, buildSchema} from "type-graphql";
import express, {Application} from "express";
import {ApolloServer} from "apollo-server-express";
import {GraphQLSchema} from "graphql";

@Resolver()
class HelloResolver {
	@Query(() => String) // eslint-disable-line require-await
	async helloWorld(): Promise {
		return "Hello World!";
	}
}

export const createApolloServer = async (): Promise => {
	const schema: GraphQLSchema = await buildSchema({resolvers: [HelloResolver]});

	const apolloServer: ApolloServer = new ApolloServer({
		schema,
		playground: true,
	});

	return apolloServer;
};
github NoQuarterTeam / fullstack-boilerplate / packages / api / src / modules / user / user.resolver.ts View on Github external
import { ResetPasswordInput } from "./inputs/resetPassword.input"
import { cookieName } from "../../lib/config"
import { UserRepository } from "./user.repository"
import { CurrentUser } from "../shared/middleware/currentUser"

@Resolver(() => User)
export class UserResolver {
  constructor(
    private readonly userService: UserService,
    private readonly userRepository: UserRepository,
    private readonly userMailer: UserMailer,
  ) {}

  // ME
  @Authorized()
  @Query(() => User, { nullable: true })
  async me(@CurrentUser() currentUser: User): Promise {
    return currentUser
  }

  // REGISTER
  @Mutation(() => User)
  async register(
    @Arg("data") data: RegisterInput,
    @Ctx() { req }: ResolverContext,
  ): Promise {
    const user = await this.userService.create(data)
    if (req.session) req.session.user = user
    this.userMailer.sendWelcomeEmail(user)
    return user
  }
github goldcaddy77 / warthog / examples / 07-feature-flags / src / feature-flag / feature-flag.resolver.ts View on Github external
featureFlagUsers(
    @Root() featureFlag: FeatureFlag,
    @Ctx() ctx: BaseContext
  ): Promise {
    return ctx.dataLoader.loaders.FeatureFlag.featureFlagUsers.load(featureFlag);
  }

  @Query(() => [FeatureFlag])
  async featureFlags(@Args() { where, orderBy, limit, offset }: FeatureFlagWhereArgs): Promise<
    FeatureFlag[]
  > {
    return this.service.find(where, orderBy, limit, offset);
  }

  // Custom resolver that has it's own InputType and calls into custom service method
  @Query(() => [String])
  async featureFlagsForUser(@Arg('where') where: FeatureFlagsForUserInput): Promise {
    return this.service.flagsForUser(where);
  }

  @Query(() => FeatureFlag)
  async featureFlag(@Arg('where') where: FeatureFlagWhereUniqueInput): Promise {
    return this.service.findOne(where);
  }

  @Mutation(() => FeatureFlag)
  async createFeatureFlag(
    @Arg('data') data: FeatureFlagCreateInput,
    @UserId() userId: string
  ): Promise {
    return this.service.create(data, userId);
  }
github benawad / codeponder / packages / server / src / modules / code-review-post / resolver.ts View on Github external
},
    });

    if (!value) {
      value = await this.postRepo.save({
        ...input,
        creatorId: req.session!.userId,
      });
    }

    return {
      codeReviewPost: value,
    };
  }

  @Query(() => CodeReviewPost, {
    nullable: true,
  })
  async getCodeReviewPostById(@Arg("id") id: string) {
    return this.postRepo.findOne(id);
  }

  @FieldResolver()
  numQuestions(@Root() root: CodeReviewPost) {
    return this.questionRepo.count({ where: { postId: root.id } });
  }

  @Query(() => FindCodeReviewPostResponse)
  async findCodeReviewPost(@Arg("input")
  {
    offset,
    limit,
github wemaintain / auto-relay / packages / core / src / services / relay-query.service.ts View on Github external
>,
    to: ClassValueThunk, 
    through?: ClassValueThunk,
    options?: RelayedQueryOptions,
    isFieldResolver: boolean = false
  ): void {
    const queryName = this.getQueryName(propertyKey, options)
    const { Connection } = this.makeEdgeConnection(to, through)
    this.registerArgs(target, propertyKey, options)

    const middleware = RelayFromArrayCountFactory(target, propertyKey);
    UseMiddleware(middleware)(target, propertyKey, descriptor)
    if(isFieldResolver) {
      FieldResolver(() => Connection, { ...options, name: queryName })(target, propertyKey, descriptor)
    } else {
      Query(() => Connection, { ...options, name: queryName })(target, propertyKey, descriptor)
    }
  }
github goldcaddy77 / warthog / examples / 08-performance / src / modules / post / post.resolver.ts View on Github external
constructor(@Inject('PostService') public readonly service: PostService) {}

  @FieldResolver(() => User)
  user(@Root() post: Post, @Ctx() ctx: BaseContext): Promise {
    return ctx.dataLoader.loaders.Post.user.load(post);
  }

  @Query(() => [Post])
  async posts(
    @Args() { where, orderBy, limit, offset }: PostWhereArgs,
    @Fields() fields: string[]
  ): Promise {
    return this.service.find(where, orderBy, limit, offset, fields);
  }

  @Query(() => Post)
  async post(@Arg('where') where: PostWhereUniqueInput): Promise {
    return this.service.findOne(where);
  }

  @Mutation(() => Post)
  async createPost(@Arg('data') data: PostCreateInput, @UserId() userId: string): Promise {
    return this.service.create(data, userId);
  }

  @Mutation(() => Post)
  async updatePost(
    @Args() { data, where }: PostUpdateArgs,
    @UserId() userId: string
  ): Promise {
    return this.service.update(data, where, userId);
  }
github birkir / prime / packages / prime-core / src / modules / internal / resolvers / PrimeResolver.ts View on Github external
const data = await this.getSettings();
    const settings = this.settingsRepository.create({
      data: defaults(input, data),
    });
    await this.settingsRepository.save(settings);
    return this.getSettings();
  }

  @Authorized()
  @Query(returns => [PrimeField])
  public allFields(): PrimeField[] {
    return fields;
  }

  @Authorized()
  @Query(returns => [PackageVersion], { nullable: true })
  public system() {
    return getPackagesVersion();
  }

  @Authorized()
  @Mutation(returns => Boolean)
  public async updateSystem(
    @Arg('versions', type => [PackageVersionInput]) packagesVersion: PackageVersionInput[]
  ): Promise {
    const allowedPackages = [
      '@primecms/core',
      '@primecms/ui',
      ...fields.map(({ packageName }) => packageName),
    ];

    if (process.env.NODE_ENV !== 'production') {
github birkir / prime / packages / prime-core / src / modules / internal / resolvers / DocumentResolver.ts View on Github external
@Resolver(of => Document)
export class DocumentResolver {
  @InjectRepository(SchemaRepository)
  private readonly schemaRepository: SchemaRepository;

  @InjectRepository(SchemaFieldRepository)
  private readonly schemaFieldRepository: SchemaFieldRepository;

  @InjectRepository(DocumentRepository)
  private readonly documentRepository: DocumentRepository;

  private readonly documentTransformer: DocumentTransformer = new DocumentTransformer();

  @Authorized()
  @Query(returns => Document, { nullable: true })
  public Document(
    @Arg('id', type => ID, { description: 'Can be either uuid or documentId' }) id: string,
    @Arg('locale', { nullable: true }) locale?: string,
    @Arg('releaseId', type => ID, { nullable: true }) releaseId?: string
  ) {
    const key = id.length === 36 ? 'id' : 'documentId';
    return this.documentRepository.loadOneByDocumentId(id, key, {
      releaseId,
      locale,
    });
  }

  @Authorized()
  @Query(returns => DocumentConnection)
  public allDocuments(
    @Arg('sort', type => [DocumentSort], { defaultValue: 1, nullable: true }) sorts: string[],
github goldcaddy77 / warthog / examples / 08-performance / src / modules / post / post.resolver.ts View on Github external
import { User } from '../user/user.model';

import { Post } from './post.model';
import { PostService } from './post.service';

@Resolver(Post)
export class PostResolver {
  constructor(@Inject('PostService') public readonly service: PostService) {}

  @FieldResolver(() => User)
  user(@Root() post: Post, @Ctx() ctx: BaseContext): Promise {
    return ctx.dataLoader.loaders.Post.user.load(post);
  }

  @Query(() => [Post])
  async posts(
    @Args() { where, orderBy, limit, offset }: PostWhereArgs,
    @Fields() fields: string[]
  ): Promise {
    return this.service.find(where, orderBy, limit, offset, fields);
  }

  @Query(() => Post)
  async post(@Arg('where') where: PostWhereUniqueInput): Promise {
    return this.service.findOne(where);
  }

  @Mutation(() => Post)
  async createPost(@Arg('data') data: PostCreateInput, @UserId() userId: string): Promise {
    return this.service.create(data, userId);
  }