How to use the type-graphql.Field 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 nodkz / conf-talks / articles / graphql / schema-build-ways / schema-via-type-graphql.js View on Github external
@Field(type => String, { nullable: true })
  name: string;
}

@ObjectType({ description: 'Article data with related Author data' })
class Article {
  @Field(type => String)
  title: string;

  @Field(type => String, { nullable: true })
  text: string;

  @Field(type => ID)
  authorId: number;

  @Field(type => Author)
  get author(): ?Object {
    return authors.find(o => o.id === this.authorId);
  }
}

@Resolver(of => Article)
class ArticleResolver implements ResolverInterface<article> {
  @Query(returns =&gt; [Article])

  // SyntaxError: Stage 2 decorators cannot be used to decorate parameters (36:17)
  // Waiting fresh Babel implementation for decorators plugin
  async articles(@Arg('limit') limit: string): Array<article> {
    return articles.slice(0, limit);
  }
}
</article></article>
github niklaskorz / nkchat / server / src / models / Message.ts View on Github external
@Column()
  content: string;

  @Field(type => ObjectID)
  @Column()
  authorId: ObjectID;

  @Field(type => ObjectID)
  @Column()
  roomId: ObjectID;

  @Field(type => [Embed])
  @Column(type => Embed)
  embeds: Embed[];

  @Field()
  createdAt(): Date {
    return this.id.getTimestamp();
  }
}
github jorisvddonk / WelcomeToTheFuture / backend / starship / Starship.ts View on Github external
if (this.movementVec.modulus() > MaxSpeedVector.modulus()) {
      this.movementVec = this.movementVec
        .toUnitVector()
        .multiply(MaxSpeedVector.modulus());
    }
  }

  @Field()
  get position(): Vector {
    return {
      x: this.positionVec.e(1),
      y: this.positionVec.e(2)
    };
  }

  @Field()
  get velocity(): Vector {
    return {
      x: this.movementVec.e(1),
      y: this.movementVec.e(2)
    };
  }

  @Field()
  get angle(): number {
    return (
      new Sylvester.Vector([1, 0]).angleTo(this.rotationVec) * 57.2957795 + 90
    );
  }

  @Field()
  get thrusting(): boolean {
github jmcdo29 / zeldaPlay / apps / api / src / app / ability-score / models / ability-score-update.ts View on Github external
import { AbilityScoreUpdate } from '@tabletop-companion/api-interface';
import { IsNotEmpty, IsNumber, IsString, Max, Min } from 'class-validator';
import { Field, InputType } from 'type-graphql';
import { typeInt } from '../../models';
import { IsCustomId } from '../../validators';

@InputType()
export class AbilityScoreUpdateDTO implements AbilityScoreUpdate {
  @Field()
  @IsCustomId('ABL')
  @IsNotEmpty()
  @IsString()
  id!: string;

  @Field(typeInt)
  @Max(20)
  @Min(0)
  @IsNumber()
  @IsNotEmpty()
  value!: number;
}
github goldcaddy77 / warthog / src / decorators / BooleanField.ts View on Github external
export function BooleanField(args: BooleanFieldOptions = {}): any {
  const options = { ...decoratorDefaults, ...args };
  const nullableOption = options.nullable === true ? { nullable: true } : {};
  const defaultOption =
    options.default === true || options.default === false ? { default: options.default } : {};

  const factories = [
    WarthogField('boolean', options),
    Field(() => GraphQLBoolean, {
      ...nullableOption,
      ...defaultOption
    }),
    Column({
      type: 'boolean',
      ...nullableOption,
      ...defaultOption
    }) as MethodDecoratorFactory
  ];

  return composeMethodDecorators(...factories);
}
github jmcdo29 / zeldaPlay / apps / api / src / app / character / models / character.graphql.ts View on Github external
@Field()
  bond!: string;

  @Field()
  flaw!: string;

  @Field(typeStrings)
  personalityTraits!: string[];

  @Field(typeStrings)
  proficiencies!: string[];

  @Field(typeStrings)
  languages!: string[];

  @Field(typeString)
  game = 'dd5';
}
github kazekyo / nestjs-graphql-relay / src / common / connection-paging.ts View on Github external
export function ConnectionType(
  TItemClass: ClassType,
  Edge: TypeValue,
) {
  @ObjectType({ isAbstract: true })
  abstract class Connection implements Relay.Connection {
    @Field()
    pageInfo!: PageInfo;

    @Field(() =&gt; [Edge])
    edges!: Array&gt;;
  }

  return Connection;
}
github magishift / magishift.core / packages / crud.1 / src / crud.resolver.ts View on Github external
@Field(() =&gt; ID, { nullable: false })
    id: string;
  }

  @ArgsType()
  class FilterResolver extends Filter {
    @Field(() =&gt; GraphQLJSONObject, { nullable: true })
    where?: Partial;

    @Field(() =&gt; GraphQLJSONObject, { nullable: true })
    whereOr?: Partial;
  }

  @ObjectType(`${nameCapFirst}FindAll`)
  class FindAllResult implements IFindAllResult {
    @Field(() =&gt; Int)
    totalCount: number;

    @Field(() =&gt; [dtoClass])
    items: TDto[];
  }

  @Resolver(() =&gt; dtoClass, { isAbstract: true })
  @UseInterceptors(ClassSerializerInterceptor)
  class CrudResolver implements ICrudResolver {
    constructor(
      protected readonly service: ICrudService,
      protected readonly mapper: ICrudMapper,
      protected readonly pubSub: PubSub,
    ) {}

    @Query(() =&gt; dtoClass, { name: findById })