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

Latest commit

 

History

History
81 lines (67 loc) · 1.68 KB

user.md

File metadata and controls

81 lines (67 loc) · 1.68 KB

User Field

User fields are added to the WPGraphQL Schema as a field with a User type.

Here, we have a User field named user on the Post Edit screen within the "ACF Docs" Field Group, set with the User "jasonbahl" as the value.

User field in the Edit Post screen

This field can be queried in GraphQL like so:

{
  post(id: "acf-example-test", idType: URI) {
    acfDocs {
      user {
        id
        username
        firstName
        lastName
      }
    }
  }
}

and the response would look like:

{
  "data": {
    "post": {
      "acfDocs": {
        "user": {
          "id": "dXNlcjox",
          "username": "jasonbahl",
          "firstName": "Jason",
          "lastName": "Bahl"
        }
      }
    }
  }
}

If the field is configured to allow multiple selections, it's added to the Schema as a List Of the User type.

Here, we have a User field named user on the Post Edit screen within the "ACF Docs" Field Group, set with the User "jasonbahl" and "WPGraphQL" as the value.

User field in the Edit Post screen

and the response to the same query would look like:

{
  "data": {
    "post": {
      "acfDocs": {
        "user": [
          {
            "id": "dXNlcjox",
            "username": "jasonbahl",
            "firstName": "Jason",
            "lastName": "Bahl"
          },
          {
            "id": "dXNlcjoy",
            "username": "WPGraphQL",
            "firstName": "WP",
            "lastName": "GraphQL"
          }
        ]
      }
    }
  }
}