Custom datatype field not appearing in GraphQL builder
I created a custom datatype in Xperience by Kentico to store multiple summaries. In the database, it is saved as a string array, for example:
["<p>summary1</p>", "<p>summary2</p>"]
I created a reusable content type with a field of this custom datatype. In Content Hub, I can create new content without any problem, and I can also see the saved value in the database.
However, in GraphQL builder, I can see the normal fields, but the field with the custom datatype is missing.
Do I need to configure something extra to make this custom field appear in GraphQL?
WebAdminModule.cs / OnPreInit
protected override void OnPreInit()
{
base.OnPreInit();
DataTypeManager.RegisterDataTypes(
new DataType<IEnumerable<string>>(
"nvarchar(max)",
"stringArray",
"xs:string",
conversionFunc: JsonDataTypeConverter.ConvertToModels,
dbConversionFunc: JsonDataTypeConverter.ConvertToString,
new DefaultDataTypeTextSerializer("stringArray")
)
{
TypeAlias = "String",
SqlValueFormat = DataTypeManager.UNICODE,
DbType = SqlDbType.NVarChar,
DefaultValueCode = "[]",
DefaultValue = [],
HasConfigurableDefaultValue = false,
}
);
DataTypeCodeGenerationManager.RegisterDataTypeCodeGenerator(
"stringArray",
() =>
new DataTypeCodeGenerator(
field => "IEnumerable<string>",
field => nameof(ValidationHelper.GetString),
field => "[]",
field => ["System.Collections.Generic"]
)
);
RegisterDefaultValueComponent(
"stringArray",
MultiSummaryFormComponent.IDENTIFIER,
(val) =>
val is IEnumerable<string> array
? JsonDataTypeConverter
.ConvertToString(array, Array.Empty<string>(), CultureInfo.InvariantCulture)
.ToString() ?? "[]"
: "[]",
(val) =>
JsonDataTypeConverter.ConvertToModels<string>(val, [], CultureInfo.InvariantCulture)
);
}
MultiSummaryFormComponent
.cs
[assembly: RegisterFormComponent(
MultiSummaryFormComponent.IDENTIFIER,
typeof(MultiSummaryFormComponent),
MultiSummaryFormComponent.DISPLAY_NAME
)]
[ComponentAttribute(typeof(MultiSummaryComponentAttribute))]
public sealed class MultiSummaryFormComponent
: FormComponent<
MultiSummaryFormComponentProperties,
MultiSummaryFormComponentClientProperties,
IEnumerable<string>
>
{
public const string IDENTIFIER = "MultiSummary";
public const string DISPLAY_NAME = "PortalGrup - Multi Summary";
public override string ClientComponentName => $"@portalgrup/adminui/{IDENTIFIER}";
protected override Task ConfigureClientProperties(
MultiSummaryFormComponentClientProperties clientProperties
)
{
base.ConfigureClientProperties(clientProperties);
clientProperties.MaxItems = Properties.MaxItems;
clientProperties.AddButtonText = Properties.AddButtonText;
clientProperties.RemoveButtonText = Properties.RemoveButtonText;
clientProperties.PlaceholderText = Properties.PlaceholderText;
// Initialize with empty array if no value exists
clientProperties.Value ??= [];
return Task.CompletedTask;
}
public override void SetValue(IEnumerable<string> value)
{
// Filter out empty or null strings and set the value
string[] filteredValue = value?.Where(s => !string.IsNullOrEmpty(s)).ToArray() ?? [];
if (filteredValue.Length > 0)
{
base.SetValue(filteredValue);
}
}
}
Admin UI:
Environment
Xperience by Kentico version: [30.9.0]
.NET version: [9]
Execution environment: [SaaS|Private cloud (Azure/AWS/Virtual machine)]
Link to relevant: https://community.kentico.com/blog/embedded-structured-content-and-the-power-of-custom-data-types
Answers
To response this discussion, you have to login first.