public CustomerMutation(Func <ICustomerRepository> funcCustomerRepository, CustomerAddedMessageService customerAddedMessageService) { FieldAsync <CustomerType>( "CreateCustomer", "Create Customer", new QueryArguments(new QueryArgument <CustomerInputType>() { Name = "customer" }) , resolve: async context => { var customer = context.GetArgument <Customer>("customer"); return(await context.TryAsyncResolve(async c => await funcCustomerRepository().AddCustomer(customer))); }); FieldAsync <CustomerType>( "UpdateCustomer", "Update Customer", new QueryArguments(new QueryArgument <CustomerInputType>() { Name = "customer" }, new QueryArgument <IdGraphType>() { Name = "customerid" }), resolve: async context => { var customer = context.GetArgument <Customer>("customer"); var customerId = context.GetArgument <int>("customerid"); customer.Id = customerId; customerAddedMessageService.AddCustomerMessage(customer); return(await context.TryAsyncResolve(async c => await funcCustomerRepository().UpdateCustomer(customer))); } ); }
public CustomerAddedSubscription(CustomerAddedMessageService messageService) { Name = "Subscription"; AddField(new EventStreamFieldType() { Name = "CustomerAdded", Type = typeof(CustomerAddedMessageType), Resolver = new FuncFieldResolver <CustomerAddedMessage>(x => x.Source as CustomerAddedMessage), Subscriber = new EventStreamResolver <CustomerAddedMessage>(x => messageService.GetCustomerAddedMessage()) }); }