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

Fix filling-in-missing-data.md example code #3550

Closed
wants to merge 1 commit into from
Closed

Conversation

ntf
Copy link
Contributor

@ntf ntf commented Jul 26, 2021

I come across this feature today when I was trying to fix a partial rendering behavior in my app.

I thought any query on node(id: ID) would re-use the cache on the store and perform partial rendering by default, but it seems that it is not the case.

For the code snippet below, it seems that the return value for "Not handled" should be undefined rather than null

const missingFieldHandlers = [
    {
        handle(field, record, argValues) {
            if (
                record != null &&
                record.__typename === ROOT_TYPE &&
                field.name === 'node' &&
                argValues.hasOwnProperty('id')
            ) {
                // If field is node(id: $id), look up the record by the value of $id
                return argValues.id;
            }

            // should return undefined instead of null if this handle function does not handle the given inputs.
            return undefined; 
        },
        kind: 'linked',
    }
];

According to this:

const newValue = handler.handle(
field,
record,
args,
this._recordSourceProxy,
);
if (
newValue !== undefined &&
(newValue === null || this._mutator.getStatus(newValue) === EXISTENT)
) {
return newValue;
}

If the return value is null, here

linkedID = this._handleMissingLinkField(field, dataID);
if (linkedID != null) {
this._mutator.setLinkedRecordID(dataID, storageKey, linkedID);
} else if (linkedID === null) {
this._mutator.setValue(dataID, storageKey, null);
}
sets the value to null and declares queryAvailability as available status instead of missing at the end.

@facebook-github-bot
Copy link
Contributor

Hi @ntf!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@facebook-github-bot
Copy link
Contributor

@kassens has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@kassens
Copy link
Member

kassens commented Aug 31, 2021

You are right, thanks for the fix!

@facebook-github-bot
Copy link
Contributor

@kassens has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@kassens merged this pull request in 01325ce.

@AndrewIngram
Copy link

I just lost several hours to this, is there any way to get doc fixes published?

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.

4 participants