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

2025/09/13 12:46 AM
Accepted answer

I don't think this is currently supported. The registration of GraphQL types (ex: your content type) and their fields is automatic, internal, and there are no API hooks into this process.

Additionally, the list of supported data types (the value you provide as the 2nd parameter to new DataType() which sets the fieldType is set to the list of scalar types used in Xperience. There's no way to add your custom data type to the list.

You can see what the underlying type registration process looks like for HotChocolate, but our use of it isn't customizable by you for headless channels.

I'd recommend giving some feedback on our roadmap about this use-case (which makes sense to me) so that it could be a future improvement to headless channels.

To response this discussion, you have to login first.