@@ -28,12 +28,14 @@ abstract class UnionTypePluginBase extends PluginBase implements TypeSystemPlugi
2828 */
2929 public function getDefinition (PluggableSchemaBuilderInterface $ schemaBuilder ) {
3030 if (!isset ($ this ->definition )) {
31- $ name = $ this ->buildName ();
31+ $ definition = $ this ->getPluginDefinition ();
32+ $ typeNames = $ definition ['types ' ];
33+ $ unionName = $ this ->buildName ();
3234
3335 $ this ->definition = new UnionType ($ this , $ schemaBuilder , [
34- 'name ' => $ name ,
36+ 'name ' => $ unionName ,
3537 'description ' => $ this ->buildDescription (),
36- 'types ' => $ this ->buildTypes ($ schemaBuilder , $ name ),
38+ 'types ' => $ this ->buildTypes ($ schemaBuilder , $ unionName , $ typeNames ),
3739 ]);
3840 }
3941
@@ -43,20 +45,25 @@ public function getDefinition(PluggableSchemaBuilderInterface $schemaBuilder) {
4345 /**
4446 * Builds the list of types that are contained within this union type.
4547 *
48+ * Collects types that are explicitly referenced by this union type or that
49+ * are implicitly assigned by the type itself.
50+ *
4651 * @param \Drupal\graphql\Plugin\GraphQL\PluggableSchemaBuilderInterface $schemaBuilder
4752 * The schema manager.
48- * @param $name
53+ * @param $unionName
4954 * The name of this plugin.
55+ * @param $typeNames
56+ * List of types that this union contains explicitly.
5057 *
5158 * @return \Drupal\graphql\GraphQL\Type\ObjectType[]
5259 * An array of types to add to this union type.
5360 */
54- protected function buildTypes (PluggableSchemaBuilderInterface $ schemaBuilder , $ name ) {
61+ protected function buildTypes (PluggableSchemaBuilderInterface $ schemaBuilder , $ unionName , $ typeNames ) {
5562 /** @var \Drupal\graphql\GraphQL\Type\ObjectType[] $types */
56- $ types = array_map (function (TypeSystemPluginInterface $ type ) use ($ schemaBuilder ) {
63+ $ types = array_map (function (TypeSystemPluginInterface $ type ) use ($ typeNames , $ schemaBuilder ) {
5764 return $ type ->getDefinition ($ schemaBuilder );
58- }, $ schemaBuilder ->find (function ($ type ) use ($ name ) {
59- return in_array ($ name , $ type ['unions ' ]);
65+ }, $ schemaBuilder ->find (function ($ type ) use ($ typeNames , $ unionName ) {
66+ return in_array ($ unionName , $ type ['unions ' ]) || in_array ( $ type [ ' name ' ], $ typeNames );
6067 }, [
6168 GRAPHQL_TYPE_PLUGIN ,
6269 ]));
0 commit comments