Automattic\WooCommerce\Api\Infrastructure
QueryInfoExtractor::build_field_entry
Build the entry for a single field node.
Method of the class: QueryInfoExtractor{}
No Hooks.
Returns
array|bool. True for leaf fields, associative array otherwise.
Usage
$result = QueryInfoExtractor::build_field_entry( $field, $variable_values, $fragments ): array|bool;
- $field(FieldNode) (required)
- The field node.
- $variable_values(array) (required)
- Variable values for resolving arguments.
- $fragments(array<string, FragmentDefinitionNode>) (required)
- Named fragment definitions from the document.
QueryInfoExtractor::build_field_entry() QueryInfoExtractor::build field entry code WC 11.0.1
private static function build_field_entry( FieldNode $field, array $variable_values, array $fragments ): array|bool {
$has_args = ! empty( $field->arguments ) && count( $field->arguments ) > 0;
$has_sub_selection = null !== $field->selectionSet;
if ( ! $has_args && ! $has_sub_selection ) {
return true;
}
$entry = array();
if ( $has_args ) {
$args = array();
foreach ( $field->arguments as $arg ) {
$args[ $arg->name->value ] = self::resolve_argument_value( $arg, $variable_values );
}
$entry['__args'] = $args;
}
if ( $has_sub_selection ) {
$sub = self::extract( $field->selectionSet, $variable_values, $fragments );
$entry = self::merge_selections( $entry, $sub );
}
return $entry;
}