Skip to content
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

Adds filter to register_graphql_field to enable reusing logic of existing ACF types #288

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

pud1m
Copy link

@pud1m pud1m commented Aug 23, 2021

Hey there!

The problem
So, at Brius Media we've been using wp-graphql and wp-graphql-acf for exciting new projects.

One thing we've stumbled upon is that, when we create new field types inside ACF, we had some trouble getting wp-graphql-acf to recognize them. Turns out that, inside the register_graphql_field function (in class-config), there's a switch statement that checks for certain acf_types and handles the way they're going to be shown in the API and, when we create a new ACF type, there's no way we can "stick" something in there and add our own logic.

Since what we do, in order to reuse ACF's code, is to extend their original fields and add our own logic on top, all we needed was to "trick" the switch statement into thinking that, for instance, our "foo_bar_field" was a "post_object" field. We started editing wp-graphql-acf's source code directly but, as you can imagine, that's not ideal. We also wanted to contribute since maybe this is a problem for other people.

The solution
We added a filter inside register_graphql_field that allows us to change the acf_type before the switch statement, thus allowing us the "reuse" the already existing logic.

This is a super simple implementation, but I'm more than happy to assist in improving it so it can be merged and help other people.

Keep up the good work, guys!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant