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
 /**
  * @param string $name
  * @param array  $mapping
  * @return Type
  */
 private function createType($name, array $mapping)
 {
     $type = new Type();
     $type->setName($name)->setExtends(isset($mapping['extends']) ? $mapping['extends'] : null)->setResolveConfig(isset($mapping['resolve']) ? $mapping['resolve'] : []);
     $this->populateFieldContainer($type, $mapping);
     return $type;
 }
Пример #3
0
 /**
  * @return SchemaContainer
  */
 private function getExceptedSchemaContainer()
 {
     if (self::$expectedSchema !== null) {
         return self::$expectedSchema;
     }
     $episodeType = new Type();
     $episodeType->setName('Episode')->setDescription('One of the films in the Star Wars Trilogy')->setValues(['NEWHOPE' => ['value' => 4, 'description' => 'Released in 1977.'], 'EMPIRE' => ['value' => 5, 'description' => 'Released in 1980.'], 'JEDI' => ['value' => 6, 'description' => 'Released in 1983.']]);
     $characterInterface = new InterfaceType();
     $characterInterface->setName('Character')->setDescription('A character in the Star Wars Trilogy')->setFields([$this->createIdField('The id of the character.'), $this->createNameField('The name of the character.'), $this->createFriendsField('The friends of the character, or an empty list if they have none.'), $this->createAppearsInField()]);
     $homePlanet = new Field();
     $homePlanet->setName('homePlanet')->setType('String')->setDescription('The home planet of the human, or null if unknown.');
     $humanType = new Type();
     $humanType->setName('Human')->setDescription('A humanoid creature in the Star Wars universe.')->setInterfaces(['Character'])->setFields([$this->createIdField('The id of the human.'), $this->createNameField('The name of the human.'), $this->createFriendsField('The friends of the human, or an empty list if they have none.'), $this->createAppearsInField(), $homePlanet]);
     $primaryFunction = new Field();
     $primaryFunction->setName('primaryFunction')->setType('String')->setDescription('The primary function of the droid.');
     $droidType = new Type();
     $droidType->setName('Droid')->setDescription('A mechanical creature in the Star Wars universe.')->setInterfaces(['Character'])->setFields([$this->createIdField('The id of the droid.'), $this->createNameField('The name of the droid.'), $this->createFriendsField('The friends of the droid, or an empty list if they have none.'), $this->createAppearsInField(), $primaryFunction]);
     $episodeField = new Field();
     $episodeField->setName('episode')->setType('Episode')->setDescription('If omitted, returns the hero of the whole saga. If provided, returns the hero of that particular episode.');
     $heroField = new Field();
     $heroField->setName('hero')->setType('Character')->setArguments([$episodeField]);
     $humanField = new Field();
     $humanField->setName('human')->setType('Human')->setArguments([$this->createIdField('id of the human')]);
     $droidField = new Field();
     $droidField->setName('droid')->setType('Droid')->setArguments([$this->createIdField('id of the droid')]);
     $query = new Query();
     $query->setFields([$heroField, $humanField, $droidField]);
     $schema = new SchemaContainer();
     $schema->addType($episodeType)->addType($humanType)->addType($droidType)->addInterface($characterInterface)->setQuerySchema($query);
     return self::$expectedSchema = $schema;
 }
Пример #4
0
 private function guessProperty(Field $field, Type $parentType = null)
 {
     if (null === $parentType) {
         return;
     }
     $parentTypeConfig = $parentType->getResolveConfig();
     if (isset($parentTypeConfig['model'])) {
         $className = $parentTypeConfig['model'];
         if (null !== ($accessor = $this->getAccessor($className, $field))) {
             $field->mergeRevolveConfig(['method' => $accessor, 'handler' => 'property']);
             return true;
         }
     }
 }
Пример #5
0
 /**
  * @param string $name
  * @param array  $mapping
  * @return Type
  */
 private function createType($name, array $mapping)
 {
     $type = new Type();
     $type->setName($name)->setResolveConfig(isset($mapping['resolve']) ? $mapping['resolve'] : []);
     if (!empty($mapping['interfaces'])) {
         $type->setInterfaces((array) $mapping['interfaces']);
     }
     if (isset($mapping['values'])) {
         $type->setValues($mapping['values']);
     }
     if (isset($mapping['model'])) {
         $type->setModel($mapping['model']);
     }
     $this->populateFieldContainer($type, $mapping);
     return $type;
 }
Пример #6
0
 /**
  * @param Type $type
  */
 private function resolveInterfaces(Type $type)
 {
     foreach ($type->getInterfaces() as &$interface) {
         $interface = $this->typeResolver->getType($interface);
     }
 }