Esempio n. 1
0
 public function build($config)
 {
     parent::build($config);
     $config->getField('friends')->getConfig()->set('resolve', function ($droid) {
         return StarWarsData::getFriends($droid);
     });
     $config->addField('primaryFunction', TypeMap::TYPE_STRING);
 }
Esempio n. 2
0
 public function build($config)
 {
     $config->addField('hero', ['type' => new CharacterInterface(), 'args' => ['episode' => ['type' => new EpisodeEnum()]], 'resolve' => function ($root, $args) {
         return StarWarsData::getHero(isset($args['episode']) ? $args['episode'] : null);
     }])->addField(new Field(['name' => 'human', 'type' => new HumanType(), 'args' => ['id' => new IdType()], 'resolve' => function ($value = null, $args = []) {
         $humans = StarWarsData::humans();
         return isset($humans[$args['id']]) ? $humans[$args['id']] : null;
     }]))->addField(new Field(['name' => 'droid', 'type' => new DroidType(), 'args' => ['id' => new IdType()], 'resolve' => function ($value = null, $args = []) {
         $droids = StarWarsData::droids();
         return isset($droids[$args['id']]) ? $droids[$args['id']] : null;
     }]));
 }
Esempio n. 3
0
 public function resolveType($object)
 {
     $humans = StarWarsData::humans();
     $droids = StarWarsData::droids();
     $id = isset($object['id']) ? $object['id'] : $object;
     if (isset($humans[$id])) {
         return new HumanType();
     }
     if (isset($droids[$id])) {
         return new DroidType();
     }
     return null;
 }
Esempio n. 4
0
 public function build($config)
 {
     $config->addField('id', new NonNullType(new IdType()))->addField('name', new NonNullType(new StringType()))->addField('friends', ['type' => new ListType(new CharacterInterface()), 'resolve' => function ($droid) {
         return StarWarsData::getFriends($droid);
     }])->addField('appearsIn', new ListType(new EpisodeEnum()))->addField('homePlanet', TypeMap::TYPE_STRING);
 }