Example #1
0
 /**
  * Returns node definitions
  *
  * @return array
  */
 protected function getNodeDefinitions()
 {
     if (!self::$nodeDefinition) {
         self::$nodeDefinition = Node::nodeDefinitions(function ($id, $context, ResolveInfo $info) {
             $userData = $this->getUserData();
             if (array_key_exists($id, $userData)) {
                 return $userData[$id];
             } else {
                 $photoData = $this->getPhotoData();
                 if (array_key_exists($id, $photoData)) {
                     return $photoData[$id];
                 }
             }
         }, function ($obj) {
             if (array_key_exists($obj['id'], $this->getUserData())) {
                 return self::$userType;
             } else {
                 return self::$photoType;
             }
         });
         self::$userType = new ObjectType(['name' => 'User', 'fields' => ['id' => ['type' => Type::nonNull(Type::id())], 'name' => ['type' => Type::string()]], 'interfaces' => [self::$nodeDefinition['nodeInterface']]]);
         self::$photoType = new ObjectType(['name' => 'Photo', 'fields' => ['id' => ['type' => Type::nonNull(Type::id())], 'width' => ['type' => Type::int()]], 'interfaces' => [self::$nodeDefinition['nodeInterface']]]);
     }
     return self::$nodeDefinition;
 }
Example #2
0
 /**
  * Creates the configuration for an id field on a node, using `self::toGlobalId` to
  * construct the ID from the provided typename. The type-specific ID is fetched
  * by calling idFetcher on the object, or if not provided, by accessing the `id`
  * property on the object.
  *
  * @param string|null $typeName
  * @param callable|null $idFetcher
  * @return array
  */
 public static function globalIdField($typeName = null, callable $idFetcher = null)
 {
     return Node::globalIdField($typeName, $idFetcher);
 }