Skip to content

Commit

Permalink
feat: Replace GfFieldWithProductFieldSetting.productField for `.con…
Browse files Browse the repository at this point in the history
…nectedProductField`.
  • Loading branch information
justlevine committed Jun 15, 2024
1 parent 181ff20 commit 3ea279a
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- fix: Add missing descriptions to types.
- feat: Add `FieldError.connectedFormField` connection to `FieldError` type.
- feat: Add support for WPGraphQL Content Blocks.
- feat: Add `GfFieldWithProductFieldSetting.connectedProductField` connection and deprecate `.productField` field.
- dev: Remove `vendor` directory from the GitHub repository.
- dev: Use `FormFieldsDataLoader` to resolve fields instead of instantiating a new `Model`.
- dev: use WP_Filesystem to handle Signature field uploads.
Expand Down
6 changes: 4 additions & 2 deletions src/Registry/FormFieldRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,10 @@ static function ( TypeRegistry $type_registry ) use ( $field, $interface_setting

$config['resolveType'] = static function ( $value ) use ( $type_registry, $possible_types ) {
$input_type = $value->get_input_type();

if ( isset( $possible_types[ $input_type ] ) ) {
$type = $type_registry->get_type( $possible_types[ $value->$input_type ] );
$type = $type_registry->get_type( $possible_types[ $input_type ] );

if ( null !== $type ) {
return $type;
}
Expand All @@ -173,7 +175,7 @@ static function ( TypeRegistry $type_registry ) use ( $field, $interface_setting
/* translators: %s: GF field type */
esc_html__( 'The "%1$1s" Gravity Forms field does not yet support the %2$2s input type.', 'wp-graphql-gravity-forms' ),
esc_html( $value->type ),
esc_html( $value->inputType ),
esc_html( $input_type ?? $value->inputType ),
)
);
};
Expand Down
23 changes: 20 additions & 3 deletions src/Type/WPInterface/FieldSetting/FieldWithProductField.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

namespace WPGraphQL\GF\Type\WPInterface\FieldSetting;

use WPGraphQL\AppContext;
use WPGraphQL\GF\Data\Loader\FormFieldsLoader;

/**
* Class - FieldWithProductField
*/
Expand All @@ -34,9 +37,23 @@ class FieldWithProductField extends AbstractFieldSetting {
public static function get_fields(): array {
// @todo make connection.
return [
'productField' => [
'type' => 'Int',
'description' => __( 'The id of the product field to which the field is associated.', 'wp-graphql-gravity-forms' ),
'productField' => [
'type' => 'Int',
'description' => __( 'The id of the product field to which the field is associated.', 'wp-graphql-gravity-forms' ),
'deprecationReason' => __( 'Use `connectedProductField` field instead.', 'wp-graphql-gravity-forms' ),
],
'connectedProductField' => [
'type' => 'ProductField',
'description' => __( 'The product field to which the field is associated.', 'wp-graphql-gravity-forms' ),
'resolve' => static function ( $source, array $args, AppContext $context ) {
if ( ! isset( $context->gfForm ) || empty( $source->productField ) ) {
return null;
}

$id_for_loader = FormFieldsLoader::prepare_loader_id( $context->gfForm->databaseId, (int) $source->productField );

return $context->get_loader( FormFieldsLoader::$name )->load_deferred( $id_for_loader );
},
],
];
}
Expand Down
5 changes: 4 additions & 1 deletion tests/wpunit/OptionCheckboxFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,10 @@ public function field_query(): string {
shouldExport
}
placeholder
productField
connectedProductField {
databaseId
type
}
type
... on OptionCheckboxField {
checkboxValues {
Expand Down
5 changes: 4 additions & 1 deletion tests/wpunit/OptionRadioFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@ public function field_query(): string {
shouldExport
}
placeholder
productField
connectedProductField {
databaseId
type
}
type
... on OptionRadioField {
hasOtherChoice
Expand Down
5 changes: 4 additions & 1 deletion tests/wpunit/OptionSelectFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,10 @@ public function field_query(): string {
shouldExport
}
placeholder
productField
connectedProductField {
databaseId
type
}
type
... on OptionSelectField {
autocompleteAttribute
Expand Down
5 changes: 4 additions & 1 deletion tests/wpunit/QuantityHiddenFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ public function field_query(): string {
shouldExport
}
placeholder
productField
connectedProductField {
databaseId
type
}
type
... on QuantityHiddenField {
value
Expand Down
5 changes: 4 additions & 1 deletion tests/wpunit/QuantityNumberFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ public function field_query(): string {
shouldExport
}
placeholder
productField
connectedProductField {
databaseId
type
}
type
value
... on QuantityNumberField {
Expand Down
5 changes: 4 additions & 1 deletion tests/wpunit/QuantitySelectFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,10 @@ public function field_query(): string {
shouldExport
}
placeholder
productField
connectedProductField {
databaseId
type
}
type
value
... on QuantitySelectField {
Expand Down

0 comments on commit 3ea279a

Please sign in to comment.