-
Notifications
You must be signed in to change notification settings - Fork 11.6k
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
Allow to pass a blob to core fetch function #71929
Conversation
public/app/core/utils/fetch.ts
Outdated
@@ -89,6 +90,9 @@ export const parseBody = (options: BackendSrvRequest, isAppJson: boolean) => { | |||
if (!options.data || typeof options.data === 'string') { | |||
return options.data; | |||
} | |||
if (options.data.constructor.name === 'Blob') { |
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.
does options.data instanceof Blob
work here?
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.
No apparently jest need a polyfill but I'm not sure how to do it.
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.
@joshhunt should we add a polyfill for this? see jsdom/jsdom#2555 and elastic/kibana#162197
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.
Ok seems like there actually is a Blob polyfill
grafana/public/test/jest-setup.ts
Line 9 in e7797ac
import 'blob-polyfill'; |
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.
I wasn't sure how to use it properly.
public/app/core/utils/fetch.ts
Outdated
@@ -1,3 +1,4 @@ | |||
import { Blob } from 'buffer'; |
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.
Ah ok this seems to be the problem. This is buffer from the node API which we (probably) don't want to use. We want to use the browser Blob (which is available globally) or use the polyfill in Jest. With this import you created a "native" Blob in the test but then were comparing it with the node Blob imported here (as that shadowed the global one).
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.
honestly I wasn't able to make it work
What is this feature?
This allows to pass a Blob and not try to parse it when using the core fetch function which is used by plugins when communicating with backend service.
Why do we need this feature?
I have feature that needs to send protobuf encoded data and this is blocking.
Who is this feature for?
Mostly for developer using fetch.
Which issue(s) does this PR fix?:
Fixes #
Special notes for your reviewer:
Please check that: