import { Field, ObjectType } from "@nestjs/graphql";
@ObjectType()
export class Restaurant {
@Field(type => String)
name: string;
@Field(type => Boolean)
isVegan: boolean;
@Field(type => String)
address: string;
@Field(type => String)
ownersName: string;
}
import { ArgsType, Field } from "@nestjs/graphql";
import { IsBoolean, IsString, Length } from "class-validator"
@ArgsType()
export class CreateRestaurantDto {
@Field(type => String)
@IsString()
@Length(5, 10)
name: string;
@Field(type => Boolean)
@IsBoolean()
isVegan: boolean;
@Field(type => String)
@IsString()
address: string;
@Field(type => String)
@IsString()
ownersName: string;
}
import { Args, Mutation, Query, Resolver } from "@nestjs/graphql";
import { CreateRestaurantDto } from "./dtos/create-restaurant.dto";
import { Restaurant } from "./entities/restaurant.entity";
@Resolver(of => Restaurant)
export class RestaurantResolver {
@Query(returns => [Restaurant])
restaurants(@Args("veganOnly") veganOnly: boolean): Restaurant[] {
return [];
}
@Mutation(returns => Boolean)
createRestaurant(@Args() createRestaurantDto: CreateRestaurantDto): boolean {
return true;
}
}