@@ -40,23 +40,37 @@ public function getBaseQuery($value, array $args, ResolveContext $context, Resol
4040 if ($ value instanceof ContentEntityInterface) {
4141 $ query = parent ::getBaseQuery ($ value , $ args , $ context , $ info );
4242
43- // Add the target field condition to the query.
44- $ definition = $ this ->getPluginDefinition ();
45- $ key = $ definition ['entity_key ' ];
46- $ field = $ definition ['field ' ];
47- $ ids = array_map (function ($ item ) {
48- return $ item ['target_id ' ];
49- }, $ value ->get ($ field )->getValue ());
50-
43+ $ metadata = $ query ->getMetadata ('graphql_context ' );
44+ $ ids = $ metadata ['ids ' ];
5145 if (empty ($ ids )) {
5246 return NULL ;
5347 }
5448
49+ $ definition = $ this ->getPluginDefinition ();
50+ $ key = $ definition ['entity_key ' ];
5551 $ operator = is_array ($ ids ) ? 'IN ' : '= ' ;
5652 $ query ->condition ($ key , $ ids , $ operator );
5753
5854 return $ query ;
5955 }
6056 }
6157
58+ /**
59+ * {@inheritdoc}
60+ */
61+ protected function getQueryContext ($ value , array $ args , ResolveContext $ context , ResolveInfo $ info ) {
62+ $ context = parent ::getQueryContext ($ value , $ args , $ context , $ info );
63+
64+ // Add the target field condition to the query.
65+ $ definition = $ this ->getPluginDefinition ();
66+ $ field = $ definition ['field ' ];
67+ $ ids = array_map (function ($ item ) {
68+ return $ item ['target_id ' ];
69+ }, $ value ->get ($ field )->getValue ());
70+
71+ return [
72+ 'ids ' => $ ids ,
73+ ] + $ context ;
74+ }
75+
6276}
0 commit comments