Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

GraphQL Formatters

No security coverage Maintenance fixes only

Part of the Graphql ecosystem · 39 projects

This module allows you to use Drupal's existing field formatters within your GraphQL queries. It helps delegate rendering tasks like text truncation, date formatting, and currency display to Drupal, making it useful for progressively decoupled applications or when you want to leverage Drupal's rendering capabilities.

GraphQL Field Formatters and renderer helpers for fields.
Applies to GraphQL 3.x only.

Use case

When it makes sense to delegate the rendering to Drupal.

Examples:

  • delegate sanitizing to Twig instead of a Javascript library
  • delegate the rendering of complex data structures (e.g. paragraphs) to Drupal
  • in combination with GraphQL Twig
  • in a progressively decoupled setup, where markup is shared between decoupled
    / non decoupled components for styling.

For helpers like:

  • Text summary: truncate or reuse the field summary if available
  • Plain text: strip tags of formatted texts
  • Drupal date format
  • Currency
  • ...

Already supported by GraphQL 3.x core

You might not need this module for these use cases,
supported by the Drupal GraphQL core:

  • Format a date with inline format: entityCreated(format: "d/m/Y")
  • Render an entity with a view mode: entityRendered(mode: TEASER)
  • Image styles
  • ...

Dependencies

GraphQL 8.3.x

View Mode based Field Formatter

WIP, does not support all data types.

Inherits from the view mode configuration of the entity bundle.

Example:

query {
  nodeQuery {
    entities {
      ... on NodeArticle {
        fieldTextFormatted {
          viewModeFieldFormatter(mode: TEASER)
        }
      }
    }
  }
}

Settings based Field Formatter

WIP

Instead of inheriting from the view mode configuration, the
settings from the field are passed.

Example:

query {
  nodeQuery {
    entities {
      ... on NodeArticle {
        fieldTextFormatted {
          fieldFormatter(settings: {
            label: "hidden",
            trimmed: 600
          })
        }
      }
    }
  }
}

Other field based helpers

Text summary

WIP

query {
  nodeQuery {
    entities {
      ... on NodeArticle {
        fieldTextFormatted {
          textSummary(max_chars: 300)
        }
      }
    }
  }
}

Date based on the date formats (e.g. short, medium) - GraphQL Date

WIP

Currency formatter

WIP

Ask your assistant about GraphQL Formatters

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
1
Tracked since
Aug 2023
Latest release
3 years ago
Releases (12 mo)
0
Maintenance
Dormant

Releases

Version Type Core PHP Release date
2.0.x-dev Dev 8–10 Aug 16, 2023