Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why there's no "NODE_ADD" type? #87

Closed
coodoo opened this issue Aug 17, 2015 · 4 comments
Closed

Why there's no "NODE_ADD" type? #87

coodoo opened this issue Aug 17, 2015 · 4 comments
Labels

Comments

@coodoo
Copy link

coodoo commented Aug 17, 2015

Since there are NODE_DELETE and RANGE_DELETE types, I'm wondering why NODE_ADD is not needed?

Personally I'm guessing that's because when you create a new object, it should always belong to one of the edges, hence RANGE_ADD is good enough, is that correct?

@yuzhi
Copy link
Contributor

yuzhi commented Aug 17, 2015

Great Question! I think you got the gist of the idea.
The mutation configs we have right now serves two main purposes:

  1. Tells us how to handle the different mutation fields
  2. Helps us figure out what fields need to be refetched with the mutation based on what we have stored for a particular node so far.
    Reason number 2 is the one I want to focus more on. When a completely new node is added, there is no way for Relay have stored any fields for that new node so far.
    If the new node is going to be a field referenced another node (ex. updating a User’s current_status), we can use that node (the User node in this case) to figure out what fields we’ll need to fetch with the mutation as part of a FIELD_CHANGE mutation config.
    If a new node is going to be referenced from a connection (ex. adding a comment in a connection of comments), we can look at the fields under edges that has been fetched for that connection (comments connection) to figure out the fields we would need for this new node as part of a RANGE_ADD mutation config.
    If the new node is not referenced by another node, it is unlikely for the current view to need any data on the new node. However, we have seen people do a route transition after a new node is created. Even though no fields are needed to update the current view, it’s possible to use REQUIRED_CHILDREN to always fetch any additional fields (like the new node's id) so that it could be used during an onSuccess mutation callback.

@yuzhi yuzhi added the question label Aug 17, 2015
@coodoo
Copy link
Author

coodoo commented Aug 19, 2015

Thanks for the great details!

@coodoo coodoo closed this as completed Aug 19, 2015
@thenikso
Copy link

I dig this. however I'm wondering how would one go to handle something like a "signup" flow; where the viewer (ie: a query root type) will go from, let's say, an empty object to an actual user.

At this point I'm thinking that a route change or reload would make sense but is there another way? I guess one would want to have something like #233 in the future?

@kassens
Copy link
Member

kassens commented Sep 30, 2015

@thenikso Since so many things might change when you log in, we currently recommend just doing a classical page refresh to clear all data. In the future a something like #233 might be useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants