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

show_in_graphql option not working properly #153

Closed
2 of 3 tasks
maxthrottleup opened this issue Jan 13, 2024 · 3 comments · Fixed by #155
Closed
2 of 3 tasks

show_in_graphql option not working properly #153

maxthrottleup opened this issue Jan 13, 2024 · 3 comments · Fixed by #155
Assignees
Labels
Type: Bug Something isn't working

Comments

@maxthrottleup
Copy link

maxthrottleup commented Jan 13, 2024

Description

I was trying to cleanup the GraphQL schema and I noticed that the "Show in GraphQL" option was not working for me. It was not removing a specific field from the schema of an active field group. Dug into the code and found an issue with this line of code:

if ( isset( $this->acf_field['show_in_graphql'] ) && false === $this->acf_field['show_in_graphql'] ) {

Not sure the entire details of how PHP interprets a false here but this condition is not working properly for me:
false === $this->acf_field['show_in_graphql']. When the "Show in GraphQL" is toggle false, the attribute 'show_in_graphql' returns a 0 and not false. I fixed this by using the function boolval like this: false === boolval( $this->acf_field['show_in_graphql'] ).

Hope this helps someone, it took me a bit of troubleshooting. Although it might not be a big deal for many people, for me is a big deal because we handle a very large website with tons of data, so it's important to have only the needed one in the Frontend. So deactivating a lot of fields will save tons of build time (we are using Gatsby to build and the queries are by themselves very heavy). I still don't know the entire implication in our build speed improvement but I did not want to hold myself from reporting this problem.

Thanks for all your hard work with these plugins!

Steps to reproduce

  1. I am using WordPress 6.4.2 hosted on Gridpane PHP version 8.1.
  2. Deactivated all plugins except: WPGraphQL, ACF Pro and WPGraphQL for ACF to avoid any possible plugin conflict.
  3. Installed the Twenty Twenty One theme to avoid any possible theme conflict.
  4. Create a new Field Group active in GraphQL.
  5. Create a new field and deactivate it from GraphQL.
  6. Assign the field group to post.
  7. Query the newly created field group using the GraphiQL interface.

Desired behavior: The field group should appear empty because the only field inside the group is deactivated.

Current behavior: The field appears there with the default name.

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

[
    {
        "key": "group_65a1daa08dbc9",
        "title": "Test Group",
        "fields": [
            {
                "key": "field_65a1daa184bc0",
                "label": "Test",
                "name": "upgp_post_test",
                "aria-label": "",
                "type": "text",
                "instructions": "",
                "required": 0,
                "conditional_logic": 0,
                "wrapper": {
                    "width": "",
                    "class": "",
                    "id": ""
                },
                "default_value": "",
                "maxlength": "",
                "placeholder": "",
                "prepend": "",
                "append": "",
                "show_in_graphql": 0
            }
        ],
        "location": [
            [
                {
                    "param": "post_type",
                    "operator": "==",
                    "value": "post"
                }
            ]
        ],
        "menu_order": 0,
        "position": "normal",
        "style": "default",
        "label_placement": "top",
        "instruction_placement": "label",
        "hide_on_screen": "",
        "active": true,
        "description": "",
        "show_in_rest": 0,
        "show_in_graphql": 1,
        "graphql_field_name": "testGroup",
        "map_graphql_types_from_location_rules": 0,
        "graphql_types": ""
    }
]

Additional context

No response

WPGraphQL Version

1.19.0

WPGraphQL For ACF Version

2.0.0

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

6.2.4 Pro

WordPress Version

6.4.2

PHP Version

8.1

Additional enviornment details

Using the hosting of Gridpane. Frontend framework: Gatsby.

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 added the Type: Bug Something isn't working label Jan 13, 2024
@jasonbahl jasonbahl self-assigned this Jan 13, 2024
@jasonbahl
Copy link
Contributor

@maxthrottleup thanks so much for reporting this bug! I'll try and reproduce but from what you shared it clearly looks like a legit bug!

@jasonbahl
Copy link
Contributor

@maxthrottleup I've reproduced this and have a PR to resolve it. #155

Hope to get this released early next week. 🙏🏻

@maxthrottleup
Copy link
Author

@jasonbahl Thank you! I gave a quick look at the PR. Heads up that there are more instances in the code that require the (bool) casting. If you search the entire repo for 'show_in_graphql' you'll find those instances. In my case when I did not address the other cases, sometimes the fields kept appearing in the schema of GraphiQL interface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants