Skip to content

Commit

Permalink
dev: prime form dataloader (#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
justlevine committed Jun 2, 2023
1 parent 17dcb6d commit a7b5d98
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -2,8 +2,9 @@

## Unreleased
- dev: Refactor database ID resolution when the GraphQL `ID` type is indeterminate. Note: The following input args now work with both database and global IDs: `GfEntriesConnectionWhereArgs.formIds`, `GfFormsConnectionwhereArgs.formIds`.
- docs: Add missing documentation regarding using `productValues` input when submitting forms.
- dev: Remove usage of deprecated `WPGraphQL\Data\DataSource::resolve_post_object()` method.
- dev: Prime the GfForm dataloader when querying form connections, to prevent unnecessary database queries.
- docs: Add missing documentation regarding using `productValues` input when submitting forms.

## v0.12.1 - Bug fix

Expand Down
9 changes: 8 additions & 1 deletion src/Data/Connection/FormsConnectionResolver.php
Expand Up @@ -110,6 +110,8 @@ public function get_query() : array {

$query = [];

$loader = $this->getLoader();

foreach ( $forms as $form ) {
/**
* "wp_graphql_gf_form_object" filter
Expand All @@ -120,7 +122,12 @@ public function get_query() : array {
*
* @param array $form Form meta array.
*/
$query[ $form['id'] ] = apply_filters( 'graphql_gf_form_object', $form );
$modified_form = apply_filters( 'graphql_gf_form_object', $form );

// Cache the form in the dataloader.
$loader->prime( $modified_form['id'], $modified_form );

$query[ $modified_form['id'] ] = $modified_form;
}

return $query;
Expand Down

0 comments on commit a7b5d98

Please sign in to comment.