Open jasonbahl opened 2 years ago
Any news on this?
@eliyadzz not yet. Would you be interested in contributing to make this happen?
We would really appreciate it if this feature could get integrated into the plugin. We're working a lot with option page (also those created with the acf_add_options_page ()
ACF function) in headless WordPress, so this would be very handy
Currently, WPGraphQL Smart Cache does not invalidate any caches when settings/options are changed (meaning values stored in the
wp_options
table).Refactor WPGraphQL core to treat options as models/nodes
This will allow WPGraphQL Smart Cache to properly map the setting groups to the cache map in the same way other nodes (posts, terms, etc) are mapped.
Direct Queries for Options should be be evicted when values change
The goal here is to ensure queries for direct option values are invalidated when said values are updated.
For example, a query such as:
should be evicted when the general settings url option is updated.
Queries for options should be mapped in the cache map. Currently this isn't happening because Options aren't using the DataLoader/Model/Node pattern (see above issue).
Once Options are refactored to use that pattern, this should probably be resolved already?
"Side-effect" evictions should be triggered when option values change
When options in WordPress are changed, they often have "side effects" that aren't always straight forward or centrally defined anywhere in WordPress core.
For example, changing rewrite rules affects anything with a URI, and we should probably call
purge_all
in response to said change.Or changing the
page_on_front
value would affect both the new and old page, and we should call purge on any queries that queried for the old or new page node. We probably don't need to purge all when this option changes, because we usually know the impact of this change.Since each option is treated differently, I believe we should identify a filterable list of options to track in response to the
updated_option
hook, and what callback should happen in response to said action.Something to the tune of (pseudo code):
The above are examples of some settings that should purge different caches when the values are changed. I think we need to do some case-by-case analysis of what should happen for each setting that WordPress core has built-in, and set a pattern for how 3rd party plugin/theme developers can hook in and tie their options to these evictions.
Future Idea I don't want to get lost
In the same way WPGraphQL respects additional fields on the
register_post_type
andregister_taxonomy
calls (such asshow_in_graphql
,graphql_single_name
,graphql_plural_name
) it would be nice if WPGraphQL could look for fields on theregister_setting
calls and then use that to determine which settings should be added to the filtered list above.For example, if I were do do something like so (pseudo code):