Skip to content

Commit

Permalink
VCST-2376: update GraphQL.NET to v8 (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksavosteev authored Jan 27, 2025
1 parent ca928db commit 2c53d91
Show file tree
Hide file tree
Showing 17 changed files with 69 additions and 76 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project>
<!-- These properties will be shared for all projects -->
<PropertyGroup>
<VersionPrefix>3.825.0</VersionPrefix>
<VersionPrefix>3.900.0</VersionPrefix>
<VersionSuffix>
</VersionSuffix>
<VersionSuffix Condition=" '$(VersionSuffix)' != '' AND '$(BuildNumber)' != '' ">$(VersionSuffix)-$(BuildNumber)</VersionSuffix>
Expand Down
2 changes: 2 additions & 0 deletions src/VirtoCommerce.QuoteModule.Core/Models/Address.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace VirtoCommerce.QuoteModule.Core.Models
[SwaggerSchemaId("QuoteAddress")]
public class Address : CoreModule.Core.Common.Address
{
public string Id { get => Key; set => Key = value; }

public TaxModule.Core.Model.Address ToTaxModel(TaxModule.Core.Model.Address target)
{
target.Key = Key;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
using MediatR;
using VirtoCommerce.CartModule.Core.Model;
using VirtoCommerce.CartModule.Core.Services;
using VirtoCommerce.Xapi.Core.Helpers;
using VirtoCommerce.Platform.Core.Common;
using VirtoCommerce.QuoteModule.Core.Services;
using VirtoCommerce.QuoteModule.ExperienceApi.Aggregates;
using VirtoCommerce.QuoteModule.ExperienceApi.Validation;
using VirtoCommerce.Xapi.Core.Helpers;
using VirtoCommerce.XCart.Core.Services;
using VirtoCommerce.XCart.Core.Validators;

Expand Down Expand Up @@ -86,9 +86,9 @@ protected virtual async Task ValidateCart(ShoppingCart cart)
});

// combine all errors
if (cartAggregate.ValidationErrors.Any() || cartAggregate.ValidationWarnings.Any() || lineItemValidationErrors.Any())
if (cartAggregate.GetValidationErrors().Any() || cartAggregate.ValidationWarnings.Any() || lineItemValidationErrors.Any())
{
var errors = cartAggregate.ValidationErrors
var errors = cartAggregate.GetValidationErrors()
.Union(cartAggregate.ValidationWarnings)
.Union(lineItemValidationErrors)
.GroupBy(x => x.ErrorCode)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using GraphQL.Types;
using VirtoCommerce.Xapi.Core.Infrastructure;
using VirtoCommerce.QuoteModule.ExperienceApi.Aggregates;
using VirtoCommerce.Xapi.Core.Infrastructure;

namespace VirtoCommerce.QuoteModule.ExperienceApi.Commands;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ public class UpdateQuoteDynamicPropertiesCommandType : QuoteCommandType<UpdateQu
{
public UpdateQuoteDynamicPropertiesCommandType()
{
Field<NonNullGraphType<ListGraphType<InputDynamicPropertyValueType>>>(
"dynamicProperties",
"Dynamic properties"
);
Field<NonNullGraphType<ListGraphType<InputDynamicPropertyValueType>>>("dynamicProperties")
.Description("Dynamic properties");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ public class InputQuoteAddressType : InputObjectGraphType<Address>
public InputQuoteAddressType()
{
Field<IntGraphType>(nameof(Address.AddressType));
Field<StringGraphType>("id", resolve: context => context.Source.Key);

Field(x => x.Id, nullable: true);
Field(x => x.Key, nullable: true);
Field(x => x.OuterId, nullable: true);
Field(x => x.Name, nullable: true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using GraphQL.Types;
using VirtoCommerce.QuoteModule.Core.Models;
using VirtoCommerce.Xapi.Core.Schemas;

namespace VirtoCommerce.QuoteModule.ExperienceApi.Schemas;

public class QuoteAddressType : ObjectGraphType<Address>
public class QuoteAddressType : ExtendableGraphType<Address>
{
public QuoteAddressType()
{
Field<IntGraphType>(nameof(Address.AddressType), resolve: context => (int)context.Source.AddressType);
Field<StringGraphType>("id", resolve: context => context.Source.Key, description: "ID");

Field<IntGraphType>(nameof(Address.AddressType)).Resolve(context => (int)context.Source.AddressType);
Field<StringGraphType>("id").Resolve(context => context.Source.Key).Description("ID");
Field(x => x.Key, nullable: true);
Field(x => x.OuterId, nullable: true);
Field(x => x.Name, nullable: true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using GraphQL.Types;
using VirtoCommerce.Xapi.Core.Schemas;
using VirtoCommerce.QuoteModule.Core.Models;
using VirtoCommerce.Xapi.Core.Schemas;

namespace VirtoCommerce.QuoteModule.ExperienceApi.Schemas;

Expand All @@ -10,11 +10,7 @@ public QuoteAttachmentType()
{
Field(x => x.Name, nullable: false);
Field(x => x.Url, nullable: false);
Field<StringGraphType>("ContentType", resolve: context => context.Source.MimeType);
Field<StringGraphType>("ContentType").Resolve(context => context.Source.MimeType);
Field(x => x.Size, nullable: false);

Field<StringGraphType>(nameof(QuoteAttachment.MimeType),
resolve: context => context.Source.MimeType,
deprecationReason: "Use ContentType");
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Linq;
using System.Threading.Tasks;
using GraphQL;
using GraphQL.DataLoader;
using GraphQL.Resolvers;
using GraphQL.Types;
Expand Down Expand Up @@ -30,16 +31,16 @@ public QuoteItemType(IMediator mediator, IDataLoaderContextAccessor dataLoader)
Field(x => x.Model.TaxType, nullable: true);
Field(x => x.Model.Quantity, nullable: false);

Field<NonNullGraphType<MoneyType>>(nameof(QuoteItem.ListPrice), resolve: context => context.Source.Model.ListPrice.ToMoney(context.Source.Quote.Currency));
Field<NonNullGraphType<MoneyType>>(nameof(QuoteItem.SalePrice), resolve: context => context.Source.Model.SalePrice.ToMoney(context.Source.Quote.Currency));
Field<NonNullGraphType<MoneyType>>(nameof(QuoteItem.ListPrice)).Resolve(context => context.Source.Model.ListPrice.ToMoney(context.Source.Quote.Currency));
Field<NonNullGraphType<MoneyType>>(nameof(QuoteItem.SalePrice)).Resolve(context => context.Source.Model.SalePrice.ToMoney(context.Source.Quote.Currency));

ExtendableField<QuoteTierPriceType>(nameof(QuoteItem.SelectedTierPrice), resolve: context => context.Source.SelectedTierPrice);
ExtendableField<NonNullGraphType<ListGraphType<NonNullGraphType<QuoteTierPriceType>>>>(nameof(QuoteItem.ProposalPrices), resolve: context => context.Source.ProposalPrices);

var productField = new FieldType
{
Name = "product",
Type = GraphTypeExtenstionHelper.GetActualType<ProductType>(),
Type = GraphTypeExtensionHelper.GetActualType<ProductType>(),
Resolver = new FuncFieldResolver<QuoteItemAggregate, IDataLoaderResult<ExpProduct>>(context =>
{
var loader = dataLoader.Context.GetOrAddBatchLoader<string, ExpProduct>("quote_lineItem_products", async ids =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using GraphQL.Types;
using VirtoCommerce.CoreModule.Core.Currency;
using VirtoCommerce.Xapi.Core.Schemas;
using VirtoCommerce.QuoteModule.Core.Models;
using VirtoCommerce.QuoteModule.ExperienceApi.Aggregates;
using VirtoCommerce.Xapi.Core.Schemas;

namespace VirtoCommerce.QuoteModule.ExperienceApi.Schemas;

Expand All @@ -14,7 +14,7 @@ public QuoteShipmentMethodType()
Field(x => x.Model.OptionName, nullable: true);
Field(x => x.Model.LogoUrl, nullable: true);
Field(x => x.Model.TypeName, nullable: true);
Field<NonNullGraphType<CurrencyType>>(nameof(ShipmentMethod.Currency), resolve: context => context.Source.Quote.Currency);
Field<NonNullGraphType<MoneyType>>(nameof(ShipmentMethod.Price), resolve: context => new Money(context.Source.Model.Price, context.Source.Quote.Currency));
Field<NonNullGraphType<CurrencyType>>(nameof(ShipmentMethod.Currency)).Resolve(context => context.Source.Quote.Currency);
Field<NonNullGraphType<MoneyType>>(nameof(ShipmentMethod.Price)).Resolve(context => new Money(context.Source.Model.Price, context.Source.Quote.Currency));
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using GraphQL.Types;
using VirtoCommerce.CoreModule.Core.Currency;
using VirtoCommerce.CoreModule.Core.Tax;
using VirtoCommerce.Xapi.Core.Schemas;
using VirtoCommerce.QuoteModule.ExperienceApi.Aggregates;
using VirtoCommerce.Xapi.Core.Schemas;

namespace VirtoCommerce.QuoteModule.ExperienceApi.Schemas;

public class QuoteTaxDetailType : ExtendableGraphType<QuoteTaxDetailAggregate>
{
public QuoteTaxDetailType()
{
Field<NonNullGraphType<MoneyType>>(nameof(TaxDetail.Rate), resolve: context => new Money(context.Source.Model.Rate, context.Source.Quote.Currency));
Field<NonNullGraphType<MoneyType>>(nameof(TaxDetail.Amount), resolve: context => new Money(context.Source.Model.Amount, context.Source.Quote.Currency));
Field<NonNullGraphType<MoneyType>>(nameof(TaxDetail.Rate)).Resolve(context => new Money(context.Source.Model.Rate, context.Source.Quote.Currency));
Field<NonNullGraphType<MoneyType>>(nameof(TaxDetail.Amount)).Resolve(context => new Money(context.Source.Model.Amount, context.Source.Quote.Currency));
Field(x => x.Model.Name, nullable: true);
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using GraphQL.Types;
using VirtoCommerce.Xapi.Core.Extensions;
using VirtoCommerce.Xapi.Core.Schemas;
using VirtoCommerce.QuoteModule.Core.Models;
using VirtoCommerce.QuoteModule.ExperienceApi.Aggregates;
using VirtoCommerce.Xapi.Core.Extensions;
using VirtoCommerce.Xapi.Core.Schemas;

namespace VirtoCommerce.QuoteModule.ExperienceApi.Schemas;

public class QuoteTierPriceType : ObjectGraphType<QuoteTierPriceAggregate>
public class QuoteTierPriceType : ExtendableGraphType<QuoteTierPriceAggregate>
{
public QuoteTierPriceType()
{
Field(x => x.Model.Quantity, nullable: false);
Field<NonNullGraphType<MoneyType>>(nameof(TierPrice.Price), resolve: context => context.Source.Model.Price.ToMoney(context.Source.Quote.Currency));
Field<NonNullGraphType<MoneyType>>(nameof(TierPrice.Price)).Resolve(context => context.Source.Model.Price.ToMoney(context.Source.Quote.Currency));
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
using GraphQL.Types;
using VirtoCommerce.CoreModule.Core.Currency;
using VirtoCommerce.Xapi.Core.Schemas;
using VirtoCommerce.QuoteModule.Core.Models;
using VirtoCommerce.QuoteModule.ExperienceApi.Aggregates;
using VirtoCommerce.Xapi.Core.Schemas;

namespace VirtoCommerce.QuoteModule.ExperienceApi.Schemas;

public class QuoteTotalsType : ObjectGraphType<QuoteTotalsAggregate>
public class QuoteTotalsType : ExtendableGraphType<QuoteTotalsAggregate>
{
public QuoteTotalsType()
{
Field<NonNullGraphType<MoneyType>>(nameof(QuoteRequestTotals.OriginalSubTotalExlTax), resolve: context => new Money(context.Source.Model.OriginalSubTotalExlTax, context.Source.Quote.Currency));
Field<NonNullGraphType<MoneyType>>(nameof(QuoteRequestTotals.SubTotalExlTax), resolve: context => new Money(context.Source.Model.SubTotalExlTax, context.Source.Quote.Currency));
Field<NonNullGraphType<MoneyType>>(nameof(QuoteRequestTotals.ShippingTotal), resolve: context => new Money(context.Source.Model.ShippingTotal, context.Source.Quote.Currency));
Field<NonNullGraphType<MoneyType>>(nameof(QuoteRequestTotals.DiscountTotal), resolve: context => new Money(context.Source.Model.DiscountTotal, context.Source.Quote.Currency));
Field<NonNullGraphType<MoneyType>>(nameof(QuoteRequestTotals.TaxTotal), resolve: context => new Money(context.Source.Model.TaxTotal, context.Source.Quote.Currency));
Field<NonNullGraphType<MoneyType>>(nameof(QuoteRequestTotals.AdjustmentQuoteExlTax), resolve: context => new Money(context.Source.Model.AdjustmentQuoteExlTax, context.Source.Quote.Currency));
Field<NonNullGraphType<MoneyType>>(nameof(QuoteRequestTotals.GrandTotalExlTax), resolve: context => new Money(context.Source.Model.GrandTotalExlTax, context.Source.Quote.Currency));
Field<NonNullGraphType<MoneyType>>(nameof(QuoteRequestTotals.GrandTotalInclTax), resolve: context => new Money(context.Source.Model.GrandTotalInclTax, context.Source.Quote.Currency));
Field<NonNullGraphType<MoneyType>>(nameof(QuoteRequestTotals.OriginalSubTotalExlTax)).Resolve(context => new Money(context.Source.Model.OriginalSubTotalExlTax, context.Source.Quote.Currency));
Field<NonNullGraphType<MoneyType>>(nameof(QuoteRequestTotals.SubTotalExlTax)).Resolve(context => new Money(context.Source.Model.SubTotalExlTax, context.Source.Quote.Currency));
Field<NonNullGraphType<MoneyType>>(nameof(QuoteRequestTotals.ShippingTotal)).Resolve(context => new Money(context.Source.Model.ShippingTotal, context.Source.Quote.Currency));
Field<NonNullGraphType<MoneyType>>(nameof(QuoteRequestTotals.DiscountTotal)).Resolve(context => new Money(context.Source.Model.DiscountTotal, context.Source.Quote.Currency));
Field<NonNullGraphType<MoneyType>>(nameof(QuoteRequestTotals.TaxTotal)).Resolve(context => new Money(context.Source.Model.TaxTotal, context.Source.Quote.Currency));
Field<NonNullGraphType<MoneyType>>(nameof(QuoteRequestTotals.AdjustmentQuoteExlTax)).Resolve(context => new Money(context.Source.Model.AdjustmentQuoteExlTax, context.Source.Quote.Currency));
Field<NonNullGraphType<MoneyType>>(nameof(QuoteRequestTotals.GrandTotalExlTax)).Resolve(context => new Money(context.Source.Model.GrandTotalExlTax, context.Source.Quote.Currency));
Field<NonNullGraphType<MoneyType>>(nameof(QuoteRequestTotals.GrandTotalInclTax)).Resolve(context => new Money(context.Source.Model.GrandTotalInclTax, context.Source.Quote.Currency));
}
}
24 changes: 12 additions & 12 deletions src/VirtoCommerce.QuoteModule.ExperienceApi/Schemas/QuoteType.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using GraphQL.Types;
using VirtoCommerce.QuoteModule.Core.Models;
using VirtoCommerce.QuoteModule.ExperienceApi.Aggregates;
using VirtoCommerce.Xapi.Core.Extensions;
using VirtoCommerce.Xapi.Core.Helpers;
using VirtoCommerce.Xapi.Core.Schemas;
using VirtoCommerce.Xapi.Core.Services;
using VirtoCommerce.QuoteModule.Core.Models;
using VirtoCommerce.QuoteModule.ExperienceApi.Aggregates;

namespace VirtoCommerce.QuoteModule.ExperienceApi.Schemas;

Expand Down Expand Up @@ -42,14 +42,14 @@ public QuoteType(IDynamicPropertyResolverService dynamicPropertyResolverService)
Field(x => x.Model.StoreId, nullable: false);
Field(x => x.Model.Tag, nullable: true);

Field<NonNullGraphType<CurrencyType>>(nameof(QuoteRequest.Currency),
resolve: context => context.Source.Currency);
Field<NonNullGraphType<MoneyType>>(nameof(QuoteRequest.ManualRelDiscountAmount),
resolve: context => context.Source.Model.ManualRelDiscountAmount.ToMoney(context.Source.Currency));
Field<NonNullGraphType<MoneyType>>(nameof(QuoteRequest.ManualShippingTotal),
resolve: context => context.Source.Model.ManualShippingTotal.ToMoney(context.Source.Currency));
Field<NonNullGraphType<MoneyType>>(nameof(QuoteRequest.ManualSubTotal),
resolve: context => context.Source.Model.ManualSubTotal.ToMoney(context.Source.Currency));
Field<NonNullGraphType<CurrencyType>>(nameof(QuoteRequest.Currency))
.Resolve(context => context.Source.Currency);
Field<NonNullGraphType<MoneyType>>(nameof(QuoteRequest.ManualRelDiscountAmount))
.Resolve(context => context.Source.Model.ManualRelDiscountAmount.ToMoney(context.Source.Currency));
Field<NonNullGraphType<MoneyType>>(nameof(QuoteRequest.ManualShippingTotal))
.Resolve(context => context.Source.Model.ManualShippingTotal.ToMoney(context.Source.Currency));
Field<NonNullGraphType<MoneyType>>(nameof(QuoteRequest.ManualSubTotal))
.Resolve(context => context.Source.Model.ManualSubTotal.ToMoney(context.Source.Currency));

ExtendableField<NonNullGraphType<QuoteTotalsType>>(nameof(QuoteRequest.Totals),
resolve: context => context.Source.Totals);
Expand All @@ -62,10 +62,10 @@ public QuoteType(IDynamicPropertyResolverService dynamicPropertyResolverService)
ExtendableField<QuoteShipmentMethodType>(nameof(QuoteRequest.ShipmentMethod), resolve: context => context.Source.ShipmentMethod);
ExtendableField<NonNullGraphType<ListGraphType<NonNullGraphType<QuoteTaxDetailType>>>>(nameof(QuoteRequest.TaxDetails), resolve: context => context.Source.TaxDetails);

ExtendableField<NonNullGraphType<ListGraphType<NonNullGraphType<DynamicPropertyValueType>>>>(
ExtendableFieldAsync<NonNullGraphType<ListGraphType<NonNullGraphType<DynamicPropertyValueType>>>>(
nameof(QuoteRequest.DynamicProperties),
"Quote dynamic property values",
QueryArgumentPresets.GetArgumentForDynamicProperties(),
context => dynamicPropertyResolverService.LoadDynamicPropertyValues(context.Source.Model, context.GetArgumentOrValue<string>("cultureName")));
async context => await dynamicPropertyResolverService.LoadDynamicPropertyValues(context.Source.Model, context.GetArgumentOrValue<string>("cultureName")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
<PackageReference Include="VirtoCommerce.FileExperienceApi.Data" Version="3.803.0" />
<PackageReference Include="VirtoCommerce.FileExperienceApi.Data" Version="3.900.0" />
<PackageReference Include="VirtoCommerce.OrdersModule.Core" Version="3.800.0" />
<PackageReference Include="VirtoCommerce.Xapi.Core" Version="3.814.0" />
<PackageReference Include="VirtoCommerce.XCart.Data" Version="3.800.0" />
<PackageReference Include="VirtoCommerce.Xapi.Core" Version="3.900.0" />
<PackageReference Include="VirtoCommerce.XCatalog.Core" Version="3.900.0" />
<PackageReference Include="VirtoCommerce.XCart.Data" Version="3.900.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\VirtoCommerce.QuoteModule.Core\VirtoCommerce.QuoteModule.Core.csproj" />
Expand Down
20 changes: 8 additions & 12 deletions src/VirtoCommerce.QuoteModule.Web/Module.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using System;
using System.IO;
using System.Threading.Tasks;
using GraphQL.Server;
using MediatR;
using GraphQL;
using GraphQL.MicrosoftDI;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using VirtoCommerce.FileExperienceApi.Core.Authorization;
using VirtoCommerce.Platform.Core.Common;
using VirtoCommerce.Platform.Core.DynamicProperties;
Expand Down Expand Up @@ -36,7 +35,6 @@
using VirtoCommerce.StoreModule.Core.Model;
using VirtoCommerce.Xapi.Core.Extensions;
using VirtoCommerce.Xapi.Core.Infrastructure;
using VirtoCommerce.Xapi.Core.Models;

namespace VirtoCommerce.QuoteModule.Web
{
Expand Down Expand Up @@ -81,12 +79,11 @@ public void Initialize(IServiceCollection serviceCollection)
serviceCollection.AddTransient<CancelQuoteEventHandler>();

// GraphQL
var assemblyMarker = typeof(AssemblyMarker);
var graphQlBuilder = new CustomGraphQLBuilder(serviceCollection);
graphQlBuilder.AddGraphTypes(assemblyMarker);
serviceCollection.AddMediatR(assemblyMarker);
serviceCollection.AddAutoMapper(assemblyMarker);
serviceCollection.AddSchemaBuilders(assemblyMarker);
_ = new GraphQLBuilder(serviceCollection, builder =>
{
builder.AddSchema(serviceCollection, typeof(AssemblyMarker));
});

serviceCollection.AddTransient<IQuoteAggregateRepository, QuoteAggregateRepository>();
serviceCollection.AddSingleton<IAuthorizationHandler, QuoteAuthorizationHandler>();
serviceCollection.AddSingleton<IFileAuthorizationRequirementFactory, QuoteAuthorizationRequirementFactory>();
Expand All @@ -98,8 +95,7 @@ public void PostInitialize(IApplicationBuilder appBuilder)
{
_appBuilder = appBuilder;

var playgroundOptions = appBuilder.ApplicationServices.GetService<IOptions<GraphQLPlaygroundOptions>>();
appBuilder.UseSchemaGraphQL<ScopedSchemaFactory<AssemblyMarker>>(playgroundOptions?.Value?.Enable ?? true, "quote");
appBuilder.UseScopedSchema<AssemblyMarker>("quote");

var dynamicPropertyRegistrar = appBuilder.ApplicationServices.GetRequiredService<IDynamicPropertyRegistrar>();
dynamicPropertyRegistrar.RegisterType<QuoteRequest>();
Expand Down
Loading

0 comments on commit 2c53d91

Please sign in to comment.