Open isBatak opened 5 years ago
@swissspidy I'm planning to make a PR for this feature, this is the idea https://github.com/isBatak/gutenberg/commit/72e35056c2dda55d46092380f16b349892dfa3b2 for the API. But, now tests are failing and I have no idea how to fix them. Do you have any suggestion?
Well which tests are failing...? If you'd create the PR already then you could point to the failing tests on Travis CI and more easily get technical feedback from maintainers.
I'll make a PR now, and see what will happen :D
The PR #17574 seems to have plenty of technical feedback, so I'm removing that label.
Also removing In Progress, since the PR hasn't had recent updates.
FYI, added this to the "Mobile Apps" project board to cover the apps side of the issue.
Besides this solutions
apiFetch.setFetchReference( fetch );
globalThis.fetch
another solution would be to export a factory function
import { createApiFetch } from '@wordpress/api-fetch'
// Browser
const apiFetch = createApiFetch({ fetch: window.fetch })
// Node
const apiFetch = createApiFetch({ fetch: require('node-fetch') })
My workaround
import fetch from 'node-fetch'
global.window = { fetch }
import apiFetch from '@wordpress/api-fetch'
apiFetch({ path: '/wp-json/wp/v2/users' }).then(console.log)
I'm trying to use
@wordpress/api-fetch
on node (decoupled WordPress and SSR), but it is not easy to polyfill fetch because ofwindow.fetch
usage https://github.com/WordPress/gutenberg/blob/master/packages/api-fetch/src/index.js#L161 and I don't want to reimplement wholedefaultFetchHandler
logic withsetFetchHandler
solution. I just want to replacefetch
with something else likeisomorphic-fetch
.Solution:
fetch