getFields() public method

public getFields ( ) : FieldDefinition[]
return FieldDefinition[]
示例#1
0
 /**
  * @param ObjectType $object
  * @param InterfaceType $iface
  * @throws \Exception
  */
 private function assertObjectImplementsInterface(ObjectType $object, InterfaceType $iface)
 {
     $objectFieldMap = $object->getFields();
     $ifaceFieldMap = $iface->getFields();
     foreach ($ifaceFieldMap as $fieldName => $ifaceField) {
         Utils::invariant(isset($objectFieldMap[$fieldName]), "\"{$iface}\" expects field \"{$fieldName}\" but \"{$object}\" does not provide it");
         /** @var $ifaceField FieldDefinition */
         /** @var $objectField FieldDefinition */
         $objectField = $objectFieldMap[$fieldName];
         Utils::invariant($this->isEqualType($ifaceField->getType(), $objectField->getType()), "{$iface}.{$fieldName} expects type \"{$ifaceField->getType()}\" but " . "{$object}.{$fieldName} provides type \"{$objectField->getType()}");
         foreach ($ifaceField->args as $ifaceArg) {
             /** @var $ifaceArg FieldArgument */
             /** @var $objectArg FieldArgument */
             $argName = $ifaceArg->name;
             $objectArg = $objectField->getArg($argName);
             // Assert interface field arg exists on object field.
             Utils::invariant($objectArg, "{$iface}.{$fieldName} expects argument \"{$argName}\" but {$object}.{$fieldName} does not provide it.");
             // Assert interface field arg type matches object field arg type.
             // (invariant)
             Utils::invariant($this->isEqualType($ifaceArg->getType(), $objectArg->getType()), "{$iface}.{$fieldName}({$argName}:) expects type \"{$ifaceArg->getType()}\" " . "but {$object}.{$fieldName}({$argName}:) provides " . "type \"{$objectArg->getType()}\"");
             // Assert argument set invariance.
             foreach ($objectField->args as $objectArg) {
                 $argName = $objectArg->name;
                 $ifaceArg = $ifaceField->getArg($argName);
                 Utils::invariant($ifaceArg, "{$iface}.{$fieldName} does not define argument \"{$argName}\" but " . "{$object}.{$fieldName} provides it.");
             }
         }
     }
 }
 /**
  * Determine if output fields should be included.
  *
  * @param  mixed $objectType
  * @return boolean
  */
 protected function includeOutputFields(ObjectType $objectType)
 {
     $fields = [];
     foreach ($objectType->getFields() as $name => $field) {
         $type = $field->getType();
         if ($type instanceof ObjectType) {
             $config = $type->config;
             if (isset($config['name']) && preg_match('/Connection$/', $config['name'])) {
                 continue;
             }
         }
         $fields[] = $name;
     }
     return $fields;
 }
示例#3
0
 /**
  * This method looks up the field on the given type defintion.
  * It has special casing for the two introspection fields, __schema
  * and __typename. __typename is special because it can always be
  * queried as a field, even in situations where no other fields
  * are allowed, like on a Union. __schema could get automatically
  * added to the query type, but that would require mutating type
  * definitions, which would cause issues.
  *
  * @param Schema $schema
  * @param ObjectType $parentType
  * @param $fieldName
  *
  * @return FieldDefinition
  */
 private static function getFieldDef(Schema $schema, ObjectType $parentType, $fieldName)
 {
     static $schemaMetaFieldDef, $typeMetaFieldDef, $typeNameMetaFieldDef;
     $schemaMetaFieldDef = $schemaMetaFieldDef ?: Introspection::schemaMetaFieldDef();
     $typeMetaFieldDef = $typeMetaFieldDef ?: Introspection::typeMetaFieldDef();
     $typeNameMetaFieldDef = $typeNameMetaFieldDef ?: Introspection::typeNameMetaFieldDef();
     if ($fieldName === $schemaMetaFieldDef->name && $schema->getQueryType() === $parentType) {
         return $schemaMetaFieldDef;
     } else {
         if ($fieldName === $typeMetaFieldDef->name && $schema->getQueryType() === $parentType) {
             return $typeMetaFieldDef;
         } else {
             if ($fieldName === $typeNameMetaFieldDef->name) {
                 return $typeNameMetaFieldDef;
             }
         }
     }
     $tmp = $parentType->getFields();
     return isset($tmp[$fieldName]) ? $tmp[$fieldName] : null;
 }