import { Cupcake as DomainCupcake , Order as DomainOrder } from '@cupcake/domain' ; import { OrderService } from '@cupcake/services' ; import { Arg , Mutation , Query , Resolver } from 'type-graphql' ; import { Cupcake } from '../cupcake/Cupcake' ; import { Order } from './Order' ; @ Resolver ( ) export class OrderResolver { constructor ( private readonly orderService ) { } @ Query ( ( ) => [ Order ] ) async orders ( ) { return this . orderService . all ( ) ; } @ Query ( ( ) => Order , { nullable : true } ) async order ( @ Arg ( 'id' ) id ) { return this . orderService . load ( id ) ; } @ Mutation ( ( ) => Order ) async createOrder ( @ Arg ( 'customerName' ) customerName , @ Arg ( 'deliveryAddress' ) deliveryAddress , @ Arg ( 'items' , ( ) => [ Cupcake ] ) items ) { const newOrder = await this . orderService . create ( { customerName , deliveryAddress , items , } ) ; return newOrder ; } }