cacheableQueryHandler = $cacheableQueryHandler; } /** * Set cache validity to the cacheableQuery after resolving any resolver in a query * * @param ResolverInterface $subject * @param mixed|Value $resolvedValue * @param Field $field * @return mixed * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function afterResolve( ResolverInterface $subject, $resolvedValue, Field $field ) { $cacheAnnotation = $field->getCache(); if (!empty($cacheAnnotation)) { if (is_array($resolvedValue)) { $this->cacheableQueryHandler->handleCacheFromResolverResponse( $resolvedValue, $cacheAnnotation ); } elseif ($resolvedValue instanceof Value) { $resolvedValue->then( function () use ($resolvedValue, $field, $cacheAnnotation) { if (is_array($resolvedValue->result)) { $this->cacheableQueryHandler->handleCacheFromResolverResponse( $resolvedValue->result, $cacheAnnotation ); } else { // case if string or integer we pass in a single array element $this->cacheableQueryHandler->handleCacheFromResolverResponse( $resolvedValue->result === null ? [] : [$field->getName() => $resolvedValue->result], $cacheAnnotation ); } } ); } else { // case if string or integer we pass in a single array element $this->cacheableQueryHandler->handleCacheFromResolverResponse( $resolvedValue === null ? [] : [$field->getName() => $resolvedValue], $cacheAnnotation ); } } return $resolvedValue; } }