-
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
Changes from 1 commit
4ff0165
7059b38
07319ee
1faf2f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 commentThe 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 commentThe 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 |
||
if (existingTypenameValue) { | ||
warnings.push(`Encountered undefined payload value for __typename which will override __typename value on existing fragment.`); | ||
} | ||
} | ||
} | ||
|
||
let containerIdForField = containerId; | ||
|
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