-
Notifications
You must be signed in to change notification settings - Fork 2k
[6.0][Proposal] Refactor Graph nodes #437
Comments
mmmm, this means that you need also to remove the Array Access, because It is clean, straightforward, and make support for additional casting like edge, non root nodes, and open graph nodes very easy, but I feel that we will loose some flexibility. I'm really confused about that |
I certainly think that would make the Graph node casting much clearer & the complexity would be reduced. I have a few questions.
What would the raw return value of a Graph node be? Would it just return an array?
I'm not sure why we'd need to remove array access since: @yguedidi How would recursion of embedded nodes work? For example the Graph user node will return a |
@SammyK Yes, as currently response JSON objects are decoded as arrays (This is also an issue in my list haha)
@devmsh Yes, as you know, I'm not a fan of array access in that case. But if some users really (really) want array access, I would need some args to understand, and please think about that: Accessing a key is in fact a call to |
If we need kill all the magic, and make For example: /* direct edge */
$response = $fb->get('me/events');
$events = $response->getGraphEvent();
/* nested edge */
$response = $fb->get('me?fields=events');
$user = $response->getGraphUser();
$events = $user->getEvents();
/* node */
$response = $fb->get('{eventID}');
$event = $response->getGraphEvent(); Currently $response = $fb->get('me/events');
$events = $response->getGraphEvents();
$response = $fb->get('{eventID}');
$event = $response->getGraphEvent(); and class GraphUser ...{
function getEvents(){
// whoever it come :D
}
} |
I totaly agree, that's why I also have in mind to remove the factories. There are useless now.
Some code: // in GraphNode or GraphEdge
public function __construct($rawData)
{
// here check the format (like in the current GraphNodeFactory)
}
// in FacebookResponse (I prefer casters to be named with "as")
public function getAsUser()
{
return new GraphUser($this->decodedBody);
}
public function getAsPhotos()
{
return new GraphPhotos($this->decodedBody);
}
// in GraphUser
public function getPhotos()
{
return new GraphPhotos($this->getField('photos'));
} Simple. Clear. Explicit. (Magicless.) |
Sorry, I update the comment to add the nested edge scenario before I see your comment I think that functions like |
|
Mmmm, so you will have GraphEvents and GraphEvent, GraphPhotos and GraphPhoto ... etc? What is the benifit of that? |
What is the benefit of all node classes? :) |
Here it's the same, but for edges |
Mmmmm Nodes have different fields so different getters included in each node class But as I think there is no differrances between edges? The all have common functionallity expect that the special picture edge? |
Some edges have fields, and the returned type when you loop over it is not the same. |
Can you please provide any referance or examples? |
I will review it and other edges then I will return back |
No problem |
Based on my quick review, there is three type of fields
While we will have many empty |
I'm with you guys on the shady things going on in the
I'm curious how complicated we wanted to make the response parsing. Part of me likes the whole recursive auto-casting of Graph node subtypes, but I can see the value of explicit casting as @yguedidi has pointed out. One of the tough parts about this refactor would be keeping support for deeply nested pagination with lines like this one in the |
I stop my contribution for a while and wait some issues to be completed, here is the list of pending issues, new features, and enhancements that paused until we close this issue and refactor the graph node.
Other pending suggestion: enable the wiki and create a road map page or use the milestone feature to organize the issues related to each milestone. hope that we can finish from that asap :) |
Any updates! |
I don't really have the time to work on this... I'm busy for the 2 next weeks and on holidays without internet connexion for the 3 next weeks... I'll back on half august. Some steps I can think of now:
|
Thank you for reporting this issue and appreciate your patience. We've notified the core team for an update on this issue. We're looking for a response within the next 30 days or the issue may be closed. |
Oh @facebook-github-bot-0. You make me lulz. |
:D |
I was notified, am I a core team member? lol |
@yguedidi You're a hardcore team member in my book. :) |
Hahaha you too! ;) |
You guys are great, definitely core team members in my book!! |
@devmsh Sorry, I just now saw this! I think you can keep adding to the |
I basicly want to simplify node casting.
The idea comes from all discussions about magic. I saw while ago that all node methods are a simple call to
getFiled()
, but how this work?Thanks to the father class
GraphNode
of course! Using a protected static casting map, the casting of child field is "delayed" to the parent class, which is then responsible of all the casting.A bit "magic" right?
I suggest to simplify
GraphNode
and remove all the autocasting feature, and add "caster" methods like->getFieldAsNode()
,->getFieldAsDate()
, and->getField()
will return the raw value.Then, all specialized node will be responsible about cast its field, exemple with
GraphAchievement
:I don't handle the case of null because I have a thought about that, who wants me open a issue? :)
We also can imagine something like
->getFromAsUser()
,->getFromAsPage
, etc.. Don't forget that with the SDK, we are in a YKWYRYKWYG (You Know What You Rrequest, You Know What You Get) basis, so it's the responsability of the developer to call the right method to get the right type.Thoughts?
The text was updated successfully, but these errors were encountered: