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: improved handling of clone and group fields #193

Merged
merged 25 commits into from
Apr 24, 2024

Conversation

jasonbahl
Copy link
Contributor

@jasonbahl jasonbahl commented Apr 5, 2024

What does this implement/fix? Explain your changes.

This is an attempt at fixing a bug related to cloning field groups that have a field of the "group" field within them.

For the situation described in #172 this gets the Schema to load and lets the fields be queried, but there are some things missing still.

For example: the Interface for the field group being cloned isn't being applied properly to the Type representing the Flexible Content Layout

Does this close any currently open issues?

closes #172
closes #197

related: wp-graphql/wp-graphql#3100

Any relevant logs, error output, GraphiQL screenshots, etc?

Given the ACF Field Groups in #172:

BEFORE:

Errors fetching the schema, as described in #172

CleanShot 2024-04-05 at 15 33 34

AFTER:

The Schema loads, and I can query data

CleanShot 2024-04-05 at 15 32 04

Any other comments?

I should be able to use the following fragment:

fragment ContentBlocksBlocksAccordionLayout on ContentBlocksBlocksAccordionLayout {
  ...BlockAccordion_Fields
}

fragment BlockAccordion_Fields on BlockAccordion_Fields {
    accordionItems {
    title
    description
  }
  description
  icon {
    node {
      mediaItemUrl
    }
  }
  sectionId
  title
  variant
}

But this is showing invalid because BlockAccordion_Fields is being applied to ContentBlocksBlocksAccordionLayoutAccordion and not ContentBlocksBlocksAccordionLayout

I believe there's some correlation with how Flex Field Layouts are mapped to the schema in /src/FieldType/FlexibleContent.php and how cloned groups apply their interfaces in src/FieldType/CloneField.php, but I've not been able to pin it down quite yet.

These fragments now work as expected.

…roblem. . .but gets us heading in the right direction
@jasonbahl jasonbahl marked this pull request as draft April 5, 2024 21:38
@jasonbahl jasonbahl self-assigned this Apr 5, 2024
…d to a field group

- update CloneField.php to return 'NULL' type as the registry handles getting the interfaces now
- update Group.php field type to return the Cloned Type if possible instead of registering a new Type
@jasonbahl jasonbahl marked this pull request as ready for review April 8, 2024 20:20
@coveralls
Copy link

coveralls commented Apr 8, 2024

Pull Request Test Coverage Report for Build 819424c07072e8c3e12fa932f8ef4586a90d56a1-PR-193

Details

  • 30 of 86 (34.88%) changed or added relevant lines in 7 files are covered.
  • 23 unchanged lines in 3 files lost coverage.
  • Overall coverage decreased (-1.0%) to 62.68%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/FieldType/FlexibleContent.php 0 1 0.0%
src/FieldConfig.php 2 4 50.0%
src/FieldType/CloneField.php 2 6 33.33%
src/Registry.php 20 24 83.33%
src/Admin/Settings.php 0 11 0.0%
src/FieldType/Repeater.php 3 14 21.43%
src/FieldType/Group.php 3 26 11.54%
Files with Coverage Reduction New Missed Lines %
src/Admin/Settings.php 1 0.0%
src/ThirdParty/AcfExtended/AcfExtended.php 1 89.1%
src/FieldType/CloneField.php 21 26.67%
Totals Coverage Status
Change from base Build d44413e138f947625195405be861d734b3cf6d4d: -1.0%
Covered Lines: 2091
Relevant Lines: 3336

💛 - Coveralls

@nhankla-kl
Copy link

Having some build errors but will log what we did to fix them.

josephfusco
josephfusco previously approved these changes Apr 9, 2024
Copy link
Member

@josephfusco josephfusco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to reproduce the original issue and confirm that the schema does not break with the changes in this PR 🙌🏻

@jasonbahl
Copy link
Contributor Author

@nhankla-kl thank you! 🙏🏻 Also happy to hop on a call if that would be helpful too. You can reach me in the WPGraphQL Slack if you would like to zoom or whatever.

@nhankla-kl
Copy link

Gettin Schema issues still:

