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

RANGE_ADD - Better warning messages when new edge is missing #574

Closed
wants to merge 1 commit into from

Conversation

xuorig
Copy link
Contributor

@xuorig xuorig commented Nov 10, 2015

Possible improvement for #542

Lot's of issues and misunderstanding with that one, range add mutations can be confusing with the current warning messages.

Better solution as @steveluscher said:

  • When relay does not query the new edge because it was not included in the intersection of tracked and fat queries, show a different warning saying it's a client-side problem ( Connection was never used in the app )
  • If the edge was queried but is not in the payload, explain it's a server side problem.

In handleRangeAdd, if the edge is missing from the payload, check if the operation RelayQueryMutation contained the newEdge field. If it didn't, it means the new edge was not included because it wasn't in the intersection of the tracked/fat query. If it did, it means the server should've returned that field and didn't.

I've added a function getNodeByFieldName to check if the operation contained the field to get the new edge. Not sure if it is the best way to check that, let me know.

The actual warning messages probably need some work, let me know what you think would be the best messages for these cases.

'update the `RANGE_ADD` mutation config?',
config.edgeName
);
if (operation.getNodeByFieldName(config.edgeName)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use operation.getFieldByStorageKey(config.edgeName)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah of course. Updated the PR!

@josephsavona
Copy link
Contributor

cc @steveluscher @kassens

@devknoll
Copy link
Contributor

Thank you!!! ❤️

@xuorig
Copy link
Contributor Author

xuorig commented Nov 18, 2015

@josephsavona @kassens any comments on this ? Would be helpful to add that in 👯

@steveluscher
Copy link
Contributor

Thanks for your patience on this. It's taken us a long time to get to it, I know. Here's what we're thinking.

To recap, these are two distinct cases.

  1. If the query includes the field but the response payload doesn't, it indicates a server error (the server should have returned null if it can't fetch a field).
  2. If the query doesn't include the field, it indicates that the range configs do not account for the tracked fields. Since this is a problem with the query rather than the response payload, what do you think about moving this warning out of the writer and into RelayMutationQuery, making it clear that the problem is range behaviors in RANGE_ADD not matching up with what the application is actually querying for by way of a helpful and well-written error message?

@xuorig
Copy link
Contributor Author

xuorig commented Dec 17, 2015

@steveluscher sorry for the wait, (finals week 😪) I have updated the PR with what you have recommended. I make the check in buildFragmentForEdgeInsertion. If the newEdge is not present in mutatedFields after it's been populated, we can assume rangeBehaviors was not matching the trackedConnection and we can warn.

Should this be an invariant or keep it as a warn ? Let me know if this is what you had in mind!

@@ -242,6 +243,21 @@ var RelayMutationQuery = {
}
}
}

// Warn if the newly created edge was not included in mutatedFields
const edgeField = mutatedFields.find(field => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead, how about moving this to an else clause at line 225? Note that mutatedEdgeFields is only empty if no range behaviors matched and the new edge field would be missing.

@josephsavona
Copy link
Contributor

Thanks for updating this! We should also remove the warning in writeRelayUpdatePayload (and just return if appropriate).

@xuorig
Copy link
Contributor Author

xuorig commented Dec 17, 2015

Shouldn't we keep the current warning in the case where the server is not returning the newEdge ?

@josephsavona
Copy link
Contributor

We should keep warning if the server doesn't return the edge, but only if we asked for the edge and didn't get it. The warning currently still occurs even if no range behaviors matched.

@xuorig
Copy link
Contributor Author

xuorig commented Dec 17, 2015

Ah you're right! Updated the PR to address your comments.

parentID: '123',
edgeName: 'feedbackCommentEdge',
parentName: 'feedback',
rangeBehaviors,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: i suspect you borrowed this from other test cases in this file, but it would make the test more self-contained and readable if we were explicit about the range behaviors, e.g rangeBehaviors: {}.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much clearer that way!

@josephsavona
Copy link
Contributor

A few more nits, but otherwise this looks great :-)

@steveluscher
Copy link
Contributor

Thanks for your patience, @xuorig. We just went over this internally, and I'd like to share a summary of our discussion. I wrote:

