Skip to content
This repository was archived by the owner on Jul 23, 2024. It is now read-only.

Commit c4a00b7

Browse files
committed
#152 - This adds support for WPGraphQL Preview
1 parent 8748465 commit c4a00b7

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/class-config.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ class Config {
2424

2525
protected $type_registry;
2626

27+
/**
28+
* @var array <string> List of field names registered to the Schema
29+
*/
30+
protected $registered_field_names;
31+
2732
/**
2833
* Initialize WPGraphQL to ACF
2934
*
@@ -48,6 +53,13 @@ public function init( \WPGraphQL\Registry\TypeRegistry $type_registry ) {
4853
$this->add_acf_fields_to_individual_posts();
4954
$this->add_acf_fields_to_users();
5055
$this->add_acf_fields_to_options_pages();
56+
57+
add_filter( 'graphql_resolve_revision_meta_from_parent', function( $should, $object_id, $meta_key, $single ) {
58+
if ( in_array( $meta_key, $this->registered_field_names, true ) ) {
59+
return false;
60+
}
61+
return $should;
62+
}, 10, 4 );
5163
}
5264

5365
/**
@@ -360,6 +372,8 @@ protected function register_graphql_field( $type_name, $field_name, $config ) {
360372
return false;
361373
}
362374

375+
376+
363377
/**
364378
* filter the field config for custom field types
365379
*
@@ -729,7 +743,7 @@ protected function register_graphql_field( $type_name, $field_name, $config ) {
729743
$type = $tax_object->graphql_single_name;
730744
}
731745
}
732-
746+
733747
$is_multiple = isset($acf_field['field_type']) && in_array( $acf_field['field_type'], array('checkbox', 'multi_select'));
734748

735749
$field_config = [
@@ -1035,6 +1049,7 @@ protected function register_graphql_field( $type_name, $field_name, $config ) {
10351049

10361050
$config = array_merge( $config, $field_config );
10371051

1052+
$this->registered_field_names[] = $acf_field['name'];
10381053
return $this->type_registry->register_field( $type_name, $field_name, $config );
10391054
}
10401055

0 commit comments

Comments
 (0)