Skip to content

Commit

Permalink
Fix incompatibility with wp-graphql-gutenberg
Browse files Browse the repository at this point in the history
  • Loading branch information
pristas-peter committed May 2, 2020
1 parent 60a19df commit cf6c362
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "pristas-peter/wp-graphql-gutenberg-acf",
"description": "Expose acf blocks through graphql",
"type": "wordpress-plugin",
"require": {
"pristas-peter/wp-graphql-gutenberg": "^0.1.2"
"name": "pristas-peter/wp-graphql-gutenberg-acf",
"description": "Expose acf blocks through graphql",
"type": "wordpress-plugin",
"require": {
"pristas-peter/wp-graphql-gutenberg": "^0.2.0"
}
}
28 changes: 21 additions & 7 deletions plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@
* Description: Enable acf blocks in WP GraphQL.
* Author: pristas-peter
* Author URI:
* Version: 0.1.1
* License: MIT
* License URI: https://opensource.org/licenses/MIT
*
* License: GPL-3
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
*/

namespace WPGraphQLGutenbergACF;

use WPGraphQLGutenberg\WPGraphQLGutenberg;
use GraphQL\Type\Definition\Type;
use WPGraphQL\Data\DataSource;
use GraphQL\Type\Definition\CustomScalarType;
Expand Down Expand Up @@ -158,7 +155,7 @@ public static function get_link_type()

public static function format_graphql_block_type_acf_name($block_name)
{
return WPGraphQLGutenberg::format_graphql_block_type_name(
return \WPGraphQLGutenberg\Schema\Types\BlockTypes::format_block_name(
$block_name
) . 'Fields';
}
Expand Down Expand Up @@ -254,6 +251,8 @@ public function is_field_name_valid($name)
return !empty($name) && !is_numeric($name);
}

private $union_types_by_name = [];

protected function get_maybe_union_type(
$types,
$type_name,
Expand All @@ -266,10 +265,25 @@ protected function get_maybe_union_type(
} elseif ($count === 1) {
return $types[0];
} else {
$object_types = [];

foreach ($types as $type) {
if (array_key_exists($type, $this->union_types_by_name)) {
$object_types = array_merge($object_types, $this->union_types_by_name[$type]);
} else {
$object_types[] = $type;
}

}


register_graphql_union_type($type_name, [
'typeNames' => $types,
'typeNames' => $object_types,
'resolveType' => $resolve_type
]);

$this->union_types_by_name[$type_name] = $types;

return $type_name;
}
}
Expand Down

0 comments on commit cf6c362

Please sign in to comment.