public Query(ITemperatureQueryService temperatureQueryService, IRoomQueryService roomQueryService) { this.temperatureQueryService = temperatureQueryService; this.roomQueryService = roomQueryService; Name = "Query"; Field <ListGraphType <TemperatureReading> >("temperatureReadings", resolve: context => temperatureQueryService.GetAll()); Field <TemperatureReading>("temperatureReading", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "id", Description = "id of the reading" } ), resolve: context => temperatureQueryService.GetById(context.GetArgument <string>("id")) ); Field <ListGraphType <Room> >("rooms", resolve: context => roomQueryService.GetAll()); Field <Room>("room", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "id", Description = "id of the room" }), resolve: context => roomQueryService.GetById(context.GetArgument <string>("id")) ); }
public Mutation( ITemperatureCommandService temperatureCommandService, ITemperatureQueryService temperatureQueryService, IRoomCommandService roomCommandService, IRoomQueryService roomQueryService, IEventHandler eventHandler) { this.temperatureCommandService = temperatureCommandService; this.temperatureQueryService = temperatureQueryService; this.roomCommandService = roomCommandService; this.roomQueryService = roomQueryService; this.eventHandler = eventHandler; Name = "Mutation"; Field <TemperatureReading>( "registerReading", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <RegisterTemperatureReading> > { Name = "temperatureReading" } ), resolve: context => { var command = context.GetArgument <API.Command.Commands.RegisterTemperatureReading>("temperatureReading"); var id = this.temperatureCommandService.RegisterReading(command); return(this.temperatureQueryService.GetById(id)); }); Field <Room>( "registerRoom", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <RegisterRoom> > { Name = "room" } ), resolve: context => { var command = context.GetArgument <API.Command.Commands.RegisterRoom>("room"); var id = this.roomCommandService.RegisterRoom(command); var room = this.roomQueryService.GetById(id); eventHandler.AddRoom(room); return(room); }); }