コード例 #1
0
 private function getExceptedSchemaContainer()
 {
     if (self::$expectedSchema !== null) {
         return self::$expectedSchema;
     }
     $idField = new Field();
     $idField->setName('id')->setDescription('The user primary key')->setType('Int');
     $nameField = new Field();
     $nameField->setName('name')->setDescription('The user name')->setType('String');
     $emailField = new Field();
     $emailField->setName('email')->setDescription('The user email')->setType('String');
     $friendsField = new Field();
     $friendsField->setName('friends')->setDescription('The user friends')->setType('[User]')->setResolveConfig('AppBundle\\Entity\\Friend');
     $userType = new Type();
     $userType->setName('User')->setDescription('User type description')->setExtends('Item')->setFields([$idField, $nameField, $emailField, $friendsField]);
     $idField = new Field();
     $idField->setName('id')->setDescription('The item primary key')->setType('Int');
     $nameField = new Field();
     $nameField->setName('name')->setDescription('The item name')->setType('String');
     $interface = new InterfaceType();
     $interface->setName('Item')->setDescription('Item interface description')->setFields([$idField, $nameField]);
     $idArg = new Field();
     $idArg->setName('id')->setDescription('The ID')->setType('Int');
     $adminField = new Field();
     $adminField->setName('admin')->setDescription('Admin description')->setType('[User]')->setResolveConfig('AppBundle\\Entity\\User')->setArguments([$idArg]);
     $idArg = clone $idArg;
     $userField = new Field();
     $userField->setName('user')->setDescription('User description')->setType('User')->setResolveConfig('AppBundle\\Entity\\User')->setArguments([$idArg]);
     $query = new Query();
     $query->setDescription('The root query description')->setFields([$adminField, $userField]);
     $schema = new SchemaContainer();
     $schema->addType($userType)->addInterface($interface)->setQuerySchema($query);
     return self::$expectedSchema = $schema;
 }
コード例 #2
0
 /**
  * Apply the resolve config of types that are used by query fields
  *
  * @param SchemaContainer $schemaContainer
  * @param Field           $field
  */
 private function mergeResolveConfig(SchemaContainer $schemaContainer, Field $field)
 {
     $typeName = TypeParser::getFinalType($field->getType());
     if ($schemaContainer->hasType($typeName)) {
         $typeConfig = $schemaContainer->getType($typeName)->getResolveConfig();
     } elseif ($schemaContainer->hasInterface($typeName)) {
         $typeConfig = $schemaContainer->getInterface($typeName)->getResolveConfig();
     } else {
         return;
     }
     $field->mergeResolveConfig($typeConfig);
 }
コード例 #3
0
ファイル: YamlDriver.php プロジェクト: 4rthem/graphql-mapper
 /**
  * @param string $name
  * @param array  $mapping
  * @return Field
  */
 private function createField($name, array $mapping)
 {
     $field = new Field();
     $field->setName($name)->setType(isset($mapping['type']) ? $mapping['type'] : null)->setProperty(isset($mapping['property']) ? $mapping['property'] : null)->setResolveConfig(isset($mapping['resolve']) ? $mapping['resolve'] : []);
     $this->populateType($field, $mapping);
     if (isset($mapping['args'])) {
         $args = [];
         foreach ($mapping['args'] as $argName => $argMapping) {
             $args[] = $this->createField($argName, $argMapping);
         }
         $field->setArguments($args);
     }
     return $field;
 }
コード例 #4
0
 /**
  * @return Field
  */
 private function createAppearsInField()
 {
     $field = new Field();
     $field->setName('appearsIn')->setDescription('Which movies they appear in.')->setType('[Episode]');
     return $field;
 }
コード例 #5
0
 /**
  * @param Field $field
  */
 private function prepareResolver(Field $field)
 {
     $resolveConfig = $field->getResolveConfig();
     if (isset($resolveConfig['handler'])) {
         $handler = $resolveConfig['handler'];
         if (!isset($this->resolveFactories[$handler])) {
             throw new \Exception(sprintf('Handle named "%s" does not exist', $resolveConfig['handler']));
         }
         $resolver = $this->resolveFactories[$handler]->getFunction($resolveConfig, $field);
         $field->setResolve($resolver);
     }
 }
コード例 #6
0
 /**
  * @param string $className
  * @param Field  $field
  * @return string|null
  */
 private function getAccessor($className, Field $field)
 {
     $class = new \ReflectionClass($className);
     $property = $field->getField() ?: $field->getName();
     $camelName = String::camelize($property);
     $getter = 'get' . $camelName;
     $getsetter = lcfirst($camelName);
     $isser = 'is' . $camelName;
     $hasser = 'has' . $camelName;
     $test = [$getter, $getsetter, $isser, $hasser];
     $reflMethods = $class->getMethods(\ReflectionMethod::IS_PUBLIC);
     $methods = [];
     foreach ($reflMethods as $reflMethod) {
         $methods[$reflMethod->getName()] = true;
     }
     foreach ($test as $method) {
         if (isset($methods[$method])) {
             return $method;
         }
     }
 }
コード例 #7
0
 /**
  * @param ClassMetadataInfo $metadata
  * @param Field             $field
  * @param SchemaContainer   $schemaContainer
  * @return TypeGuess
  * @throws MappingException
  */
 private function guessAssociation(ClassMetadataInfo $metadata, Field $field, SchemaContainer $schemaContainer)
 {
     $property = $field->getProperty() ?: $field->getName();
     $multiple = $metadata->isCollectionValuedAssociation($property);
     $mapping = $metadata->getAssociationMapping($property);
     foreach ($schemaContainer->getTypes() as $type) {
         $containerContext = new ContainerContext($type, $schemaContainer);
         if (!$this->isFieldContainerSupported($containerContext)) {
             continue;
         }
         if ($type->getModel() === $mapping['targetEntity']) {
             $typeName = $type->getName();
             if ($multiple) {
                 $typeName = sprintf('[%s]', $typeName);
             }
             return new TypeGuess($typeName, Guess::HIGH_CONFIDENCE);
         }
     }
 }