Failure running getIntrospectionQuery: {
"graphQLErrors": [
{
"message": "The field 'subLayout' on Type 'PostSectionsPostSectionsContentLayout_Fields' is configured to return 'PostContentSubLayout' which is a non-existent Type in the Schema. Make sure to define a valid type for all fields. This might occur if there was a typo with 'PostContentSubLayout', or it needs to be registered to the Schema.",
"extensions": {
"category": "graphql"
},
"locations": [
{
"line": 15,
"column": 5
}
],
"path": [
"__schema",
"types"
],
"trace": [
{
"file": "/sites/dev-back-vertice.kernandlead.com/files/wp-content/plugins/wp-graphql/vendor/webonyx/graphql-php/src/Type/Schema.php",
"line": 406,
"call": "WPGraphQL\Registry\TypeRegistry::WPGraphQL\Registry\{closure}()"
},
{
"file": "/sites/dev-back-vertice.kernandlead.com/files/wp-content/plugins/wp-graphql/vendor/webonyx/graphql-php/src/Type/Definition/FieldDefinition.php",
"line": 210,
"call": "GraphQL\Type\Schema::resolveType()"
},
{
"file": "/sites/dev-back-vertice.kernandlead.com/files/wp-content/plugins/wp-graphql/vendor/webonyx/graphql-php/src/Utils/TypeInfo.php",
"line": 213,
"call": "GraphQL\Type\Definition\FieldDefinition::getType()"
},
{
"file": "/sites/dev-back-vertice.kernandlead.com/files/wp-content/plugins/wp-graphql/vendor/webonyx/graphql-php/src/Type/Schema.php",
"line": 222,
"call": "GraphQL\Utils\TypeInfo::extractTypes()"
},
{
"file": "/sites/dev-back-vertice.kernandlead.com/files/wp-content/plugins/wp-graphql/vendor/webonyx/graphql-php/src/Type/Schema.php",
"line": 208,
"call": "GraphQL\Type\Schema::collectAllTypes()"
},
{
"file": "/sites/dev-back-vertice.kernandlead.com/files/wp-content/plugins/wp-graphql/vendor/webonyx/graphql-php/src/Type/Introspection.php",
"line": 240,
"call": "GraphQL\Type\Schema::getTypeMap()"
},
{
"file": "/sites/dev-back-vertice.kernandlead.com/files/wp-content/plugins/wp-graphql/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
"line": 623,
"call": "GraphQL\Type\Introspection::GraphQL\Type\{closure}()"
},
{
"file": "/sites/dev-back-vertice.kernandlead.com/files/wp-content/plugins/wp-graphql/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
"line": 550,
"call": "GraphQL\Executor\ReferenceExecutor::resolveFieldValueOrError()"
},
{
"file": "/sites/dev-back-vertice.kernandlead.com/files/wp-content/plugins/wp-graphql/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
"line": 1195,
"call": "GraphQL\Executor\ReferenceExecutor::resolveField()"
},
{
"file": "/sites/dev-back-vertice.kernandlead.com/files/wp-content/plugins/wp-graphql/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
"line": 1145,
"call": "GraphQL\Executor\ReferenceExecutor::executeFields()"
},
{
"file": "/sites/dev-back-vertice.kernandlead.com/files/wp-content/plugins/wp-graphql/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
"line": 1106,
"call": "GraphQL\Executor\ReferenceExecutor::collectAndExecuteSubfields()"
},
{
"file": "/sites/dev-back-vertice.kernandlead.com/files/wp-content/plugins/wp-graphql/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
"line": 793,
"call": "GraphQL\Executor\ReferenceExecutor::completeObjectValue()"
},
{
"file": "/sites/dev-back-vertice.kernandlead.com/files/wp-content/plugins/wp-graphql/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
"line": 741,
"call": "GraphQL\Executor\ReferenceExecutor::completeValue()"
},
{
"file": "/sites/dev-back-vertice.kernandlead.com/files/wp-content/plugins/wp-graphql/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
"line": 654,
"call": "GraphQL\Executor\ReferenceExecutor::completeValue()"
},
{
"file": "/sites/dev-back-vertice.kernandlead.com/files/wp-content/plugins/wp-graphql/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
"line": 557,
"call": "GraphQL\Executor\ReferenceExecutor::completeValueCatchingError()"
},
{
"file": "/sites/dev-back-vertice.kernandlead.com/files/wp-content/plugins/wp-graphql/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
"line": 1195,
"call": "GraphQL\Executor\ReferenceExecutor::resolveField()"
},
{
"file": "/sites/dev-back-vertice.kernandlead.com/files/wp-content/plugins/wp-graphql/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
"line": 264,
"call": "GraphQL\Executor\ReferenceExecutor::executeFields()"
},
{
"file": "/sites/dev-back-vertice.kernandlead.com/files/wp-content/plugins/wp-graphql/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
"line": 215,
"call": "GraphQL\Executor\ReferenceExecutor::executeOperation()"
},
{
"file": "/sites/dev-back-vertice.kernandlead.com/files/wp-content/plugins/wp-graphql/vendor/webonyx/graphql-php/src/Executor/Executor.php",
"line": 156,
"call": "GraphQL\Executor\ReferenceExecutor::doExecute()"
},
{
"file": "/sites/dev-back-vertice.kernandlead.com/files/wp-content/plugins/wp-graphql/vendor/webonyx/graphql-php/src/GraphQL.php",
"line": 162,
"call": "GraphQL\Executor\Executor::promiseToExecute()"
},
{
"file": "/sites/dev-back-vertice.kernandlead.com/files/wp-content/plugins/wp-graphql/vendor/webonyx/graphql-php/src/Server/Helper.php",
"line": 311,
"call": "GraphQL\GraphQL::promiseToExecute()"
},
{
"file": "/sites/dev-back-vertice.kernandlead.com/files/wp-content/plugins/wp-graphql/vendor/webonyx/graphql-php/src/Server/Helper.php",
"line": 211,
"call": "GraphQL\Server\Helper::promiseToExecuteOperation()"
},
{
"file": "/sites/dev-back-vertice.kernandlead.com/files/wp-content/plugins/wp-graphql/vendor/webonyx/graphql-php/src/Server/StandardServer.php",
"line": 136,
"call": "GraphQL\Server\Helper::executeOperation()"
},
{
"file": "/sites/dev-back-vertice.kernandlead.com/files/wp-content/plugins/wp-graphql/src/Request.php",
"line": 703,
"call": "GraphQL\Server\StandardServer::executeRequest()"
},
{
"file": "/sites/dev-back-vertice.kernandlead.com/files/wp-content/plugins/wp-graphql/src/Router.php",
"line": 465,
"call": "WPGraphQL\Request::execute_http()"
},
{
"file": "/sites/dev-back-vertice.kernandlead.com/files/wp-content/plugins/wp-graphql/src/Router.php",
"line": 257,
"call": "WPGraphQL\Router::process_http_request()"
},
{
"file": "/sites/dev-back-vertice.kernandlead.com/files/wp-includes/class-wp-hook.php",
"line": 324,
"call": "WPGraphQL\Router::resolve_http_request()"
},
{
"file": "/sites/dev-back-vertice.kernandlead.com/files/wp-includes/class-wp-hook.php",
"line": 348,
"call": "WP_Hook::apply_filters()"
},
{
"file": "/sites/dev-back-vertice.kernandlead.com/files/wp-includes/plugin.php",
"line": 565,
"call": "WP_Hook::do_action()"
},
{
"file": "/sites/dev-back-vertice.kernandlead.com/files/wp-includes/class-wp.php",
"line": 418,
"function": "do_action_ref_array()"
},
{
"file": "/sites/dev-back-vertice.kernandlead.com/files/wp-includes/class-wp.php",
"line": 813,
"call": "WP::parse_request()"
},
{
"file": "/sites/dev-back-vertice.kernandlead.com/files/wp-includes/functions.php",
"line": 1336,
"call": "WP::main()"
},
{
"file": "/sites/dev-back-vertice.kernandlead.com/files/wp-blog-header.php",
"line": 16,
"function": "wp()"
},
{
"file": "/sites/dev-back-vertice.kernandlead.com/files/index.php",
"line": 17,
"function": "require('/sites/dev-back-vertice.kernandlead.com/files/wp-blog-header.php')"
}
]
}
],
"clientErrors": [],
"networkError": null,
"message": "The field 'subLayout' on Type 'PostSectionsPostSectionsContentLayout_Fields' is configured to return 'PostContentSubLayout' which is a non-existent Type in the Schema. Make sure to define a valid type for all fields. This might occur if there was a typo with 'PostContentSubLayout', or it needs to be registered to the Schema."
}

