public void GetComplexType_HasOverriddenType_OverriddenTypeReturned() { // Arrange AbstractTypeFactory <IGraphType> .OverrideType <FooType, FooTypeExtended>(); // Act var targetType = GraphTypeExtenstionHelper.GetActualComplexType <FooType>(); // Assert targetType.Name.Should().Be(nameof(FooTypeExtended)); }
public void GetComplexTypeThreeLevels_HasOverriddenType_OverriddenTypeReturned() { // Arrange AbstractTypeFactory <IGraphType> .OverrideType <FooType, FooTypeExtended>(); // Act var targetType = GraphTypeExtenstionHelper.GetActualComplexType <FooComplex2 <FooComplex <FooType> > >(); // Assert typeof(FooComplex2 <FooComplex <FooType> >).GenericTypeArguments[0].GenericTypeArguments.Should().OnlyContain(x => x.Name.EqualsInvariant(nameof(FooType))); targetType.GenericTypeArguments[0].GenericTypeArguments.Should().OnlyContain(x => x.Name.EqualsInvariant(nameof(FooTypeExtended))); }
public FieldType ExtendableField <TGraphType>( string name, string description = null, QueryArguments arguments = null, Func <IResolveFieldContext <TSourceType>, object> resolve = null, string deprecationReason = null) where TGraphType : IGraphType { return(AddField(new FieldType { Name = name, Description = description, DeprecationReason = deprecationReason, Type = GraphTypeExtenstionHelper.GetActualComplexType <TGraphType>(), Arguments = arguments, Resolver = resolve != null ? new FuncFieldResolver <TSourceType, object>(context => { context.CopyArgumentsToUserContext(); return resolve(context); }) : null })); }
public void Build(ISchema schema) { ValueConverter.Register <ExpOrderAddress, Optional <ExpOrderAddress> >(x => new Optional <ExpOrderAddress>(x)); _ = schema.Query.AddField(new FieldType { Name = "order", Arguments = AbstractTypeFactory <OrderQueryArguments> .TryCreateInstance(), Type = GraphTypeExtenstionHelper.GetActualType <CustomerOrderType>(), Resolver = new AsyncFieldResolver <object>(async context => { var request = context.ExtractQuery <GetOrderQuery>(); context.CopyArgumentsToUserContext(); var orderAggregate = await _mediator.Send(request); var authorizationResult = await _authorizationService.AuthorizeAsync(context.GetCurrentPrincipal(), orderAggregate.Order, new CanAccessOrderAuthorizationRequirement()); if (!authorizationResult.Succeeded) { throw new AuthorizationError($"Access denied"); } var allCurrencies = await _currencyService.GetAllCurrenciesAsync(); //Store all currencies in the user context for future resolve in the schema types context.SetCurrencies(allCurrencies, request.CultureName); //store order aggregate in the user context for future usage in the graph types resolvers context.SetExpandedObjectGraph(orderAggregate); return(orderAggregate); }) }); var orderConnectionBuilder = GraphTypeExtenstionHelper .CreateConnection <CustomerOrderType, object>() .Name("orders") .PageSize(20) .Arguments(); orderConnectionBuilder.ResolveAsync(async context => await ResolveOrdersConnectionAsync(_mediator, context)); schema.Query.AddField(orderConnectionBuilder.FieldType); var paymentsConnectionBuilder = GraphTypeExtenstionHelper .CreateConnection <PaymentInType, object>() .Name("payments") .PageSize(20) .Arguments(); paymentsConnectionBuilder.ResolveAsync(async context => await ResolvePaymentsConnectionAsync(_mediator, context)); schema.Query.AddField(paymentsConnectionBuilder.FieldType); _ = schema.Mutation.AddField(FieldBuilder.Create <object, CustomerOrderAggregate>(GraphTypeExtenstionHelper.GetActualType <CustomerOrderType>()) .Name("createOrderFromCart") .Argument(GraphTypeExtenstionHelper.GetActualComplexType <NonNullGraphType <InputCreateOrderFromCartType> >(), _commandName) .ResolveAsync(async context => { var type = GenericTypeHelper.GetActualType <CreateOrderFromCartCommand>(); var response = (CustomerOrderAggregate)await _mediator.Send(context.GetArgument(type, _commandName)); context.SetExpandedObjectGraph(response); return(response); }) .FieldType); _ = schema.Mutation.AddField(FieldBuilder.Create <object, bool>(typeof(BooleanGraphType)) .Name("changeOrderStatus") .Argument(GraphTypeExtenstionHelper.GetActualComplexType <NonNullGraphType <InputChangeOrderStatusType> >(), _commandName) .ResolveAsync(async context => { var type = GenericTypeHelper.GetActualType <ChangeOrderStatusCommand>(); var command = (ChangeOrderStatusCommand)context.GetArgument(type, _commandName); await CheckAuthAsync(context, command.OrderId); return(await _mediator.Send(command)); }) .FieldType); _ = schema.Mutation.AddField(FieldBuilder.Create <object, ProcessPaymentRequestResult>(typeof(ProcessPaymentRequestResultType)) .Name("processOrderPayment") .Argument(GraphTypeExtenstionHelper.GetActualComplexType <NonNullGraphType <InputProcessOrderPaymentType> >(), _commandName) .ResolveAsync(async context => { var type = GenericTypeHelper.GetActualType <ProcessOrderPaymentCommand>(); var command = (ProcessOrderPaymentCommand)context.GetArgument(type, _commandName); await CheckAuthAsync(context, command.OrderId); return(await _mediator.Send(command)); }) .DeprecationReason("Obsolete. Use 'initializePayment' mutation") .FieldType); _ = schema.Mutation.AddField(FieldBuilder.Create <object, InitializePaymentResult>(typeof(InitializePaymentResultType)) .Name("initializePayment") .Argument(GraphTypeExtenstionHelper.GetActualComplexType <NonNullGraphType <InputInitializePaymentType> >(), _commandName) .ResolveAsync(async context => { var type = GenericTypeHelper.GetActualType <InitializePaymentCommand>(); var command = (InitializePaymentCommand)context.GetArgument(type, _commandName); await CheckAuthAsync(context, command.OrderId); return(await _mediator.Send(command)); }) .FieldType); _ = schema.Mutation.AddField(FieldBuilder.Create <object, AuthorizePaymentResult>(typeof(AuthorizePaymentResultType)) .Name("authorizePayment") .Argument(GraphTypeExtenstionHelper.GetActualComplexType <NonNullGraphType <InputAuthorizePaymentType> >(), _commandName) .ResolveAsync(async context => { var type = GenericTypeHelper.GetActualType <AuthorizePaymentCommand>(); var command = (AuthorizePaymentCommand)context.GetArgument(type, _commandName); await CheckAuthAsync(context, command.OrderId); return(await _mediator.Send(command)); }) .FieldType); _ = schema.Mutation.AddField(FieldBuilder.Create <CustomerOrderAggregate, CustomerOrderAggregate>(GraphTypeExtenstionHelper.GetActualType <CustomerOrderType>()) .Name("updateOrderDynamicProperties") .Argument(GraphTypeExtenstionHelper.GetActualComplexType <NonNullGraphType <InputUpdateOrderDynamicPropertiesType> >(), _commandName) .ResolveAsync(async context => { var type = GenericTypeHelper.GetActualType <UpdateOrderDynamicPropertiesCommand>(); var command = (UpdateOrderDynamicPropertiesCommand)context.GetArgument(type, _commandName); await CheckAuthAsync(context, command.OrderId); return(await _mediator.Send(command)); }) .FieldType); _ = schema.Mutation.AddField(FieldBuilder.Create <CustomerOrderAggregate, CustomerOrderAggregate>(GraphTypeExtenstionHelper.GetActualType <CustomerOrderType>()) .Name("updateOrderItemDynamicProperties") .Argument(GraphTypeExtenstionHelper.GetActualComplexType <NonNullGraphType <InputUpdateOrderItemDynamicPropertiesType> >(), _commandName) .ResolveAsync(async context => { var type = GenericTypeHelper.GetActualType <UpdateOrderItemDynamicPropertiesCommand>(); var command = (UpdateOrderItemDynamicPropertiesCommand)context.GetArgument(type, _commandName); await CheckAuthAsync(context, command.OrderId); return(await _mediator.Send(command)); }) .FieldType); _ = schema.Mutation.AddField(FieldBuilder.Create <CustomerOrderAggregate, CustomerOrderAggregate>(GraphTypeExtenstionHelper.GetActualType <CustomerOrderType>()) .Name("updateOrderPaymentDynamicProperties") .Argument(GraphTypeExtenstionHelper.GetActualComplexType <NonNullGraphType <InputUpdateOrderPaymentDynamicPropertiesType> >(), _commandName) .ResolveAsync(async context => { var type = GenericTypeHelper.GetActualType <UpdateOrderPaymentDynamicPropertiesCommand>(); var command = (UpdateOrderPaymentDynamicPropertiesCommand)context.GetArgument(type, _commandName); await CheckAuthAsync(context, command.OrderId); return(await _mediator.Send(command)); }) .FieldType); _ = schema.Mutation.AddField(FieldBuilder.Create <CustomerOrderAggregate, CustomerOrderAggregate>(GraphTypeExtenstionHelper.GetActualType <CustomerOrderType>()) .Name("updateOrderShipmentDynamicProperties") .Argument(GraphTypeExtenstionHelper.GetActualComplexType <NonNullGraphType <InputUpdateOrderShipmentDynamicPropertiesType> >(), _commandName) .ResolveAsync(async context => { var type = GenericTypeHelper.GetActualType <UpdateOrderShipmentDynamicPropertiesCommand>(); var command = (UpdateOrderShipmentDynamicPropertiesCommand)context.GetArgument(type, _commandName); await CheckAuthAsync(context, command.OrderId); return(await _mediator.Send(command)); }) .FieldType); _ = schema.Mutation.AddField(FieldBuilder.Create <CustomerOrderAggregate, CustomerOrderAggregate>(GraphTypeExtenstionHelper.GetActualType <CustomerOrderType>()) .Name("addOrUpdateOrderPayment") .Argument(GraphTypeExtenstionHelper.GetActualComplexType <NonNullGraphType <InputAddOrUpdateOrderPaymentType> >(), _commandName) .ResolveAsync(async context => { var type = GenericTypeHelper.GetActualType <AddOrUpdateOrderPaymentCommand>(); var command = (AddOrUpdateOrderPaymentCommand)context.GetArgument(type, _commandName); await CheckAuthAsync(context, command.OrderId); var response = await _mediator.Send(command); context.SetExpandedObjectGraph(response); return(response); }) .FieldType); }