Skip to content

Commit 5cff081

Browse files
authored
dev: Use FormFieldsDataLoader to resolve fields instead of instantiating a new Model (#418)
* dev: Use `FormFieldsDataLoader` to resolve fields instead of instantiating a new `Model` * tests: cleanup * dev: use `FormsLoader` instead of creating new model
1 parent de8beb6 commit 5cff081

File tree

22 files changed

+341
-162
lines changed

22 files changed

+341
-162
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- feat!: Implement `FormField` model and `DataLoader`, and refactor `FormFieldsConnectionResolver` to extend `AbstractConnectionResolver`.
66
- feat!: Refactor `FormsConnectionResolver` and `EntriesConnectionResolver` for compatibility with WPGraphQL v1.26.0 improvements.
77
- feat!: Narrow `FormField.choices` and `FormField.inputs` field types to their implementations.
8+
- dev: Use `FormFieldsDataLoader` to resolve fields instead of instantiating a new `Model`.
89
- chore!: Bump minimum WPGraphQL version to v1.26.0.
910
- chore!: Bump minimum WordPress version to v6.0.0.
1011
- chore!: Bump minimum Gravity Forms version to v2.7.0.

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"codeception/phpunit-wrapper": "^9.0",
3636
"codeception/util-universalframework": "^1.0",
3737
"lucatume/wp-browser": "<3.5",
38-
"wp-graphql/wp-graphql-testcase": "~3.0.1",
38+
"wp-graphql/wp-graphql-testcase": "~3.3.0",
3939
"phpunit/phpunit": "^9.0",
4040
"phpstan/phpstan": "^1.2",
4141
"phpstan/extension-installer": "^1.1",
@@ -92,7 +92,7 @@
9292
"php ./vendor/bin/phpcbf"
9393
],
9494
"phpstan": [
95-
"phpstan analyze --ansi --memory-limit=1G"
95+
"phpstan analyze --ansi --memory-limit=1G -v"
9696
]
9797
},
9898
"archive": {

composer.lock

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

phpstan.neon.dist

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ parameters:
66
checkExplicitMixedMissingReturn: true
77
checkFunctionNameCase: true
88
checkInternalClassCaseSensitivity: true
9-
checkMissingIterableValueType: false # @todo make true
109
checkTooWideReturnTypesInProtectedAndPublicMethods: true
1110
inferPrivatePropertyTypeFromConstructor: true
1211
polluteScopeWithAlwaysIterableForeach: false
@@ -15,14 +14,12 @@ parameters:
1514
reportStaticMethodSignatures: true
1615
reportWrongPhpDocTypeInVarTag: true
1716
treatPhpDocTypesAsCertain: false
18-
featureToggles:
19-
disableRuntimeReflectionProvider: true
2017
dynamicConstantNames:
2118
- WPGRAPHQL_GF_AUTOLOAD
2219
stubFiles:
2320
# Simulate added properties
24-
- phpstan/class-app-context.stub
25-
- phpstan/class-gf-quiz.stub
21+
- phpstan/class-app-context.php
22+
- phpstan/class-gf-quiz.php
2623
bootstrapFiles:
2724
- phpstan/constants.php
2825
- wp-graphql-gravity-forms.php
@@ -38,4 +35,5 @@ parameters:
3835
- ../wp-gatsby/
3936
- ../wp-jamstack-deployments/
4037
ignoreErrors:
38+
- identifier: missingType.iterableValue
4139
- '#^Function gf_apply_filters(_ref_array)? invoked with ([1-9]|1[0-2]) parameters, 2 required\.$#'

phpstan/class-app-context.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace WPGraphQL;
4+
/**
5+
* @property ?\WPGraphQL\GF\Model\Form $gfForm
6+
* @property \WPGraphQL\GF\Model\SubmittedEntry|\WPGraphQL\GF\Model\SubmittedEntry|null $gfEntry
7+
* @property ?\WPGraphQL\GF\Model\FormField $gfField
8+
*/
9+
class AppContext {}

phpstan/class-app-context.stub

Lines changed: 0 additions & 9 deletions
This file was deleted.
File renamed without changes.

src/Data/Connection/FormFieldsConnectionResolver.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,14 @@ class FormFieldsConnectionResolver extends AbstractConnectionResolver {
4141

4242
/**
4343
* {@inheritDoc}
44+
*
45+
* @throws \Exception If the Form model is not set on the AppContext.
4446
*/
4547
public function __construct( $source, array $args, AppContext $context, ResolveInfo $info ) {
48+
if ( ! isset( $context->gfForm ) ) {
49+
throw new \Exception( 'The FormFieldsConnectionResolver requires a Form to be set on the AppContext.' );
50+
}
51+
4652
$this->form = $context->gfForm;
4753
$this->form_fields = ! empty( $source->formFields ) ? $source->formFields : [];
4854

@@ -176,7 +182,7 @@ protected function is_valid_model( $model ) {
176182
*/
177183
public function get_node_by_id( $id ) {
178184
// The id needs to include the form.
179-
$id_for_loader = (string) $this->form->databaseId . ':' . (string) $id;
185+
$id_for_loader = FormFieldsLoader::prepare_loader_id( $this->form->databaseId, (int) $id );
180186

181187
return parent::get_node_by_id( $id_for_loader );
182188
}

0 commit comments

Comments
 (0)