@jasonbahl
Copy link
Contributor Author

@nhankla-kl can you provide an export of your ACF Field Groups so we can try and reproduce?

@jasonbahl jasonbahl closed this Apr 10, 2024
@jasonbahl
Copy link
Contributor Author

oops. didn't mean to close.

@jasonbahl jasonbahl reopened this Apr 10, 2024
@nhankla-kl
Copy link

Sure

acf-export-2024-04-10.json

@jasonbahl
Copy link
Contributor Author

@nhankla-kl was your ACF Field Groups working in the Schema prior to this PR and breaking in this PR?

@nhankla-kl
Copy link

@jasonbahl it works in .5.5.3

@jasonbahl
Copy link
Contributor Author

@nhankla-kl WPGraphQL for ACF v0.5.3? As in this version: https://github.com/wp-graphql/wp-graphql-acf/releases/tag/v0.5.3?

@nhankla-kl
Copy link

@jasonbahl correct

Screenshot 2024-04-10 at 12 24 03 PM

@jasonbahl
Copy link
Contributor Author

jasonbahl commented Apr 10, 2024

@nhankla-kl Ok so WPGraphQL for ACF v2.2.0 release also does not work, I assume? https://github.com/wp-graphql/wpgraphql-acf/releases/tag/v2.2.0

