Register ACF Select and Radio Fields as GraphQL Enum Types #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces a new feature to the
wp-graphql-acfplugin that allows automatic registration of ACF select and radio fields as GraphQL Enum types. This feature enhances the plugin's type-safety.The changes primarily consist of a new function
register_choices_of_acf_fields_as_enum_typeand modifications in the select and radio case block.The
register_choices_of_acf_fields_as_enum_typefunction takes an array representing an ACF field as input and checks if the field type is either 'select' or 'radio'. For such fields, the function generates a unique name and creates an array of Enum values using the provided choices in the field. If the enum type does not exist in the registry, it registers the enum type with its associated values and descriptions.The modifications to the case block for the 'radio' type for example ensure that the newly registered enum type is used as the field's type.
This change not only enhances the functionality of the
wp-graphql-acfplugin but also aligns it more closely with GraphQL's philosophy of strong typing. As such, it is expected to increase the robustness and reliability of interactions with ACF select and radio fields via the GraphQL API.The new feature has been thoroughly tested to ensure its seamless operation with existing functionalities.
Please review the changes and provide any feedback or questions you might have.