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

Cloning a field group that contains a nested group field causes invalid schema #201

Open
2 of 3 tasks
jasonbahl opened this issue Apr 26, 2024 · 1 comment
Open
2 of 3 tasks
Assignees
Labels
type: bug Issue that causes incorrect or unexpected behavior

Comments

@jasonbahl
Copy link
Contributor

Description

When cloning a field group that contains a group field, the Schema produced is invalid and causes tooling such as the GraphiQL IDE to not load properly.

i.e.

CleanShot 2024-04-26 at 09 45 56

Steps to reproduce

The original scenario came from #172 and #193 but I'm detailing the steps here again in a simplified scenario and a more advanced scenario.

Both scenarios are starting with a fresh WP install with the following:

  • WordPress 6.5.2 on PHP 8.2
  • ACF Pro v6.2.7
  • WPGraphQL v1.24.0
  • WPGraphQL for ACF v2.3.0
  • WPGraphQL IDE v1.1.8

Simple Scenario

While this might not feel simple, it's the simplest breakdown I could come up with. You can either import the field groups using the JSON export provided further down, or expand the steps below to manually create the field groups.

Steps to manually create the field groups

##Create 3 field groups:

  • Field Group C
    • field 1:
    • type: text
    • label: Text Field
    • name: text_field
    • field 2:
      • type: group
      • label: Group Field
      • name: group_field
  • Field Group B
    • field 1:
      • type: Clone
      • label: Layout
      • name: layout
      • fields: "All fields from Field Group C field group"
  • Field Group A
    • field 1:
      • type: flexible_content
      • label: Flexible Content
      • name: flexible_content
      • layouts:
        • layout 1:
          • label: Layout One
          • name: layout_one
          • fields:
            • field 1:
              • type: clone
              • label: Cloned Field Group
              • name: cloned_field_group
              • fields: "All fields from Field Group B field group"

Given these 3 ACF Field Groups where Field Group A contains a flexible_content field that clones Field Group B which contains a clone field that clones Field Group C, if we try and load the GraphQL IDE, we are presented with the following error:

Interface field FieldGroupB_Fields.layout expects type FieldGroupCLayout but 
SectionsSectionsLayoutOneLayout_Fields.layout is type FieldGroupBLayout.

CleanShot 2024-04-26 at 10 04 49

More Advanced Scenario

I don't have the steps to manually reproduce written down, but you can import the JSON provided below, then load the Schema and be presented with a similar error.

Interface field PostContent_Fields.subLayout expects type SubmoduleLayoutSubLayout but
 PostSectionsPostSectionsContentLayout_Fields.subLayout is type PostContentSubLayout.

CleanShot 2024-04-26 at 10 05 38

PHP or JSON export of the ACF Field Group(s)

Simple Scenario

acf-export-2024-04-26.json

More Advanced Scenario

acf-export-issue-172-b.json

Additional context

I thought this bug was fixed in Release v2.3.0 (#200, via PR #193) and added the following tests for this scenario (https://github.com/wp-graphql/wpgraphql-acf/blob/develop/tests/functional/TestCloneGroupWithoutPrefixCest.php), but the tests were not comprehensive enough. While the queries can still be executed as shown in the tests, the "Introspection" query returns invalid types leading to the GraphiQL IDE failing to load as expected. We need a few more tests to ensure the Schema is valid, and not just that we can query for AcfFieldGroups and query for the post with the AcfFieldGroups

Related:


NOTE: this is NOT a regression of recent releases to WPGraphQL or WPGraphQL for ACF, it's just been identified as not fully resolved by the recent releases when it was believed to have been solved.

WPGraphQL Version

1.24.0

WPGraphQL For ACF Version

2.3.0

ACF (Advanced Custom Fields) Version. Free or Pro?

6.2.7 PRO

WordPress Version

6.5.2

PHP Version

8.2

Additional enviornment details

No response

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have disabled ALL plugins except for WPGraphQL, WPGraphQL For ACF, ACF, etc.

  • Yes
  • My issue is with compatibility with a specific WordPress plugin, and I have listed all my installed plugins (and version info) above.
@jasonbahl jasonbahl self-assigned this Apr 29, 2024
@jasonbahl jasonbahl added the type: bug Issue that causes incorrect or unexpected behavior label Apr 29, 2024
@EldenChris
Copy link

EldenChris commented May 30, 2024

Hi, We had the exact same problem and our fix was to change this :

/src/FieldType/CloneField.php - line 22

$type_name = Utils::format_type_name( $parent_type . ' ' . $field_name );

to

$type_name = Utils::format_type_name( $field_name );

But we don't know what kind of side effects this can bring. But schema is now working and queries are okay even with nested clones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Issue that causes incorrect or unexpected behavior
Projects
None yet
Development

No branches or pull requests

2 participants