/** * 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; }
/** * Given a function to map from an ID to an underlying object, and a function * to map from an underlying object to the concrete GraphQLObjectType it * corresponds to, constructs a `Node` interface that objects can implement, * and a field config for a `node` root field. * * If the typeResolver is omitted, object resolution on the interface will be * handled with the `isTypeOf` method on object types, as with any GraphQL * interface without a provided `resolveType` method. * * @param callable $idFetcher * @param callable $typeResolver * @return array */ public static function nodeDefinitions(callable $idFetcher, callable $typeResolver = null) { return Node::nodeDefinitions($idFetcher, $typeResolver); }