Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

ACF not showing when rule is set to user role #58

Closed
jydmnd opened this issue Sep 9, 2019 · 4 comments
Closed

ACF not showing when rule is set to user role #58

jydmnd opened this issue Sep 9, 2019 · 4 comments

Comments

@jydmnd
Copy link

jydmnd commented Sep 9, 2019

When creating an ACF and setting the rules as:
Show this field group if:
User role is equal to ROLE
The ACF field isn't queryable through the viewer (when authenticated). Here is an example query :

query getViewer {
  viewer {
    id
    username
    name
    userId
    myacf
  }
}

This returns this error :

{
  "errors": [
    {
      "message": "Cannot query field \"myacf\" on type \"User\".",
      "category": "graphql",
      "locations": [
        {
          "line": 7,
          "column": 5
        }
      ]
    }
  ]
}

It works when the rule is set as User role is equal to All, but will show on every user profile, which is not ideal.

@jasonbahl jasonbahl added enhancement New feature or request New Feature labels Sep 9, 2019
@jasonbahl
Copy link
Contributor

Hey @jydmnd!

Thanks for reporting this. This ACF "location rule" is not yet supported.

For context, should anyone come across this:

The GraphQL Schema is independent of any context, such as the user's role, for example. The Schema is representation of what's possible (what can be asked for), and Resolvers take into consideration context (such as the current user, or a specific object being resolved) when resolving the info. . .but in ACF, there is context, because you're loading a specific admin page to interact with the fields.

Mapping contextual rules from ACF Field Groups, such as a specific page or a specific user role, gets tricky, because the GraphQL Schema is the same Schema regardless of resolve context
so adding support for those contextual locations has been tricky to say the least.


This is a location I think we should support.

The way I see it working would be that the fields should be added to the User Type.

This way, the fields can be asked for anytime a user is asked for. During resolution, the user role can be checked, and if the user has the assigned capability, the fields will resolve. If the user doesn't have the assigned capability, the field group will return null.

@jasonbahl
Copy link
Contributor

👋🏻 Sorry for the delay on this, but this has been fixed!

With v0.5.0 (#250) you can use the User Role rule and the field group will be mapped to the Schema.

Below is a screenshot of this rule in action, and the new UI where you can opt-in to manually overriding how it is auto-mapped if needed.

Screen Shot 2021-04-20 at 4 26 25 PM

@jakubszynklarz
Copy link

Hi @jasonbahl,
I have the same problem. The fields I create should be displayed for every user, regardless of their role. Unfortunately, you can't see the "author's site" field group in GrapQL Schema. I am asking for help and information on what I am doing wrong.

WPGraphQL version 1.3.5
WPGraphQL for Advanced Custom Fields version 0.4.1

acf
viewer
user

@jakubszynklarz
Copy link

I updated the plugin to version 0.5.2 and the problem is fixed

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants