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

dev: Use FormFieldsDataLoader to resolve fields instead of instantiating a new Model #418

Merged
merged 3 commits into from
Jun 1, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- feat!: Implement `FormField` model and `DataLoader`, and refactor `FormFieldsConnectionResolver` to extend `AbstractConnectionResolver`.
- feat!: Refactor `FormsConnectionResolver` and `EntriesConnectionResolver` for compatibility with WPGraphQL v1.26.0 improvements.
- feat!: Narrow `FormField.choices` and `FormField.inputs` field types to their implementations.
- dev: Use `FormFieldsDataLoader` to resolve fields instead of instantiating a new `Model`.
- chore!: Bump minimum WPGraphQL version to v1.26.0.
- chore!: Bump minimum WordPress version to v6.0.0.
- chore!: Bump minimum Gravity Forms version to v2.7.0.
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"codeception/phpunit-wrapper": "^9.0",
"codeception/util-universalframework": "^1.0",
"lucatume/wp-browser": "<3.5",
"wp-graphql/wp-graphql-testcase": "~3.0.1",
"wp-graphql/wp-graphql-testcase": "~3.3.0",
"phpunit/phpunit": "^9.0",
"phpstan/phpstan": "^1.2",
"phpstan/extension-installer": "^1.1",
Expand Down Expand Up @@ -92,7 +92,7 @@
"php ./vendor/bin/phpcbf"
],
"phpstan": [
"phpstan analyze --ansi --memory-limit=1G"
"phpstan analyze --ansi --memory-limit=1G -v"
]
},
"archive": {
Expand Down
64 changes: 32 additions & 32 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ parameters:
checkExplicitMixedMissingReturn: true
checkFunctionNameCase: true
checkInternalClassCaseSensitivity: true
checkMissingIterableValueType: false # @todo make true
checkTooWideReturnTypesInProtectedAndPublicMethods: true
inferPrivatePropertyTypeFromConstructor: true
polluteScopeWithAlwaysIterableForeach: false
Expand All @@ -15,14 +14,12 @@ parameters:
reportStaticMethodSignatures: true
reportWrongPhpDocTypeInVarTag: true
treatPhpDocTypesAsCertain: false
featureToggles:
disableRuntimeReflectionProvider: true
dynamicConstantNames:
- WPGRAPHQL_GF_AUTOLOAD
stubFiles:
# Simulate added properties
- phpstan/class-app-context.stub
- phpstan/class-gf-quiz.stub
- phpstan/class-app-context.php
- phpstan/class-gf-quiz.php
bootstrapFiles:
- phpstan/constants.php
- wp-graphql-gravity-forms.php
Expand All @@ -38,4 +35,5 @@ parameters:
- ../wp-gatsby/
- ../wp-jamstack-deployments/
ignoreErrors:
- identifier: missingType.iterableValue
- '#^Function gf_apply_filters(_ref_array)? invoked with ([1-9]|1[0-2]) parameters, 2 required\.$#'
9 changes: 9 additions & 0 deletions phpstan/class-app-context.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace WPGraphQL;
/**
* @property ?\WPGraphQL\GF\Model\Form $gfForm
* @property \WPGraphQL\GF\Model\SubmittedEntry|\WPGraphQL\GF\Model\SubmittedEntry|null $gfEntry
* @property ?\WPGraphQL\GF\Model\FormField $gfField
*/
class AppContext {}
9 changes: 0 additions & 9 deletions phpstan/class-app-context.stub

This file was deleted.

File renamed without changes.
8 changes: 7 additions & 1 deletion src/Data/Connection/FormFieldsConnectionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,14 @@ class FormFieldsConnectionResolver extends AbstractConnectionResolver {

/**
* {@inheritDoc}
*
* @throws \Exception If the Form model is not set on the AppContext.
*/
public function __construct( $source, array $args, AppContext $context, ResolveInfo $info ) {
if ( ! isset( $context->gfForm ) ) {
throw new \Exception( 'The FormFieldsConnectionResolver requires a Form to be set on the AppContext.' );
}

$this->form = $context->gfForm;
$this->form_fields = ! empty( $source->formFields ) ? $source->formFields : [];

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

return parent::get_node_by_id( $id_for_loader );
}
Expand Down
Loading
Loading