-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Block Bindings: Improve getRegisteredPostMeta resolver #65450
Block Bindings: Improve getRegisteredPostMeta resolver #65450
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
let options; | ||
try { | ||
const { | ||
rest_namespace: restNamespace = 'wp/v2', | ||
rest_base: restBase, | ||
} = ( await resolveSelect.getPostType( postType ) ) || {}; | ||
const options = await apiFetch( { | ||
options = await apiFetch( { | ||
path: `${ restNamespace }/${ restBase }/?context=edit`, | ||
method: 'OPTIONS', | ||
} ); | ||
} catch ( error ) { | ||
// Do nothing if the request comes back with an API error. | ||
return; | ||
} | ||
|
||
if ( options ) { |
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.
@@ -47,7 +47,7 @@ export interface State { | |||
navigationFallbackId: EntityRecordKey; | |||
userPatternCategories: Array< UserPatternCategory >; | |||
defaultTemplates: Record< string, string >; | |||
registeredPostMeta: Record< string, { postType: string } >; | |||
registeredPostMeta: Record< string, Object >; |
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 if Object
is enough or we should specify the properties. Those properties might change in the future if the REST API schema changes, and that seems unrelated to this part of the code. That's why ended up using just Object
.
Additionally, the other similar resolvers use the same.
Size Change: -5 B (0%) Total Size: 1.77 MB
ℹ️ View Unchanged
|
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.
Thank you for a quick follow up and inspecting how resolvers are handled in different places. It makes sense to replicate a similar approach.
What?
This PR covers two points reported here:
false
when there is an error.Why?
It doesn't seem right at the moment.
How?
For handling the error, I followed a similar approach to other resolvers like this one, this one, or this one.
Additionally, I updated the second parameter of Record to be
Object
.Testing Instructions
Everything should keep working as expected and e2e tests should pass.