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

add warning around missing __typename in fragment payload #413

Merged
merged 4 commits into from
Apr 22, 2019

Conversation

finnigantime
Copy link
Contributor

✔ Write a summary

Add warning around missing __typename in fragment payload. See #412. This is my attempt to add a warning around this condition. Note that the warning is only emitted if verbose logging is enabled so I'm not sure how helpful it'll be.

✔ Tests!

N/A

✔ Bump the version if needed

N/A

@finnigantime finnigantime requested a review from nevir April 5, 2019 20:16
Copy link
Contributor

@nevir nevir left a comment

Choose a reason for hiding this comment

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

Thanks for taking this on!

I've got some tweaks to it, though - let's also add a unit test or two, please

*/
getAddTypename() {
return this._addTypename;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than converting this into a getter, let's make the property public

@@ -223,6 +223,13 @@ export class SnapshotEditor {
if (payload && payloadName in payload) {
warnings.push(`Encountered undefined at ${[...prefixPath, ...path].join('.')}. Treating as null`);
}

if (this._context.getAddTypename() && payloadName === '__typename') {
const existingTypenameValue = deepGet(this._getNodeData(containerId), path);
Copy link
Contributor

Choose a reason for hiding this comment

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

You can skip this check - it's even more of a problem for cases where typename is missing (for some consumers of hermes, __typename is part of object identity)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done. For unit testing, how to test? I didn't see an existing example checking tracer warnings. I see tests for catching InvalidPayloadError. By the way, should this be an InvalidPayloadError instead of a warning? That would be more visible to consumers.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, failing hard here would be 👍


re: unit testing the tracer, we typically fall back to testing the console output, rather than the tracer itself (since that's more stable, and these messages are likely to change). But it's also not a very proven pattern; injecting the tracer might be better.

Example test: https://github.com/convoyinc/apollo-cache-hermes/blob/master/test/unit/Cache/transactions.ts#L53-L62

@finnigantime finnigantime merged commit 7e2ba10 into master Apr 22, 2019
@finnigantime finnigantime deleted the finnigan/412-emit-warning branch April 22, 2019 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants