-
Notifications
You must be signed in to change notification settings - Fork 122
"graphql_acf_relationship_post_model" hook added. #124
Conversation
$post_object = get_post( $post_id ); | ||
if ( $post_object instanceof \WP_Post ) { | ||
$post_model = new Post( $post_object ); | ||
} | ||
|
||
$post_model = apply_filters( 'graphql_acf_relationship_post_model', $post_model, $post_id, $root, $acf_field ); |
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.
@kidunot89 So, this is a bit of a band-aid and doesn't address the underlying issue.
Any other plugin like Carbon Fields, CMB2, Metabox.io, etc, etc will have similar needs as this, and going around filtering all their fields to play nice with WooCommerce custom Models doesn't scale.
First, I think the ACF plugin needs to take advantage of Deferred loading and use the Loader. That's on me to get updated in this repo.
This would then mean that the Model wouldn't even be instantiated in this resolver, so this would need to be handled more centrally in the Loader level.
Perhaps a central filter somewhere in the PostObjectLoader might help us re-route posts of the "product" type to the Product Model 🤔 (maybe that's already even happening?)
Then I think it might solve some headaches if WPGraphQL for WooCommerce extended the WPGraphQL Model Layer.
From what I can tell, you extend Model
class here: https://github.com/wp-graphql/wp-graphql-woocommerce/blob/develop/includes/model/class-crud-cpt.php#L20
And since the Crud_CPT
Model is intended to deal with CPTs, so you should probably extend the Post
model instead of just Model.
This would then mean that any field expecting a Post
model would work with any instance of a Product
Model, because they'd be an extension of the Post
model.
That would, I believe, solve a lot of one-off headaches around this stuff?
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 could try that, but it could definitely break some things.
@jasonbahl I was pretty sure we had resolved this in another PR, but I can't find that PR 🤦♂️ |
@kidunot89 oh gosh. This was the Model issue we discussed with @CodeProKid. Haha! |
Yea, but I remember us having video call where we resolved it. |
@kidunot89 ok, so I think this code needs to change to Then, in the loader we need to have a filter where you can return a Right now we have a check if it's a I think we should add a new method to the Abstract Loader called I can get a PR in shortly, then you can filter the loader to return whatever model(s) you need to. |
Yea, thats the solution I kinda remember. I though we had opened a PR then 😅. |
Adds a hook so a custom post type model can be provided to ACF "relationship" group type resolvers.
This is related to an issue in WooGraphQL #253.