Let me try to work through this to make sure I understand it.

Client devs have the option of configuring a RANGE_ADD config or not. If they do configure one, it's likely because they expect it to be of use.

Now, if you've specified a RANGE_ADD config, there are tracked connections that match, but none of them match your rangeBehaviors, it's because you have a connection in your app with arguments that you haven't accounted for in your RANGE_ADD config. This is the aim of the warning, to say “hey… we found at least one tracked connection for that parentID/connectionName combination, but we couldn't find an associated rangeBehavior – did you forget to configure one?”

@yungsters: …this warning … can be triggered [if] the key does not have a range behavior defined.

Interesting. To fallback by refetching the whole connection is good (and what the code does now if you don't have a matching range behavior) but one of the nice things about RANGE_ADD configs is to prevent refetching and to enable optimistic mutations. When you miss a rangeBehavior, you lose all of that without warning.

What if we changed the warning to indicate that the entire connection has been refetched and that the developer can't expect optimistic mutations to work, with a little bit about how to write a more efficient and optimism-compatible mutation. Something like:

“Relay.Mutation: Since the connection ships(orderby:"latest") of the field faction with id 123 matched none of the rangeBehaviors specified in your RANGE_ADD config, the entire connection has been refetched. Configure a range behavior for this connection to fetch only the new edge and to enable optimistic mutations. See http://… for more information.”

The only problem here is that there's no way for the developer to squelch this warning if their desired behavior was to refetch the connection. Thoughts, @yuzhi @xuorig @yungsters?

@yungsters
Copy link
Contributor

I discussed with @yuzhi a bit. Currently, setting a range behavior configuration to null means the range should not be refetched at all. I think we should change this to IGNORE instead of null.

We can add a REFETCH or ALL constant to squelch the warning.

@xuorig
Copy link
Contributor Author

xuorig commented Jan 6, 2016

Correct me if I'm wrong but If the desired behavior was to refetch the connection, why would there be a RANGE_ADD then ? wouldn't you use something like REQUIRED_CHILDREN instead ?

We can add a REFETCH or ALL constant to squelch the warning.

That would definitly help remove any ambiguity about the behavior.

@yungsters
Copy link
Contributor

A RANGE_ADD may be an APPEND for some but REFETCH for others (e.g. if a particular argument causes sorting that can only be determined by the server).

@xuorig
Copy link
Contributor Author

xuorig commented Jan 10, 2016

@steveluscher @yungsters I propose that we change the warning message to something like @steveluscher proposed, where we clearly state which connection wasn't found in the rangeBehaviors.

In another PR we can address the REFETCH / ALL and IGNORE behaviors ? I would gladly work on a solution for this too.

@xuorig
Copy link
Contributor Author

xuorig commented Jan 11, 2016

I have modified the PR with the message @steveluscher proposed. I think this might be a good first step to clear up the small confusion people have with RANGE_ADD mutations.

@yungsters yungsters assigned wincent and yungsters and unassigned wincent Mar 1, 2016
@yungsters
Copy link
Contributor

@facebook-github-bot import

@facebook-github-bot
Copy link
Contributor

Thanks for importing. If you are an FB employee go to Phabricator to review.

@ghost ghost closed this in cde735b Mar 9, 2016
@xuorig xuorig deleted the better-range-add-warnings branch March 9, 2016 03:11
ghost pushed a commit that referenced this pull request Apr 1, 2016
Summary:As discussed in #574, #542

Introduce 2 new range behaviors:
  - `REFETCH`: Will refetch the entire connection (to squelch the warning when no `rangeBehavior` matches the tracked connection)
  - `IGNORE`: Replaces using null, means the range should not be refetched at all.

I've deprecated `null`, maybe we don't need to, what do you think ?

yungsters steveluscher

let me what you think! ?
Closes #945

Reviewed By: josephsavona

Differential Revision: D3117256

Pulled By: wincent

fb-gh-sync-id: e7b5ab2fe6beebcd53f400a62634a7cd5aae383b
fbshipit-source-id: e7b5ab2fe6beebcd53f400a62634a7cd5aae383b
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants