getPossibleTypes() public method

public getPossibleTypes ( GraphQL\Type\Definition\AbstractType $abstractType ) : ObjectType[]
$abstractType GraphQL\Type\Definition\AbstractType
return GraphQL\Type\Definition\ObjectType[]
 /**
  * Go through all of the implementations of type, and find other interaces
  * that they implement. If those interfaces include `field` as a valid field,
  * return them, sorted by how often the implementations include the other
  * interface.
  */
 static function getSiblingInterfacesIncludingField(Schema $schema, AbstractType $type, $fieldName)
 {
     $types = $schema->getPossibleTypes($type);
     $suggestedInterfaces = array_reduce($types, function ($acc, $t) use($fieldName) {
         foreach ($t->getInterfaces() as $i) {
             if (empty($i->getFields()[$fieldName])) {
                 continue;
             }
             if (!isset($acc[$i->name])) {
                 $acc[$i->name] = 0;
             }
             $acc[$i->name] += 1;
         }
         return $acc;
     }, []);
     $suggestedInterfaceNames = array_keys($suggestedInterfaces);
     usort($suggestedInterfaceNames, function ($a, $b) use($suggestedInterfaces) {
         return $suggestedInterfaces[$b] - $suggestedInterfaces[$a];
     });
     return $suggestedInterfaceNames;
 }
Beispiel #2
0
 /**
  * Provided two composite types, determine if they "overlap". Two composite
  * types overlap when the Sets of possible concrete types for each intersect.
  *
  * This is often used to determine if a fragment of a given type could possibly
  * be visited in a context of another type.
  *
  * This function is commutative.
  */
 static function doTypesOverlap(Schema $schema, CompositeType $typeA, CompositeType $typeB)
 {
     // Equivalent types overlap
     if ($typeA === $typeB) {
         return true;
     }
     if ($typeA instanceof AbstractType) {
         if ($typeB instanceof AbstractType) {
             // If both types are abstract, then determine if there is any intersection
             // between possible concrete types of each.
             foreach ($schema->getPossibleTypes($typeA) as $type) {
                 if ($schema->isPossibleType($typeB, $type)) {
                     return true;
                 }
             }
             return false;
         }
         /** @var $typeB ObjectType */
         // Determine if the latter type is a possible concrete type of the former.
         return $schema->isPossibleType($typeA, $typeB);
     }
     if ($typeB instanceof AbstractType) {
         /** @var $typeA ObjectType */
         // Determine if the former type is a possible concrete type of the latter.
         return $schema->isPossibleType($typeB, $typeA);
     }
     // Otherwise the types do not overlap.
     return false;
 }