Custom datatype field not appearing in GraphQL builder

2025/09/12 11:58 AM

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:

1.00

Environment

Tags:
Xperience Administration v30.9.0 Custom modules

Answers

To response this discussion, you have to login first.