From 0f164fc8bdf173b7203ff2c3d1afb2913c9b95ac Mon Sep 17 00:00:00 2001 From: Jens Schulze Date: Fri, 26 Jul 2024 10:28:22 +0200 Subject: [PATCH] fix resolving of custom fields in GraphQL module (#336) --- .../Type/TypeIntegrationTests.cs | 82 +++++++++++++++++++ .../commercetools.Api.IntegrationTests.csproj | 4 +- .../config.zeroql.json | 2 +- 3 files changed, 86 insertions(+), 2 deletions(-) diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Type/TypeIntegrationTests.cs b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Type/TypeIntegrationTests.cs index 37a081dcc50..96c02340437 100644 --- a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Type/TypeIntegrationTests.cs +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/Type/TypeIntegrationTests.cs @@ -1,10 +1,18 @@ using System.Collections.Generic; +using System.Text.Json; +using System.Text.Json.Nodes; using System.Threading.Tasks; using commercetools.Sdk.Api.Client; using commercetools.Sdk.Api.Models.Common; using commercetools.Sdk.Api.Models.Types; +using commercetools.Sdk.GraphQL.Api; using Xunit; using static commercetools.Api.IntegrationTests.Type.TypeFixtures; +using static commercetools.Api.IntegrationTests.Cart.CartFixture; +using CustomFieldsDraft = commercetools.Sdk.Api.Models.Types.CustomFieldsDraft; +using FieldDefinition = commercetools.Sdk.Api.Models.Types.FieldDefinition; +using FieldType = commercetools.Sdk.Api.Models.Types.FieldType; +using LocalizedString = commercetools.Sdk.Api.Models.Common.LocalizedString; namespace commercetools.Api.IntegrationTests.Type { @@ -71,6 +79,80 @@ await WithType( }); } + [Fact] + public async Task CartWithCustomType() + { + var gqlClient = _client.GraphQLClient(); + + var key = $"QueryType-{TestingUtility.RandomString()}"; + + await WithType( + _client, + typeDraft => + { + var draft = DefaultTypeDraftWithKey(typeDraft, key); + draft.FieldDefinitions = new List() + { + new FieldDefinition() + { + Type = new CustomFieldStringType() + { + }, + Label = new LocalizedString() + { + {"en", "test-string"} + }, + Required = false, + Name = "test-string" + }, + new FieldDefinition() + { + Type = new CustomFieldSetType() + { + ElementType = new CustomFieldStringType() + }, + Label = new LocalizedString() + { + {"en", "test-set"} + }, + Required = false, + Name = "test-set" + } + }; + return draft; + }, + async type => + { + await WithCart(_client, cartDraft => + { + var draft = DefaultCartDraft(cartDraft); + draft.Custom = new CustomFieldsDraft() + { + Type = new TypeResourceIdentifier() { Key = type.Key }, + Fields = new FieldContainer() + { + { "test-set", new List() + { + "abc", + "def" + } + }, + { "test-string", "foo" + } + } + }; + return draft; + }, async cart => + { + var cartId = cart.Id; + var t = await gqlClient.Query(o => o.Cart(id: cartId, selector: cart => new { Custom = cart.Custom(custom => new { Field = custom.CustomFieldsRaw(selector: field => field.Value) })})); + Assert.Equal("abc", t.Data.Custom.Field[0].Deserialize>()[0]); + Assert.Equal("def", t.Data.Custom.Field[0].Deserialize>()[1]); + Assert.Equal("foo", t.Data.Custom.Field[1].ToString()); + }); + }); + } + [Fact] public async Task UpdateTypeByIdChangeDescription() { diff --git a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/commercetools.Api.IntegrationTests.csproj b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/commercetools.Api.IntegrationTests.csproj index 590d7b4773a..ed393c56f38 100644 --- a/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/commercetools.Api.IntegrationTests.csproj +++ b/commercetools.Sdk/IntegrationTests/commercetools.Api.IntegrationTests/commercetools.Api.IntegrationTests.csproj @@ -1,7 +1,7 @@  - net6.0 + net7.0 false 6e42aa04-1612-4e1c-8bb2-190e5c88343f true @@ -15,6 +15,7 @@ + @@ -32,6 +33,7 @@ + diff --git a/commercetools.Sdk/commercetools.Sdk.GraphQL.Api/config.zeroql.json b/commercetools.Sdk/commercetools.Sdk.GraphQL.Api/config.zeroql.json index 2749154078c..fa2814bd0bf 100644 --- a/commercetools.Sdk/commercetools.Sdk.GraphQL.Api/config.zeroql.json +++ b/commercetools.Sdk/commercetools.Sdk.GraphQL.Api/config.zeroql.json @@ -8,7 +8,7 @@ "BigDecimal": "System.Decimal", "Country": "System.String", "Locale": "System.String", - "Json": "System.String", + "Json": "System.Text.Json.Nodes.JsonValue", "KeyReferenceInput": "System.String", "Set": "System.String", "Time": "System.String",