Skip to content

Commit 8d8d94d

Browse files
authored
chore: better type hints and backfill missing descriptions (#433)
1 parent 5734c94 commit 8d8d94d

File tree

15 files changed

+86
-31
lines changed

15 files changed

+86
-31
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
- fix!: Keep `PageField` with previous page data when filtering `formFields` by `pageNumber`. H/t @SamuelHadsall .
1010
- fix: Handle RadioField submission values when using a custom "other" choice. H/t @Gytjarek .
1111
- fix: Check for Submission Confirmation url before attempting to get the associated post ID.
12-
- fix: Flush static Gravity Forms state between multiple calls to `GFUtils::submit_form()`.
12+
- fix: Flush static Gravity Forms state between multiple calls to `GFUtils::submit_form()`.
13+
- fix: Add missing descriptions to types.
1314
- feat: Add `FieldError.connectedFormField` connection to `FieldError` type.
1415
- feat: Add support for WPGraphQL Content Blocks.
1516
- dev: Remove `vendor` directory from the GitHub repository.
@@ -21,6 +22,7 @@
2122
- chore!: Bump minimum WPGraphQL version to v1.26.0.
2223
- chore!: Bump minimum WordPress version to v6.0.0.
2324
- chore!: Bump minimum Gravity Forms version to v2.7.0.
25+
- chore: Update PHP interfaces and Abstract classes with better type hints.
2426
- chore: Declare `strict_types` in all PHP files.
2527
- chore: Update Composer dev-dependencies and fix test compatibility with `wp-graphql-test-case` v3.0.x.
2628
- docs: Add docs on using Multi-page forms.

src/Connection/AbstractConnection.php

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,29 @@
1515

1616
/**
1717
* Class - AbstractConnection
18+
*
19+
* @phpstan-type ConnectionConfig array{fromType:string,
20+
* fromFieldName: string,
21+
* resolve: callable,
22+
* oneToOne?: bool,
23+
* toType?: string,
24+
* connectionArgs?: array<string,array{
25+
* type: string|array<string,string | array<string,string>>,
26+
* description: string,
27+
* defaultValue?: mixed
28+
* }>,
29+
* connectionFields?: array<string,array{
30+
* type: string|array<string,string | array<string,string>>,
31+
* description: string,
32+
* args?: array<string,array{
33+
* type: string|array<string,string | array<string,string>>,
34+
* description: string,
35+
* defaultValue?: mixed,
36+
* }>,
37+
* resolve?: callable,
38+
* deprecationReason?: string,
39+
* }>,
40+
* }
1841
*/
1942
abstract class AbstractConnection implements Hookable, Registrable {
2043
/**
@@ -34,7 +57,7 @@ public static function register_hooks(): void {
3457
/**
3558
* Gets custom connection configuration arguments, such as the resolver, edgeFields, connectionArgs, etc.
3659
*
37-
* @return array<string,array<string,mixed>>
60+
* @return array<string,array{type:string|array<string,string|array<string,string>>,description:string,defaultValue?:mixed}>
3861
*/
3962
public static function get_connection_args(): array {
4063
return [];
@@ -43,9 +66,9 @@ public static function get_connection_args(): array {
4366
/**
4467
* Returns a filtered array of connection args.
4568
*
46-
* @param string[] $filter_by .
69+
* @param ?string[] $filter_by an array of specific connections to return.
4770
*
48-
* @return array<string,array<string,mixed>>
71+
* @return array<string,array{type:string|array<string,string|array<string,string>>,description:string,defaultValue?:mixed}>
4972
*/
5073
public static function get_filtered_connection_args( ?array $filter_by = null ): array {
5174
$connection_args = static::get_connection_args();

src/Extensions/GFQuiz/Type/WPObject/QuizResults/QuizResultsFieldCount.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ public static function get_type_config(): array {
4141
public static function get_connections(): array {
4242
return [
4343
'formField' => [
44-
'toType' => 'QuizField',
45-
'oneToOne' => true,
46-
'resolve' => static function ( $source ): array {
44+
'toType' => 'QuizField',
45+
'description' => __( 'The quiz field.', 'wp-graphql-gravity-forms' ),
46+
'oneToOne' => true,
47+
'resolve' => static function ( $source ): array {
4748
return [ 'node' => $source['field'] ];
4849
},
4950
],

src/Interfaces/Enum.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
// phpcs:ignore PHPCompatibility.Keywords.ForbiddenNames.enumFound -- @todo Remove b/c
1717
interface Enum {
1818
/**
19-
* Gets the Enum type values.
19+
* Gets the Enum values configuration array.
2020
*
21-
* @return array<string,array<string,mixed>>
21+
* @return array<string,array{description:string,value:mixed,deprecationReason?:string}>
2222
*/
2323
public static function get_values(): array;
2424
}

src/Interfaces/Mutation.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,16 @@
1515
*/
1616
interface Mutation {
1717
/**
18-
* Defines the input field configuration.
18+
* Gets the input fields for the mutation.
1919
*
20-
* @return array<string,array<string,mixed>>
21-
*
22-
* @since 0.4.0
20+
* @return array<string,array{type:string|array<string,string|array<string,string>>,description:string,defaultValue?:string}>
2321
*/
2422
public static function get_input_fields(): array;
2523

2624
/**
27-
* Defines the output field configuration.
25+
* Gets the fields for the type.
2826
*
29-
* @return array<string,array<string,mixed>>
30-
*
31-
* @since 0.4.0
27+
* @return array<string,array{type:string|array<string,string|array<string,string>>,description:string,args?:array<string,array{type:string|array<string,string|array<string,string>>,description:string,defaultValue?:mixed}>,resolve?:callable,deprecationReason?:string}>
3228
*/
3329
public static function get_output_fields(): array;
3430

src/Interfaces/TypeWithConnections.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
*/
1616
interface TypeWithConnections {
1717
/**
18-
* Gets the the connection config for the GraphQL Type.
18+
* Gets the properties for the type.
1919
*
20-
* @return array<string,array<string,mixed>>
20+
* @return array<string,array{toType:string,description:string,args?:array<string,array{type:string|array<string,string|array<string,string>>,description:string,defaultValue?:mixed}>,connectionInterfaces?:string[],oneToOne?:bool,resolve?:callable}>
2121
*/
2222
public static function get_connections(): array;
2323
}

src/Interfaces/TypeWithFields.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
*/
1616
interface TypeWithFields {
1717
/**
18-
* Gets the GraphQL fields for the type.
18+
* Gets the fields for the type.
1919
*
20-
* @return array<string,array<string,mixed>> The GraphQL field configs for the type.
20+
* @return array<string,array{type:string|array<string,string|array<string,string>>,description:string,args?:array<string,array{type:string|array<string,string|array<string,string>>,description:string,defaultValue?:mixed}>,resolve?:callable,deprecationReason?:string}>
2121
*/
2222
public static function get_fields(): array;
2323
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
/**
3+
* Interface for a GraphQL TypeWithInputFields.
4+
*
5+
* @package WPGraphQL\GF\Interfaces
6+
* @since 0.10.0
7+
*/
8+
9+
declare( strict_types = 1 );
10+
11+
namespace WPGraphQL\GF\Interfaces;
12+
13+
/**
14+
* Interface - TypeWithInputFields.
15+
*/
16+
interface TypeWithInputFields {
17+
/**
18+
* Gets the input fields for the type.
19+
*
20+
* @return array<string,array{type:string|array<string,string|array<string,string>>,description:string,defaultValue?:string}>
21+
*/
22+
public static function get_fields(): array;
23+
}

src/Type/Enum/AbstractEnum.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ abstract class AbstractEnum extends AbstractType implements Enum, TypeWithDescri
2525
*/
2626
public static string $type;
2727

28+
/**
29+
* Gets the Enum values configuration array.
30+
*
31+
* @return array<string,array{description:string,value:mixed,deprecationReason?:string}>
32+
*/
33+
abstract public static function get_values(): array;
34+
2835
/**
2936
* {@inheritDoc}
3037
*/

src/Type/Input/AbstractInput.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
namespace WPGraphQL\GF\Type\Input;
1212

1313
use WPGraphQL\GF\Interfaces\TypeWithDescription;
14-
use WPGraphQL\GF\Interfaces\TypeWithFields;
14+
use WPGraphQL\GF\Interfaces\TypeWithInputFields;
1515
use WPGraphQL\GF\Type\AbstractType;
1616

1717
/**
1818
* Class - AbstractInput
1919
*/
20-
abstract class AbstractInput extends AbstractType implements TypeWithDescription, TypeWithFields {
20+
abstract class AbstractInput extends AbstractType implements TypeWithDescription, TypeWithInputFields {
2121
/**
2222
* Type registered in WPGraphQL.
2323
*

0 commit comments

Comments
 (0)