Archives: Filters

  • graphql_cursor_ordering_field

    Filters the field used for ordering connection queries when cursors are used for pagination

    apply_filters( 'graphql_cursor_ordering_field', array $field, \WPGraphQL\Data\Cursor\CursorBuilder $cursor_builder, \WPGraphQL\Data\Cursor\PostObjectCursor $object_cursor );

    Params

    • $field (array): The field used for ordering the cursor.
      • $key (string): The field key
      • $value (string): The field value
      • $type (string): The type the field should be cast as
      • $order (string): The order the field should be ordered by
    • $cursor_builder (\WPGraphQL\Data\Cursor\CursorBuilder): The instance of the CursorBuilder class, passed to the filter for context
    • $object_cursor (\WPGraphQL\Data\Cursor\PostObjectCursor): The instance of the PostObjectCursor class, passed to the filter for context
  • graphql_html_entity_decoding_enabled

    Given a string, and optional context, this decodes html entities if html_entity_decode is enabled

    apply_filters( 'graphql_html_entity_decoding_enabled', boolean $enabled, string $string, string $field_name, \WPGraphQL\Model\Model $model );

    Params

    • $enabled (string): Whether html_entity_decode should be applied to the string passed through the \WPGraphQL\Utils::html_entity_decode method.
    • $string (string): The string being passed through for possible decoding
    • $field_name (string): The field name being passed through for posible decoding
    • $model (\WPGraphQL\Model\Model): The Model that is being affected

    Examples

    Below are some examples showing how to use the graphql_html_entity_decoding_enabled filter.

    Disable html_entity_decoding for all fields

    This disables decoding for all fields it’s applied to:

    add_filter( 'graphql_html_entity_decoding_enabled', '__return_false' );

    Enable html_entity_decoding for all fields

    This enables decoding for all fields it’s applied to:

    add_filter( 'graphql_html_entity_decoding_enabled', '__return_true' );

    Enable html_entity_decoding for a specific field

    add_filter( 'graphql_html_entity_decoding_enabled', function( $enabled, $string, $field_name, $model ) {
            // Enable for the 'content' field on the 
    	if ( $model instanceof \WPGraphQL\Model\Post && 'contentRendered' === $field_name ) {
    		return true;
    	}
    	
    	return $enabled;
    
    }, 10, 4 );
  • graphql_wp_union_type_config

    Filter the config of WPUnionType

    apply_filters( 'graphql_wp_union_type_config', array $config, WPUnionType $union_type );

    Params

    • $config (array): Array of configuration options passed to the WPUnionType when instantiating a new type
    • $union_type (WPUnionType): The instance of the WPUnionType class
  • graphql_union_possible_types

    Filter the possible_types to allow systems to add to the possible resolveTypes.

    apply_filters( 'graphql_union_possible_types', array $types, array $config );

    Params

    • $types (array): The possible types for the Union
    • $config (array): The config for the Union Type
  • graphql_union_resolve_type

    Filter the resolve type method for all unions

    apply_filters( 'graphql_union_resolve_type', mixed $type, mixed $object, WPUnionType $union_type );

    Params

    • $type (mixed): The Type to resolve to, based on the object being resolved
    • $object (mixed): The Object being resolved
    • $union_type (WPUnionType): The WPUnionType instance
  • graphql_schema_config

    Set the $filterable_config as the $config that was passed to the WPSchema when instantiated

    apply_filters( 'graphql_schema_config', SchemaConfig $config );

    Params

    • $config (array): The WPSchema config to filter
  • graphql_custom_scalar_config

    Filter WPScalar config

    apply_filters( 'graphql_custom_scalar_config', array $config, TypeRegistry $type_registry );

    Params

    • $config (array): The WPScalar config
    • $type_registry (TypeRegistry): The TypeRegistry
  • graphql_object_fields

    Filter all object fields, passing the $typename as a param. This is useful when several different types need to be easily filtered at once. . .for example, if ALL types with a field of a certain name needed to be adjusted, or something to that tune.

    apply_filters( 'graphql_object_fields', array $fields, string $type_name, WPObjectType $object_type, TypeRegistry $type_registry );

    Params

    • $fields (array): The array of fields for the object config
    • $type_name (string): The name of the object type
    • $object_type (WPObjectType): The WPObjectType Class
    • $type_registry (TypeRegistry): The Type Registry
  • graphql_object_type_interfaces

    Filters the interfaces applied to an object type

    apply_filters( 'graphql_object_type_interfaces', array $interfaces, array $config, WPObjectType $object_type );

    Params

    • $interfaces (array): List of interfaces applied to the Object Type
    • $config (array): The config for the Object Type
    • $object_type (WPObjectType): The WPObjectType instance
  • graphql_wp_object_type_config

    Filter the config of WPObjectType

    apply_filters( 'graphql_wp_object_type_config', array $config, WPObjectType $object_type );

    Params

    • $config (array): Array of configuration options passed to the WPObjectType when instantiating a new type
    • $object_type (WPObjectType): The instance of the WPObjectType class