GraphQL\Type\Definition\ObjectType::isTypeOf PHP Method

isTypeOf() public method

public isTypeOf ( $value, $context, ResolveInfo $info ) : boolean | null
$value
$context
$info ResolveInfo
return boolean | null
    public function isTypeOf($value, $context, ResolveInfo $info)
    {
        return isset($this->config['isTypeOf']) ? call_user_func($this->config['isTypeOf'], $value, $context, $info) : null;
    }

Usage Example

示例#1
0
 /**
  * Complete an Object value by executing all sub-selections.
  *
  * @param ExecutionContext $exeContext
  * @param ObjectType $returnType
  * @param $fieldNodes
  * @param ResolveInfo $info
  * @param array $path
  * @param $result
  * @return array|Promise|\stdClass
  * @throws Error
  */
 private static function completeObjectValue(ExecutionContext $exeContext, ObjectType $returnType, $fieldNodes, ResolveInfo $info, $path, &$result)
 {
     // If there is an isTypeOf predicate function, call it with the
     // current result. If isTypeOf returns false, then raise an error rather
     // than continuing execution.
     if (false === $returnType->isTypeOf($result, $exeContext->contextValue, $info)) {
         throw new Error("Expected value of type {$returnType} but got: " . Utils::getVariableType($result), $fieldNodes);
     }
     // Collect sub-fields to execute to complete this value.
     $subFieldNodes = new \ArrayObject();
     $visitedFragmentNames = new \ArrayObject();
     foreach ($fieldNodes as $fieldNode) {
         if (isset($fieldNode->selectionSet)) {
             $subFieldNodes = self::collectFields($exeContext, $returnType, $fieldNode->selectionSet, $subFieldNodes, $visitedFragmentNames);
         }
     }
     return self::executeFields($exeContext, $returnType, $result, $path, $subFieldNodes);
 }