youknowriad / blockbook

Build and Share WordPress Blocks in Isolation.
http://youknowriad.github.io/blockbook/
GNU General Public License v3.0
158 stars 17 forks source link

Support mocking the API #3

Open youknowriad opened 4 years ago

youknowriad commented 4 years ago

Some blocks depend on the WP API, it would be great to be able to mock the API to preview these blocks in isolation.

leoloso commented 4 years ago

To have in consideration: mocking should hopefully work with any API, not only with the WP REST API.

In my case, I use GraphQL to fetch data for my blocks, executing a GraphQL query over POST (some example queries here, and the fetch is executed here)

youknowriad commented 4 years ago

Most blocks rely on wp.apiFetch to perform the API requests, so it seems like a good candidate to mocking APIs. Right now, it's already possible to do so by registering a custom middleware. We can try to make it more user-friendly and document it.

For APIs not relying on wp.apiFetch, I think you should check if the library you're using allows interceptors, most generally do.