This specific PR did not break anything?

If you are looking to migrate from v0.. to v2.*, I recommend checking the upgrade guide here: https://acf.wpgraphql.com/upgrade-guide/

It has some helpful information on things to look for in the Schema, such as avoiding special characters in GraphQL Type and Field names, avoiding field/type names starting with a number, etc.

I did import your ACF field group and will see if I can help identify how to best support it, but it doesn't seem that this specific PR has caused any new issues compared to v2.2.0

@jasonbahl
Copy link
Contributor Author

@nhankla-kl One thing I noticed is that you had a couple instances of different ACF Field Groups with the same GraphQL Type Name:

  • [module] Blog by Categories
  • [module] Blog List

Both had the GraphQL Type Name: ModuleBlog

  • [module] Content Grid
  • [module] News

Both had the GraphQL Type Name ModuleNews

  • [module] Video Hero
  • [module] Hero

Both had the GraphQL Type Name ModuleHero

I'm still looking through things, but these are some observations so far.

@jasonbahl
Copy link
Contributor Author

@nhankla-kl Ok, I think I'm getting close to understanding another bug.

It appears that there is a bug when it comes to cloning a field group that contains other cloned field groups.

For example, you have the [module] Alternating Row which has the following clone fields:

  • header
  • media
  • background
  • slant
  • border
  • layout

It appears that somehow the double cloning isn't properly assigning GraphQL Interfaces to the schema.

I'm working to better understand why this is and figure out a fix for it.

@jasonbahl
Copy link
Contributor Author

@nhankla-kl I think I might have discovered the problem and am working on updating this PR with a solution. Hopefully will have something to test shortly 🤞🏻

@jasonbahl
Copy link
Contributor Author

@nhankla-kl I've pushed up several changes to this PR and I believe we're getting close to having things work for the original scenario and the scenario you brought up if you want to give it another try.

Comment on lines +45 to +53
echo "Installing WPGraphQL from GitHub repo ${WPGRAPHQL_GIT_REPO}"
# Clone the repository
git clone -b ${WPGRAPHQL_GIT_BRANCH} ${WPGRAPHQL_GIT_REPO} "${PLUGINS_DIR}/wp-graphql"
# Navigate to the plugin directory
cd "${PLUGINS_DIR}/wp-graphql"
# Install dependencies with Composer
composer install --no-dev
# Optionally activate the plugin using wp-cli
wp plugin activate wp-graphql --allow-root
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE:

This allows us to run tests against arbitrary branches of WPGraphQL.

For example, this feature relies on some work in this PR (wp-graphql/wp-graphql#3100)

So, I was able to update my .env.testing file with these values:

 WPGRAPHQL_GIT_REPO="https://github.com/jasonbahl/wp-graphql.git"
 WPGRAPHQL_GIT_BRANCH="fix/interface-recursion"

And tests pass when running against that branch of WPGraphQL 👏🏻 👏🏻

CleanShot 2024-04-19 at 11 40 22

@jasonbahl
Copy link
Contributor Author

@nhankla-kl I've updated #172 with a comment outlining steps to reproduce using the exported ACF Field Group you have provided.

Using your ACF Field Group, I am now able to load the Schema.

Before

Schema doesn't load properly and errors out the GraphiQL IDE

CleanShot 2024-04-22 at 10 07 50

After

Schema loads and I can use the GraphiQL IDE:

CleanShot 2024-04-22 at 10 08 22


Test added using the exported ACF Field Group provided above as an imported field group with assertions on querying the possible types and on executing an example query: 43d2b91

jasonbahl added a commit to wp-graphql/wp-graphql that referenced this pull request Apr 22, 2024
@nhankla-kl
Copy link

@jasonbahl this is amazing will test it on several dev sites that have similar ACF structure. Will let you know. Thanks!

@jasonbahl
Copy link
Contributor Author

related: wp-graphql/wp-graphql#3102 (specifically, see: wp-graphql/wp-graphql#3100)

@jasonbahl
Copy link
Contributor Author

@jasonbahl
Copy link
Contributor Author

And here we are, with all tests passing! 🥳

https://github.com/wp-graphql/wpgraphql-acf/actions/runs/8810691564

@jasonbahl jasonbahl merged commit 9a81fa1 into develop Apr 24, 2024
26 checks passed
@jasonbahl jasonbahl changed the title fix: cloning group fields feat: improved handling of clone and group fields Apr 24, 2024
@jasonbahl
Copy link
Contributor Author

@nhankla-kl fwiw, it seems like there still are some more bugs related to cloning field groups that have nested group fields.

I've broken it down into another issue that I'm continuing to troubleshoot: #201

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants