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

feat: deprecate FormField.id in favor of databaseId #352

Merged
merged 1 commit into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/form-field-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ For an example of the PostCategory field:
gfEntries{
formFields {
nodes {
id
databaseId
... on PostCategoryField { # the Interface
hasAllCategories
inputType
Expand Down
8 changes: 4 additions & 4 deletions docs/querying-entries.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The `id` input accepts either the Gravity Forms Entry ID ( `idType: DATABASE_ID`
isDraft
formFields(first: 300) {
nodes {
id
databaseId
type
... on TextField {
label
Expand All @@ -47,7 +47,7 @@ The `id` input accepts either the Gravity Forms Entry ID ( `idType: DATABASE_ID`
isStarred
formFields(first: 300) {
nodes {
id
databaseId
type
... on TextField {
label
Expand All @@ -74,7 +74,7 @@ Entries that include [Pricing Fields](https://docs.gravityforms.com/category/use
items {
connectedFormField {
... on ProductSingleField {
id
databaseId
}
}
currency
Expand All @@ -90,7 +90,7 @@ Entries that include [Pricing Fields](https://docs.gravityforms.com/category/use
options {
connectedFormField{
... on OptionCheckboxField {
id
databaseId
}
}
fieldLabel
Expand Down
9 changes: 5 additions & 4 deletions docs/querying-formfields.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ This method is best if you have a small form with a limited number of field type
databaseId
formFields(first: 300) {
nodes {
id
databaseId
type
cssClass
... on TextField {
Expand Down Expand Up @@ -65,7 +65,7 @@ Luckily, we can use [GraphQL Interfaces](https://graphql.org/learn/schema/#inter
databaseId
formFields(where: {pageNumber: 1}) {
nodes {
id
databaseId
inputType
type
... on GfFieldWithLabelSetting {
Expand Down Expand Up @@ -185,10 +185,11 @@ The code comments in the example query below explain how you can get a filtered
# Filter form fields by the page number in multi-page forms.
pageNumber: 2
}
) {
) {
nodes {
id
databaseId
type
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions docs/querying-forms.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The `id` input accepts either the Gravity Forms form ID (`idType: DATABASE_ID`)
dateCreated
formFields {
nodes {
id
databaseId
type
... on TextField {
label
Expand Down Expand Up @@ -71,7 +71,7 @@ The code comments in the example query below shows how you can fetch and filter
formFields(first: 300) {
nodes {
type
id
databaseId
cssClass
... on TextField {
label
Expand Down
8 changes: 7 additions & 1 deletion src/Type/WPInterface/FormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,14 @@ public static function get_fields() : array {
'resolve' => static fn ( $source ) : bool => ! empty( $source->displayOnly ),
],
'id' => [
'type' => [ 'non_null' => 'Int' ],
'description' => __( 'Field database ID.', 'wp-graphql-gravity-forms' ),
'deprecationReason' => __( 'This field will be changing to return a Global ID in a future release. Future-proof your code and use databaseId instead.', 'wp-graphql-gravity-forms' ),
],
'databaseId' => [
'type' => [ 'non_null' => 'Int' ],
'description' => __( 'Field ID.', 'wp-graphql-gravity-forms' ),
'description' => __( 'Field database ID.', 'wp-graphql-gravity-forms' ),
'resolve' => static fn ( $source ) : int => absint( $source->id ),
],
'inputType' => [
'type' => FormFieldTypeEnum::$type,
Expand Down
2 changes: 1 addition & 1 deletion tests/_support/TestCase/FormFieldTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ protected function entry_query() : string {
formFields {
nodes {
displayOnly
id
databaseId
inputType
layoutGridColumnSpan
layoutSpacerGridColumnSpan
Expand Down
1 change: 0 additions & 1 deletion tests/wpunit/CaptchaFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ public function field_query() : string {
return '
... on CaptchaField {
displayOnly
id
inputType
layoutGridColumnSpan
layoutSpacerGridColumnSpan
Expand Down
2 changes: 2 additions & 0 deletions tests/wpunit/EntryQueriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ private function get_entry_query() : string {
formFields {
nodes {
id
databaseId
}
}
id
Expand Down Expand Up @@ -285,6 +286,7 @@ public function expected_field_response( array $entry, array $form ) : array {
'nodes',
[
$this->expectedField( 'id', (int) $form['fields'][0]['id'] ),
$this->expectedField( 'databaseId', (int) $form['fields'][0]['id'] ),
]
),
]
Expand Down
1 change: 0 additions & 1 deletion tests/wpunit/ProductCalculationFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ public function field_query():string {
description
descriptionPlacement
displayOnly
id
inputName
inputType
label
Expand Down
1 change: 0 additions & 1 deletion tests/wpunit/ProductHiddenFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ public function field_query():string {
description
descriptionPlacement
displayOnly
id
inputName
inputType
label
Expand Down
1 change: 0 additions & 1 deletion tests/wpunit/ProductPriceFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ public function field_query():string {
description
descriptionPlacement
displayOnly
id
inputName
inputType
label
Expand Down
1 change: 0 additions & 1 deletion tests/wpunit/ProductRadioFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ public function field_query():string {
description
descriptionPlacement
displayOnly
id
inputName
inputType
label
Expand Down
1 change: 0 additions & 1 deletion tests/wpunit/ProductSelectFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ public function field_query():string {
description
descriptionPlacement
displayOnly
id
inputName
inputType
label
Expand Down
1 change: 0 additions & 1 deletion tests/wpunit/ProductSingleFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ public function field_query():string {
description
descriptionPlacement
displayOnly
id
inputName
inputType
label
Expand Down
14 changes: 7 additions & 7 deletions tests/wpunit/SubmitFormMutationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -670,21 +670,21 @@ public function testSubmitWithOrderItems() : void {
$this->assertEquals( 'USD', $actual['data']['submitGfForm']['entry']['orderSummary']['currency'] );

// Test first Order Item.
$this->assertEquals( $fields[0]->id, $actual['data']['submitGfForm']['entry']['orderSummary']['items'][0]['connectedFormField']['id'] );
$this->assertEquals( $fields[0]->id, $actual['data']['submitGfForm']['entry']['orderSummary']['items'][0]['connectedFormField']['databaseId'] );
$this->assertEquals( 'USD', $actual['data']['submitGfForm']['entry']['orderSummary']['items'][0]['currency'] );
$this->assertStringContainsString( $actual['data']['submitGfForm']['entry']['orderSummary']['items'][0]['price'], $fields[0]->basePrice );
$this->assertEquals( 2, $actual['data']['submitGfForm']['entry']['orderSummary']['items'][0]['quantity'] );
$expected_subtotal_one = floatval( preg_replace( '/[^\d\.]/', '', $fields[0]->basePrice ) ) * 2;
$this->assertEquals( $expected_subtotal_one, $actual['data']['submitGfForm']['entry']['orderSummary']['items'][0]['subtotal'] );

// Test second Order Item.
$this->assertEquals( $fields[1]->id, $actual['data']['submitGfForm']['entry']['orderSummary']['items'][1]['connectedFormField']['id'] );
$this->assertEquals( $fields[1]->id, $actual['data']['submitGfForm']['entry']['orderSummary']['items'][1]['connectedFormField']['databaseId'] );
$this->assertEquals( 'USD', $actual['data']['submitGfForm']['entry']['orderSummary']['items'][1]['currency'] );
$this->assertStringContainsString( $actual['data']['submitGfForm']['entry']['orderSummary']['items'][1]['price'], $fields[1]->basePrice );
$this->assertEquals( 2, $actual['data']['submitGfForm']['entry']['orderSummary']['items'][1]['quantity'] );
// Test options.
$this->assertNotEmpty( $actual['data']['submitGfForm']['entry']['orderSummary']['items'][1]['options'] );
$this->assertEquals( $fields[3]->id, $actual['data']['submitGfForm']['entry']['orderSummary']['items'][1]['options'][0]['connectedFormField']['id'] );
$this->assertEquals( $fields[3]->id, $actual['data']['submitGfForm']['entry']['orderSummary']['items'][1]['options'][0]['connectedFormField']['databaseId'] );
$this->assertEquals( $fields[3]->label, $actual['data']['submitGfForm']['entry']['orderSummary']['items'][1]['options'][0]['fieldLabel'] );
$this->assertEquals( $fields[3]->choices[0]['value'], $actual['data']['submitGfForm']['entry']['orderSummary']['items'][1]['options'][0]['name'] );
$this->assertEquals( $fields[3]->label . ': ' . $fields[3]->choices[0]['value'], $actual['data']['submitGfForm']['entry']['orderSummary']['items'][1]['options'][0]['optionLabel'] );
Expand All @@ -699,7 +699,7 @@ public function testSubmitWithOrderItems() : void {
$this->assertEquals( $expected_subtotal_two, $actual['data']['submitGfForm']['entry']['orderSummary']['items'][1]['subtotal'] );

// Test shipping field.
$this->assertEquals( $fields[4]->id, $actual['data']['submitGfForm']['entry']['orderSummary']['items'][2]['connectedFormField']['id'] );
$this->assertEquals( $fields[4]->id, $actual['data']['submitGfForm']['entry']['orderSummary']['items'][2]['connectedFormField']['databaseId'] );
$this->assertEquals( 'USD', $actual['data']['submitGfForm']['entry']['orderSummary']['items'][2]['currency'] );
$this->assertStringContainsString( $actual['data']['submitGfForm']['entry']['orderSummary']['items'][2]['price'], $fields[4]->basePrice );
$this->assertTrue( $actual['data']['submitGfForm']['entry']['orderSummary']['items'][2]['isShipping'] );
Expand Down Expand Up @@ -793,8 +793,8 @@ public function submit_mutation() : string {
orderSummary{
currency
items{
connectedFormField{
id
connectedFormField {
databaseId
}
currency
description
Expand All @@ -808,7 +808,7 @@ public function submit_mutation() : string {
name
options{
connectedFormField {
id
databaseId
}
fieldLabel
name
Expand Down