Skip to content

Commit 2592f79

Browse files
authored
chore: Add compatibility for WPGraphQL 2.3.3 and lazy-loaded descriptions. (#457)
* fix: check for missing `$context->gfField` before use * dev: support WPGraphQL 2.3.3 * dev: lazy-load `description` strings * chore: headers bump
1 parent 704fa8b commit 2592f79

File tree

264 files changed

+1219
-1044
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

264 files changed

+1219
-1044
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## [Unreleased]
4+
5+
- dev: Add support for lazy-loaded descriptions.
6+
- ci: Test compatibility against WPGraphWL v2.3.3.
7+
38
## [v0.13.1]
49

510
This _minor_ release tests compatibility against WordPress 6.8.x and WPGraphQL 1.31.x.

composer.lock

Lines changed: 39 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker/app.post-setup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ install_gf || true
4040

4141
# Install WPGraphQL and Activate
4242
if ! $( wp plugin is-installed wp-graphql --allow-root ); then
43-
wp plugin install wp-graphql --version=1.32.1 --allow-root
43+
wp plugin install wp-graphql --allow-root
4444
fi
4545
wp plugin activate wp-graphql --allow-root
4646

docs/recipes/register-custom-field-value-inputs.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ For example:
1818
register_graphql_input_type(
1919
'MyCustomFieldValueInput',
2020
[
21-
'description' => __( 'The `fieldValues` input for a MyCustomField field.', 'my-plugin' ),
21+
'description' => static fn () => __( 'The `fieldValues` input for a MyCustomField field.', 'my-plugin' ),
2222
'fields' => [
2323
//see https://www.wpgraphql.com/functions/register_graphql_input_type/
2424
],
@@ -37,7 +37,7 @@ add_filter(
3737
function( array $fields ) : array {
3838
$fields['myCustomFieldValues'] = [ // The field value name.
3939
'type' => 'MyCustomFieldValueInput', // This is registered above.
40-
'description' => __( 'The form field values for MyCustomField fields.', 'my-plugin'),
40+
'description' => static fn () => __( 'The form field values for MyCustomField fields.', 'my-plugin'),
4141
];
4242
}
4343
);

docs/recipes/register-custom-form-field.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ register_graphql_field(
2222
'myCustomProperty',
2323
[
2424
'type' => 'String',
25-
'description' => __( 'This is a custom property that exists on my custom GF field', 'my-plugin' ),
25+
'description' => static fn () => __( 'This is a custom property that exists on my custom GF field', 'my-plugin' ),
2626
'resolve' => fn( $source ) => $source->my_custom_property // if the GF_Field property is the same name as the GraphQL field, this can be ommitted.
2727
]
2828
);
@@ -36,7 +36,7 @@ register_graphql_field(
3636
'myCustomFormFieldValue',
3737
[
3838
'type' => 'MyCustomFormFieldValueObject',
39-
'description' => __( 'The Field Value object for my custom GF field.', 'my-plugin'),
39+
'description' => static fn () => __( 'The Field Value object for my custom GF field.', 'my-plugin'),
4040
'resolve' => function( $source ){
4141
/**
4242
* Usually, the entry is saved in the formField's context/
@@ -78,7 +78,7 @@ add_filter(
7878
// Add `myCustomField` to the GraphQL type.
7979
$fields['myCustomField'] = [
8080
'type' => 'String',
81-
'description' => __( 'The autocomplete attribute for the field.', 'wp-graphql-gravity-forms' ),
81+
'description' => static fn () => __( 'The autocomplete attribute for the field.', 'wp-graphql-gravity-forms' ),
8282
];
8383

8484
return $fields;

docs/recipes/register-form-to-custom-field.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function my_add_form_to_post() {
2727
'form', // The field name to add.
2828
// The config object:
2929
[
30-
'description' => __( 'The Gravity Forms form for the post', 'my-plugin' ),
30+
'description' => static fn () => __( 'The Gravity Forms form for the post', 'my-plugin' ),
3131
'type' => \WPGraphQL\GF\Type\WPObject\Form\Form::$type,
3232
'resolve' => static function( $source, array $args, \WPGraphQL\AppContext $context ){
3333
// Get the form id from the post meta.

phpstan/class-app-context.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,31 @@ class SubmittedEntry {}
66
class DraftEntry {}
77
class FormField {}
88

9+
namespace WPGraphQL\Data\Loader;
10+
abstract class AbstractDataLoader {}
11+
12+
namespace WPGraphQL\GF\Data\Loader;
13+
class DraftEntriesLoader {}
14+
class EntriesLoader {}
15+
class FormsLoader {}
16+
class FormFieldsLoader {}
17+
918
namespace WPGraphQL;
1019
/**
1120
* @property ?\WPGraphQL\GF\Model\Form $gfForm
1221
* @property \WPGraphQL\GF\Model\SubmittedEntry|\WPGraphQL\GF\Model\DraftEntry|null $gfEntry
1322
* @property ?\WPGraphQL\GF\Model\FormField $gfField
1423
*/
15-
class AppContext {}
24+
class AppContext {
25+
/**
26+
* @param string $key
27+
* @return ( $key is 'gf_draft_entry' ? \WPGraphQL\GF\Data\Loader\DraftEntriesLoader :
28+
* ( $key is 'gf_entry' ? \WPGraphQL\GF\Data\Loader\EntriesLoader :
29+
* ( $key is 'gf_form' ? \WPGraphQL\GF\Data\Loader\FormsLoader :
30+
* ( $key is 'gf_form_field' ? \WPGraphQL\GF\Data\Loader\FormFieldsLoader : \WPGraphQL\Data\Loader\AbstractDataLoader )
31+
* )
32+
* )
33+
* )
34+
*/
35+
public function get_loader($key){}
36+
}

src/Connection/AbstractConnection.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@
2323
* toType?: string,
2424
* connectionArgs?: array<string,array{
2525
* type: string|array<string,string | array<string,string>>,
26-
* description: string,
26+
* description: callable():string,
2727
* defaultValue?: mixed
2828
* }>,
2929
* connectionFields?: array<string,array{
3030
* type: string|array<string,string | array<string,string>>,
31-
* description: string,
31+
* description: callable():string,
3232
* args?: array<string,array{
3333
* type: string|array<string,string | array<string,string>>,
34-
* description: string,
34+
* description: callable():string,
3535
* defaultValue?: mixed,
3636
* }>,
3737
* resolve?: callable,
38-
* deprecationReason?: string,
38+
* deprecationReason?: callable():string,
3939
* }>,
4040
* }
4141
*/
@@ -57,7 +57,7 @@ public static function register_hooks(): void {
5757
/**
5858
* Gets custom connection configuration arguments, such as the resolver, edgeFields, connectionArgs, etc.
5959
*
60-
* @return array<string,array{type:string|array<string,string|array<string,string>>,description:string,defaultValue?:mixed}>
60+
* @return array<string,array{type:string|array<string,string|array<string,string>>,description:callable():string,defaultValue?:mixed}>
6161
*/
6262
public static function get_connection_args(): array {
6363
return [];
@@ -68,7 +68,7 @@ public static function get_connection_args(): array {
6868
*
6969
* @param ?string[] $filter_by an array of specific connections to return.
7070
*
71-
* @return array<string,array{type:string|array<string,string|array<string,string>>,description:string,defaultValue?:mixed}>
71+
* @return array<string,array{type:string|array<string,string|array<string,string>>,description:callable():string,defaultValue?:mixed}>
7272
*/
7373
public static function get_filtered_connection_args( ?array $filter_by = null ): array {
7474
$connection_args = static::get_connection_args();

0 commit comments

Comments
 (0)