-
Notifications
You must be signed in to change notification settings - Fork 30
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
Conversation
There was a problem hiding this 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; | ||
} |
There was a problem hiding this comment.
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
src/operations/SnapshotEditor.ts
Outdated
@@ -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); |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
2af6b81
to
7059b38
Compare
5b7e59d
to
1faf2f8
Compare
✔ 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