Not able to retrieve GraphQL for form validation in webform

Created on 14 May 2025, about 2 months ago

Problem/Motivation

Currently, the GraphQL Compose Webform module does not expose form element validation properties such as required, required_error, pattern, pattern_error, and other validation-related options via the GraphQL schema. This is a limitation when building decoupled or headless applications that rely on Webform data to dynamically generate and validate frontend forms.

Developers are unable to retrieve essential validation rules that are configured in the Webform UI, making it difficult to replicate Drupal-side validation logic on the client-side using GraphQL.

Steps to reproduce

  1. Create a webform with one or more elements (e.g., textfield, email, etc.).
  2. Set validation properties such as:
    • Mark a field as required
    • Add a pattern or custom validation
    • Define corresponding error messages
  3. Use GraphQL to query the webform through the GraphQL Compose Webform module.
  4. Observe that validation-related metadata is not present in the GraphQL response.

Proposed resolution

Extend the GraphQL Compose Webform module to include validation-related properties for each element in the GraphQL schema and output. This could be done by:

  • Adding a validation object to each webform element type, including:
    • required (boolean)
    • required_error (string)
    • counter (boolean)
    • counter_type (string)
    • pattern (string)
    • pattern_error (string)
    • minlength, maxlength (integer)

Ensure this metadata is included in both the schema definition and the actual query response. This enhancement will allow frontend frameworks to implement the same validation logic as Drupal's Webform.

Remaining tasks

  • Review Webform element properties for all supported validation types.
  • Update schema definitions to include these new fields.
  • Update resolver logic to return these values for each element.
  • Write/update test coverage for validation-related fields.
  • Document usage in the module README or Drupal.org documentation.

User interface changes

None expected in the Drupal admin UI. This change only affects the GraphQL schema and API consumers.

API changes

GraphQL schema will be extended to expose additional validation metadata for webform elements.

Data model changes

No changes to the underlying Drupal data model or storage. This is purely an enhancement to GraphQL output.

Feature request
Status

Active

Version

1.3

Component

Code

Created by

🇮🇳India jayvala

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024