@@ -12,6 +12,11 @@ class FieldConfig {
1212 */
1313 protected $ acf_field ;
1414
15+ /**
16+ * @var array
17+ */
18+ protected $ raw_field ;
19+
1520 /**
1621 * @var array
1722 */
@@ -46,12 +51,13 @@ class FieldConfig {
4651 * @throws \GraphQL\Error\Error
4752 */
4853 public function __construct ( array $ acf_field , array $ acf_field_group , Registry $ registry ) {
49- $ this ->acf_field = $ acf_field ;
54+ $ this ->raw_field = $ acf_field ;
55+ $ this ->acf_field = ! empty ( $ acf_field ['key ' ] ) && acf_get_field ( $ acf_field ['key ' ] ) ? acf_get_field ( $ acf_field ['key ' ] ) : $ acf_field ;
5056 $ this ->acf_field_group = $ acf_field_group ;
5157 $ this ->registry = $ registry ;
5258 $ this ->graphql_field_group_type_name = $ this ->registry ->get_field_group_graphql_type_name ( $ this ->acf_field_group );
5359 $ this ->graphql_field_name = $ this ->registry ->get_graphql_field_name ( $ this ->acf_field );
54- $ this ->graphql_field_type = Utils::get_graphql_field_type ( $ this ->acf_field ['type ' ] );
60+ $ this ->graphql_field_type = Utils::get_graphql_field_type ( $ this ->raw_field ['type ' ] );
5561 }
5662
5763 /**
@@ -85,7 +91,9 @@ public function get_graphql_field_type(): ?AcfGraphQLFieldType {
8591 public function get_parent_graphql_type_name ( array $ acf_field , ?string $ prepend = '' ): string {
8692 $ type_name = '' ;
8793
88- if ( ! empty ( $ acf_field ['parent ' ] ) ) {
94+ if ( ! empty ( $ acf_field ['parent_layout_group ' ] ) ) {
95+ $ type_name = $ this ->registry ->get_field_group_graphql_type_name ( $ acf_field ['parent_layout_group ' ] );
96+ } elseif ( ! empty ( $ acf_field ['parent ' ] ) ) {
8997 $ parent_field = acf_get_field ( $ acf_field ['parent ' ] );
9098 $ parent_group = acf_get_field_group ( $ acf_field ['parent ' ] );
9199 if ( ! empty ( $ parent_field ) ) {
@@ -137,7 +145,12 @@ public function get_field_description(): string {
137145 } else {
138146 // Fallback description
139147 // translators: %s is the name of the ACF Field Group
140- $ description = sprintf ( __ ( 'Field added to the schema as part of the "%s" Field Group ' , 'wp-graphql-acf ' ), $ this ->registry ->get_field_group_graphql_type_name ( $ this ->acf_field_group ) );
148+ $ description = sprintf (
149+ // translators: %1$s is the ACF Field Type and %2$s is the name of the ACF Field Group
150+ __ ( 'Field of the "%1$s" Field Type added to the schema as part of the "%2$s" Field Group ' , 'wp-graphql-acf ' ),
151+ $ this ->acf_field ['type ' ] ?? '' ,
152+ $ this ->registry ->get_field_group_graphql_type_name ( $ this ->acf_field_group )
153+ );
141154 }
142155
143156 return $ description ;
@@ -150,6 +163,13 @@ public function get_acf_field(): array {
150163 return $ this ->acf_field ;
151164 }
152165
166+ /**
167+ * @return array
168+ */
169+ public function get_raw_acf_field (): array {
170+ return $ this ->raw_field ;
171+ }
172+
153173 /**
154174 * @return array
155175 */
@@ -217,6 +237,12 @@ public function get_graphql_field_config():?array {
217237 return null ;
218238 }
219239
240+ // if the field type returns a NULL type,
241+ // bail and prevent the field from being directly mapped to the Schema
242+ if ( 'NULL ' === $ field_type ) {
243+ return null ;
244+ }
245+
220246 switch ( $ this ->acf_field ['type ' ] ) {
221247 case 'color_picker ' :
222248 case 'number ' :
@@ -288,6 +314,7 @@ public function should_format_field_value( string $field_type ): bool {
288314 'repeater ' ,
289315 'flexible_content ' ,
290316 'oembed ' ,
317+ 'clone ' ,
291318 ];
292319
293320 return in_array ( $ field_type , $ types_to_format , true );
@@ -347,10 +374,9 @@ public function resolve_field( $root, array $args, AppContext $context, ResolveI
347374 } elseif ( ! empty ( $ field_config ['__key ' ] ) ) {
348375 $ field_key = $ field_config ['__key ' ];
349376 }
350- $ cloned_field_config = acf_get_field ( $ field_key );
351- $ field_config = ! empty ( $ cloned_field_config ) ? $ cloned_field_config : $ field_config ;
352377 }
353378
379+
354380 $ should_format_value = false ;
355381
356382 if ( ! empty ( $ field_config ['type ' ] ) && $ this ->should_format_field_value ( $ field_config ['type ' ] ) ) {
@@ -362,7 +388,7 @@ public function resolve_field( $root, array $args, AppContext $context, ResolveI
362388 }
363389
364390 // if the field_config is empty or not an array, set it as an empty array as a fallback
365- $ field_config = ! empty ( $ field_config ) && is_array ( $ field_config ) ? $ field_config : [];
391+ $ field_config = ! empty ( $ field_config ) ? $ field_config : [];
366392
367393 // If the root being passed down already has a value
368394 // for the field key, let's use it to resolve
@@ -391,6 +417,7 @@ public function resolve_field( $root, array $args, AppContext $context, ResolveI
391417 return $ pre_value ;
392418 }
393419
420+ $ parent_field = null ;
394421 $ parent_field_name = null ;
395422 if ( ! empty ( $ field_config ['parent ' ] ) ) {
396423 $ parent_field = acf_get_field ( $ field_config ['parent ' ] );
@@ -419,6 +446,8 @@ public function resolve_field( $root, array $args, AppContext $context, ResolveI
419446 }
420447 }
421448
449+
450+
422451 // If there's no node_id at this point, we can return null
423452 if ( empty ( $ return_value ) && empty ( $ node_id ) ) {
424453 return null ;
@@ -429,7 +458,6 @@ public function resolve_field( $root, array $args, AppContext $context, ResolveI
429458 $ return_value = $ this ->get_field ( $ field_key , $ parent_field_name , $ node_id , $ should_format_value );
430459 }
431460
432-
433461 // Prepare the value for response
434462 $ prepared_value = $ this ->prepare_acf_field_value ( $ return_value , $ root , $ node_id , $ field_config );
435463 // Empty values are set to null
0 commit comments