diff --git a/.env b/.env.dist similarity index 73% rename from .env rename to .env.dist index ec17662..2a32741 100644 --- a/.env +++ b/.env.dist @@ -12,8 +12,8 @@ ADMIN_PATH=/wp-admin TEST_DB_NAME=wpgraphql_acf_tests TEST_DB_HOST=127.0.0.1 -TEST_DB_USER=wordpress -TEST_DB_PASSWORD=wordpress +TEST_DB_USER=root +TEST_DB_PASSWORD=root TEST_WP_TABLE_PREFIX=wp_ SKIP_DB_CREATE=false @@ -29,3 +29,9 @@ TESTS_ENVS=tests/_envs #WPGRAPHQL_VERSION=v1.3.3 SKIP_TESTS_CLEANUP=1 SUITES=wpunit + +WORDPRESS_DB_HOST=${DB_HOST} +WORDPRESS_DB_USER=${DB_USER} +WORDPRESS_DB_PASSWORD=${DB_PASSWORD} +WORDPRESS_DB_NAME=${DB_NAME} +WORDPRESS_TABLE_PREFIX=${WP_TABLE_PREFIX} diff --git a/.github/workflows/upload-schema-artifact.yml b/.github/workflows/upload-schema-artifact.yml new file mode 100644 index 0000000..4f21d62 --- /dev/null +++ b/.github/workflows/upload-schema-artifact.yml @@ -0,0 +1,52 @@ +name: Upload Schema Artifact + +on: + release: + types: [ published ] + +jobs: + run: + runs-on: ubuntu-latest + name: Generate and Upload WPGraphQL for ACF Schema Artifact + services: + mariadb: + image: mariadb + ports: + - 3306:3306 + env: + MYSQL_ROOT_PASSWORD: root + # Ensure docker waits for mariadb to start + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup PHP w/ Composer & WP-CLI + uses: shivammathur/setup-php@v2 + with: + php-version: 7.3 + extensions: mbstring, intl, bcmath, exif, gd, mysqli, opcache, zip, pdo_mysql + coverage: none + tools: composer, wp-cli + + - name: Setup WordPress + run: | + composer run install-test-env + + - name: Install WP CLI for ACF + run: | + wp plugin install https://github.com/hoppinger/advanced-custom-fields-wpcli/archive/refs/heads/master.zip --activate --path="/tmp/wordpress" + - name: Import test Field Group + run: | + wp acf import --json_file="${GITHUB_WORKSPACE}/docs/field-group-examples-export.json" --path="/tmp/wordpress" + - name: Generate the Static Schema + run: | + cd /tmp/wordpress/ + # Output: /tmp/schema.graphql + wp graphql generate-static-schema + - name: Upload schema as release artifact + uses: softprops/action-gh-release@v1 + with: + files: /tmp/schema.graphql + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index e6c29ad..cbb1489 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,6 @@ vendor/composer/installed.json vendor/composer/*/ composer.lock .log +local +wp-content + diff --git a/README.md b/README.md index f231b0f..1ad8cba 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # WPGraphQL for Advanced Custom Fields -WPGraphQL for Advanced Custom Fields automatically exposes your ACF fields to the WPGraphQL Schema. +WPGraphQL for Advanced Custom Fields automatically exposes your ACF fields to the WPGraphQL Schema. - [Install and Activate](#install-and-activate) - [Installing from Github](#install-from-github) @@ -8,51 +8,51 @@ WPGraphQL for Advanced Custom Fields automatically exposes your ACF fields to th - [Dependencies](#dependencies) - [Adding Fields to the WPGraphQL Schema](#adding-fields-to-wpgraphql) - [Supported Fields](#supported-fields) - - [Text](#text-field) - - [Text Area](#text-area-field) - - [Number](#number-field) - - [Range](#range-field) - - [Email](#email-field) - - [URL](#url-field) - - [Password](#password-field) - - [Image](#image-field) - - [File](#file-field) - - [WYSIWYG Editor](#wysiwyg-field) - - [oEmbed](#oembed-field) - - [Gallery](#gallery-field) - - [Select](#select-field) - - [Checkbox](#checkbox-field) - - [Radio Button](#radio-button-field) - - [Button Group](#button-group-field) - - [True/False](#true-false-field) - - [Link](#link-field) - - [Post Object](#post-object-field) - - [Page Link](#page-link-field) - - [Relationship](#relationship-field) - - [Taxonomy](#taxonomy-field) - - [User](#user-field) - - [Google Map](#google-map-field) - - [Date Picker](#date-picker-field) - - [Date/Time Picker](#date-time-picker-field) - - [Time Picker](#time-picker-field) - - [Color Picker](#color-picker-field) - - [Message](#message-field) - - [Accordion](#accordion-field) - - [Tab](#tab-field) - - [Group](#group-field) - - [Repeater](#repeater-field) - - [Flexible Content](#flexible-content-field) - - [Clone](#clone-field) + - [Accordion](./docs/fields/accordion.md) + - [Button Group](./docs/fields/button-group.md) + - [Checkbox](./docs/fields/checkbox.md) + - [Clone](./docs/fields/clone.md) + - [Color Picker](./docs/fields/color-picker.md) + - [Date Picker](./docs/fields/date-picker.md) + - [Date/Time Picker](./docs/fields/date-time-picker.md) + - [Email](./docs/fields/email.md) + - [File](./docs/fields/file.md) + - [Flexible Content](./docs/fields/flexible-content.md) + - [Gallery](./docs/fields/gallery.md) + - [Google Map](./docs/fields/google-map.md) + - [Group](./docs/fields/group.md) + - [Image](./docs/fields/image.md) + - [Link](./docs/fields/link.md) + - [Message](./docs/fields/message.md) + - [Number](./docs/fields/number.md) + - [Oembed](./docs/fields/oembed.md) + - [Page Link](./docs/fields/page-link.md) + - [Password](./docs/fields/password.md) + - [Post Object](./docs/fields/post-object.md) + - [Radio](./docs/fields/radio.md) + - [Range](./docs/fields/range.md) + - [Relationship](./docs/fields/relationship.md) + - [Repeater](./docs/fields/repeater.md) + - [Select](./docs/fields/select.md) + - [Tab](./docs/fields/tab.md) + - [Taxonomy](./docs/fields/taxonomy.md) + - [Text](./docs/fields/text.md) + - [Text Area](./docs/fields/text-area.md) + - [Time Picker](./docs/fields/time-picker.md) + - [True/False](./docs/fields/true-false.md) + - [Url](./docs/fields/url.md) + - [User](./docs/fields/user.md) + - [WYSIWYG](./docs/fields/wysiwyg.md) - [Options Pages](#options-pages) - [Location Rules](#location-rules) ## Install and Activate -WPGraphQL for Advanced Custom Fields is not currently available on the WordPress.org repository, so you must download it from Github, or Composer. +WPGraphQL for Advanced Custom Fields is not currently available on the WordPress.org repository, so you must download it from Github, or Composer. ### Installing From Github -To install the plugin from Github, you can [download the latest release zip file](https://github.com/wp-graphql/wp-graphql-acf/archive/master.zip), upload the Zip file to your WordPress install, and activate the plugin. +To install the plugin from Github, you can [download the latest release zip file](https://github.com/wp-graphql/wp-graphql-acf/archive/master.zip), upload the Zip file to your WordPress install, and activate the plugin. [Click here](https://wordpress.org/support/article/managing-plugins/) to learn more about installing WordPress plugins from a Zip file. @@ -62,19 +62,19 @@ To install the plugin from Github, you can [download the latest release zip file ## Dependencies -In order to use WPGraphQL for Advanced Custom Fields, you must have [WPGraphQL](https://github.com/wp-graphql/wp-graphql) and [Advanced Custom Fields](https://advancedcustomfields.com) (free or pro) installed and activated. +In order to use WPGraphQL for Advanced Custom Fields, you must have [WPGraphQL](https://github.com/wp-graphql/wp-graphql) and [Advanced Custom Fields](https://advancedcustomfields.com) (free or pro) installed and activated. ## Adding Fields to the WPGraphQL Schema **TL;DR:** [Here's a video](https://www.youtube.com/watch?v=rIg4MHc8elg) showing an overview of usage. -Advanced Custom Fields, or ACF for short, enables users to add Field Groups, either using a [Graphical User Interface](https://www.advancedcustomfields.com/resources/creating-a-field-group/), [PHP code](https://www.advancedcustomfields.com/resources/register-fields-via-php/), or [local JSON](https://www.advancedcustomfields.com/resources/local-json/) to various screens in the WordPress dashboard, such as (but not limited to) the Edit Post, Edit User and Edit Term screens. +Advanced Custom Fields, or ACF for short, enables users to add Field Groups, either using a [Graphical User Interface](https://www.advancedcustomfields.com/resources/creating-a-field-group/), [PHP code](https://www.advancedcustomfields.com/resources/register-fields-via-php/), or [local JSON](https://www.advancedcustomfields.com/resources/local-json/) to various screens in the WordPress dashboard, such as (but not limited to) the Edit Post, Edit User and Edit Term screens. -Whatever method you use to register ACF fields to your WordPress site should work with WPGraphQL for Advanced Custom Fields. For the sake of simplicity, the documentation below will _primarily_ use the Graphic User Interface for examples. +Whatever method you use to register ACF fields to your WordPress site should work with WPGraphQL for Advanced Custom Fields. For the sake of simplicity, the documentation below will _primarily_ use the Graphic User Interface for examples. ### Add ACF Fields to the WPGraphQL Schema -The first step in using Advanced Custom Fields with WPGraphQL is to [create an ACF Field Group](https://www.advancedcustomfields.com/resources/creating-a-field-group/). +The first step in using Advanced Custom Fields with WPGraphQL is to [create an ACF Field Group](https://www.advancedcustomfields.com/resources/creating-a-field-group/). By default, field groups are _not_ exposed to WPGraphQL. You must opt-in to expose your ACF Field Groups and fields to the WPGraphQL Schema as some information managed by your ACF fields may not be intended for exposure in a queryable API like WPGraphQL. @@ -96,7 +96,7 @@ When registering ACF Fields in PHP, you need to add `show_in_graphql` and `graph ``` function my_acf_add_local_field_groups() { - + acf_add_local_field_group(array( 'key' => 'group_1', 'title' => 'My Group', @@ -120,7 +120,7 @@ function my_acf_add_local_field_groups() { ), ), )); - + } add_action('acf/init', 'my_acf_add_local_field_groups'); @@ -130,7 +130,7 @@ Each individual field will inherit its GraphQL name from the supplied `name` tag ## Supported Fields -In order to document interacting with the fields in GraphQL, an example field group has been created with one field of each type. +In order to document interacting with the fields in GraphQL, an example field group has been created with one field of each type. To replicate the same field group documented here you can download the [example field group](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/field-group-examples-export.json) and [import it](https://support.advancedcustomfields.com/forums/topic/importing-exporting-acf-settings/) into your environment. @@ -138,1565 +138,6 @@ For the sake of documentation, this example field group has the [location rule]( ![Location rule set to Post Type is equal to Post](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/location-rule-post-type-post.png?raw=true) -### Text Field - -Text fields are added to the WPGraphQL Schema as a field with the Type `String`. - -Text fields can be queried and a String will be returned. - -Here, we have a Text field named `text` on the Post Edit screen within the "ACF Docs" Field Group. - -![Text field in the Edit Post screen](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/text-field-input.png?raw=true) - -This field can be Queried in GraphQL like so: - -```graphql -{ - post( id: "acf-example-test" idType: URI ) { - acfDocs { - text - } - } -} -``` - -and the results of the query would be: - -```json -{ - "data": { - "post": { - "acfDocs": { - "text": "Text Value" - } - } - } -} -``` - -### Text Area Field - -Text Area fields are added to the WPGraphQL Schema as a field with the Type `String`. - -Text Area fields can be queried and a String will be returned. - -Here, we have a Text Area field named `text_area` on the Post Edit screen within the "ACF Docs" Field Group. - -![Text Area field in the Edit Post screen](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/text-area-field-input.png?raw=true) - -This field can be Queried in GraphQL like so: - -```graphql -{ - post( id: "acf-example-test" idType: URI ) { - acfDocs { - textArea - } - } -} -``` - -and the results of the query would be: - -```json -{ - "data": { - "post": { - "acfDocs": { - "textArea": "Text value" - } - } - } -} -``` - -### Number Field - -Number fields are added to the WPGraphQL Schema as a field with the Type `Float`. - -Number fields can be queried and a Float will be returned. - -Here, we have a Number field named `number` on the Post Edit screen within the "ACF Docs" Field Group. - -![Number field in the Edit Post screen](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/number-field-input.png?raw=true) - -This field can be Queried in GraphQL like so: - -```graphql -{ - post( id: "acf-example-test" idType: URI ) { - acfDocs { - number - } - } -} -``` - -and the results of the query would be: - -```json -{ - "data": { - "post": { - "acfDocs": { - "number": 5 - } - } - } -} -``` - -### Range Field - -Range fields are added to the WPGraphQL Schema as a field with the Type `Float`. - -Range fields can be queried and a Float will be returned. - -Here, we have a Range field named `range` on the Post Edit screen within the "ACF Docs" Field Group. - -![Range field in the Edit Post screen](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/range-field-input.png?raw=true) - -This field can be Queried in GraphQL like so: - -```graphql -{ - post( id: "acf-example-test" idType: URI ) { - acfDocs { - range - } - } -} -``` - -and the results of the query would be: - -```json -{ - "data": { - "post": { - "acfDocs": { - "range": 5 - } - } - } -} -``` - -### Email Field - -Email fields are added to the WPGraphQL Schema as a field with the Type `String`. - -Email fields can be queried and a String will be returned. - -Here, we have an Email field named `email` on the Post Edit screen within the "ACF Docs" Field Group. - -![Email field in the Edit Post screen](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/email-field-input.png?raw=true) - -This field can be Queried in GraphQL like so: - -```graphql -{ - post( id: "acf-example-test" idType: URI ) { - acfDocs { - email - } - } -} -``` - -and the results of the query would be: - -```json -{ - "data": { - "post": { - "acfDocs": { - "email": "test@example.com" - } - } - } -} -``` - -### URL Field - -Url fields are added to the WPGraphQL Schema as a field with the Type `String`. - -Url fields can be queried and a String will be returned. - -Here, we have a URL field named `url` on the Post Edit screen within the "ACF Docs" Field Group. - -![Url field in the Edit Post screen](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/url-field-input.png?raw=true) - -This field can be Queried in GraphQL like so: - -```graphql -{ - post( id: "acf-example-test" idType: URI ) { - acfDocs { - url - } - } -} -``` - -and the results of the query would be: - -```json -{ - "data": { - "post": { - "acfDocs": { - "url": "https://wpgraphql.com" - } - } - } -} -``` - -### Password Field - -Password fields are added to the WPGraphQL Schema as a field with the Type `String`. - -Password fields can be queried and a String will be returned. - -Here, we have a Password field named `password` on the Post Edit screen within the "ACF Docs" Field Group. - -![Password field in the Edit Post screen](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/password-field-input.png?raw=true) - -This field can be Queried in GraphQL like so: - -```graphql -{ - post( id: "acf-example-test" idType: URI ) { - acfDocs { - password - } - } -} -``` - -and the results of the query would be: - -```json -{ - "data": { - "post": { - "acfDocs": { - "password": "123456" - } - } - } -} -``` - -### Image Field - -Image fields are added to the WPGraphQL Schema as a field with the Type `MediaItem`. - -Image fields can be queried and a MediaItem will be returned. - -The `MediaItem` type is an Object type that has it's own fields that can be selected. So, instead of _just_ getting the Image ID returned and having to ask for the MediaItem object in a follow-up request, we can ask for fields available on the MediaItem Type. For this example, we ask for the `id` and `sourceUrl`. - -Here, we have an Image field named `image` on the Post Edit screen within the "ACF Docs" Field Group. - -![Image field in the Edit Post screen](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/image-field-input.png?raw=true) - -This field can be Queried in GraphQL like so: - -```graphql -{ - post( id: "acf-example-test" idType: URI ) { - acfDocs { - image { - id - sourceUrl(size: MEDIUM) - } - } - } -} -``` - -And the results of the query would be: - -```json -{ - "data": { - "post": { - "acfDocs": { - "image": { - "id": "YXR0YWNobWVudDozMjM=", - "sourceUrl": "http://wpgraphql.local/wp-content/uploads/2020/03/babe-ruth-300x169.jpg" - } - } - } - } -} -``` - -### File Field - -File fields are added to the WPGraphQL Schema as a field with the Type `MediaItem`. - -File fields can be queried and a MediaItem will be returned. - -The `MediaItem` type is an Object type that has it's own fields that can be selected. So, instead of _just_ getting the File ID returned and having to ask for the MediaItem object in a follow-up request, we can ask for fields available on the MediaItem Type. For this example, we ask for the `id` and `mediaItemUrl`. - -Here, we have a File field named `file` on the Post Edit screen within the "ACF Docs" Field Group. - -![File field in the Edit Post screen](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/file-field-input.png?raw=true) - -This field can be Queried in GraphQL like so: - -```graphql -{ - post(id: "acf-example-test", idType: URI) { - acfDocs { - file { - id - mediaItemUrl - } - } - } -} -``` - -And the results of the query would be: - -```json -{ - "data": { - "post": { - "acfDocs": { - "file": { - "id": "YXR0YWNobWVudDozMjQ=", - "mediaItemUrl": "http://acf2.local/wp-content/uploads/2020/03/little-ceasars-receipt-01282020.pdf" - } - } - } - } -} -``` - -### WYSIWYG Editor Field - -WYSIWYG fields are added to the WPGraphQL Schema as a field with the Type `String`. - -WYSIWYG fields can be queried and a String will be returned. - -Here, we have a WYSIWYG field named `wysiwyg` on the Post Edit screen within the "ACF Docs" Field Group. - -![WYSIWYG field in the Edit Post screen](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/wysiwyg-field-input.png?raw=true) - -This field can be Queried in GraphQL like so: - -```graphql -{ - post( id: "acf-example-test" idType: URI ) { - acfDocs { - wysiwyg - } - } -} -``` - -and the results of the query would be: - -```json -{ - "data": { - "post": { - "acfDocs": { - "wysiwyg": "
Some content in a WYSIWYG field
\n" - } - } - } -} -``` - -### oEmbed Field - -oEmbed fields are added to the WPGraphQL Schema as a field with the Type `String`. - -oEmbed fields can be queried and a String will be returned. - -Here, we have a oEmbed field named `oembed` on the Post Edit screen within the "ACF Docs" Field Group. - -![oEmbed field in the Edit Post screen](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/oEmbed-field-input.png?raw=true) - -This field can be Queried in GraphQL like so: - -```graphql -{ - post(id: "acf-example-test", idType: URI) { - acfDocs { - oembed - } - } -} -``` - -and the results of the query would be: - -```json -{ - "data": { - "post": { - "acfDocs": { - "oembed": "https://www.youtube.com/watch?v=ZEytXfaWwcc" - } - } - } -} -``` - -### Gallery Field - -Gallery fields are added to the WPGraphQL Schema as a field with the Type of `['list_of' => 'MediaItem']`. - -Gallery fields can be queried and a list of MediaItem types will be returned. - -Since the type is a list, we can expect an array to be returned. And since the Type within the list is `MediaItem`, we can ask for fields we want returned for each `MediaItem` in the list. In this case, let's say we want to ask for the `id` of each image and the `sourceUrl`, (size large). - -Here, we have a Gallery field named `gallery` on the Post Edit screen within the "ACF Docs" Field Group. - -![Gallery field in the Edit Post screen](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/gallery-field-input.png?raw=true) - -This field can be Queried in GraphQL like so: - -```graphql -{ - post(id: "acf-example-test", idType: URI) { - acfDocs { - gallery { - id - sourceUrl(size: LARGE) - } - } - } -} -``` - -and the results of the query would be: - -```json -{ - "data": { - "post": { - "acfDocs": { - "gallery": [ - { - "id": "YXR0YWNobWVudDoyNTY=", - "sourceUrl": "http://wpgraphql.local/wp-content/uploads/2020/02/babe-ruth.jpg" - }, - { - "id": "YXR0YWNobWVudDoyNTU=", - "sourceUrl": "http://wpgraphql.local/wp-content/uploads/2020/02/babe-ruth-baseball-986x1024.jpg" - } - ] - } - } - } -} -``` - -### Select Field - -Select fields (when configured to _not_ allow mutliple selections) are added to the WPGraphQL Schema as a field with the Type `String`. - -Select fields, without multiple selections allowed, can be queried and a String will be returned. - -Here, we have a Select field named `select` on the Post Edit screen within the "ACF Docs" Field Group, and "Choice 1" is selected. - -![Select field in the Edit Post screen](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/select-field-input.png?raw=true) - -This field can be Queried in GraphQL like so: - -```graphql -{ - post(id: "acf-example-test", idType: URI) { - acfDocs { - select - } - } -} -``` - -and the results of the query would be: - -```json -{ - "data": { - "post": { - "acfDocs": { - "select": "choice_1" - } - } - } -} -``` - -### Checkbox Field - -Checkbox fields are added to the WPGraphQL Schema as a field with the Type `[ 'list_of' => 'String' ]`. - -Checkbox fields can be queried and a list (array) of Strings (the selected values) will be returned. - -Here, we have a Checkbox field named `checkbox` on the Post Edit screen within the "ACF Docs" Field Group, and "Choice 1" is selected. - -![Checkbox field in the Edit Post screen](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/checkbox-field-input.png?raw=true) - -This field can be Queried in GraphQL like so: - -```graphql -{ - post(id: "acf-example-test", idType: URI) { - acfDocs { - checkbox - } - } -} -``` - -and the results of the query would be: - -```json -{ - "data": { - "post": { - "acfDocs": { - "checkbox": [ - "choice_1" - ] - } - } - } -} -``` - -### Radio Button Field - -Radio Button fields are added to the WPGraphQL Schema as a field with the Type `String`. - -Radio Button fields can be queried and a String will be returned. - -Here, we have a Radio Button field named `radio_button` on the Post Edit screen within the "ACF Docs" Field Group, and "Choice 2" is selected. - -![Radio Button field in the Edit Post screen](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/radio-button-field-input.png?raw=true) - -This field can be Queried in GraphQL like so: - -```graphql -{ - post(id: "acf-example-test", idType: URI) { - acfDocs { - radioButton - } - } -} -``` - -and the results of the query would be: - -```json -{ - "data": { - "post": { - "acfDocs": { - "radioButton": "choice_2" - } - } - } -} -``` - -### Button Group Field - -Button Group fields are added to the WPGraphQL Schema as a field with the Type `String`. - -Button Group fields can be queried and a String will be returned. - -Here, we have a Button Group field named `button_group` on the Post Edit screen within the "ACF Docs" Field Group, and "Choice 2" is selected. - -![Button Group field in the Edit Post screen](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/button-group-field-input.png?raw=true) - -This field can be Queried in GraphQL like so: - -```graphql -{ - post(id: "acf-example-test", idType: URI) { - acfDocs { - buttonGroup - } - } -} -``` - -and the results of the query would be: - -```json -{ - "data": { - "post": { - "acfDocs": { - "buttonGroup": "choice_2" - } - } - } -} -``` - -### True/False Field - -True/False fields are added to the WPGraphQL Schema as a field with the Type `Boolean`. - -True/False fields can be queried and a Boolean will be returned. - -Here, we have a True/False field named `true_false` on the Post Edit screen within the "ACF Docs" Field Group, and "true" is selected. - -![True/False field in the Edit Post screen](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/true-false-field-input.png?raw=true) - -This field can be Queried in GraphQL like so: - -```graphql -{ - post(id: "acf-example-test", idType: URI) { - acfDocs { - trueFalse - } - } -} -``` - -and the results of the query would be: - -```json -{ - "data": { - "post": { - "acfDocs": { - "trueFalse": true - } - } - } -} -``` - -### Link Field - -Link fields are added to the WPGraphQL Schema as a field with the Type `ACF_Link`. - -Link fields can be queried and a `ACF_Link` will be returned. The ACF Link is an object with fields that can be selected. - -The available fields on the `ACF_Link` Type are: - -- **target** (String): The target of the link -- **title** (String): The target of the link -- **url** (String): The url of the link - -Here, we have a Link field named `link` on the Post Edit screen within the "ACF Docs" Field Group. - -![Link field in the Edit Post screen](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/link-field-input.png?raw=true) - -This field can be Queried in GraphQL like so: - -```graphql -{ - post(id: "acf-example-test", idType: URI) { - acfDocs { - link { - target - title - url - } - } - } -} -``` - -and the results of the query would be: - -```json -{ - "data": { - "post": { - "acfDocs": { - "link": { - "target": "", - "title": "Hello world!", - "url": "http://acf2.local/hello-world/" - } - } - } - } -} -``` - -### Post Object Field - -Post Object fields are added to the WPGraphQL Schema as a field with a [Union](https://graphql.org/learn/schema/#union-types) of Possible Types the field is configured to allow. - -If the field is configured to allow multiple selections, it will be added to the Schema as a List Of the Union Type. - -Since Post Object fields can be configured to be limited to certain Post Types, the Union will represent those Types. - -For example, if the Post Object field is configured to allow Posts of the `post` and `page` types to be selected: - -![Post Object field Post Type Config](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/post-object-field-post-type-config.png?raw=true) - -Then the Union type for the field will allow `Post` and `Page` types to be returned, as seen in the Schema via GraphiQL: - -![Post Object field Union Possible Types](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/post-object-field-possible-types.png?raw=true) - -Here, we have a Post Object field named `post_object` on the Post Edit screen within the "ACF Docs" Field Group, configured with the Post "Hello World!". - -![Post Object field in the Edit Post screen](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/post-object-field-input-post.png?raw=true) - -As a GraphQL consumer, we don't know in advance if the value is going to be a Page or a Post. - -So we can specify, via GraphQL fragment, what fields we want if the object is a Post, or if it is a Page. - -This field can be Queried in GraphQL like so: - -```graphql -{ - post(id: "acf-example-test", idType: URI) { - acfDocs { - postObject { - __typename - ... on Post { - id - title - date - } - ... on Page { - id - title - } - } - } - } -} -``` - -and the results of the query would be: - -```json -{ - "data": { - "post": { - "acfDocs": { - "postObject": { - "__typename": "Post", - "id": "cG9zdDox", - "title": "Hello world!", - "date": "2020-02-20T23:12:21" - } - } - } - } -} -``` - -If the input of the field was saved as a Page, instead of a Post, like so: - -![Post Object field in the Edit Post screen](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/post-object-field-input-page.png?raw=true) - -Then the same query above, would return the following results: - -```json -{ - "data": { - "post": { - "acfDocs": { - "postObject": { - "__typename": "Page", - "id": "cGFnZToy", - "title": "Sample Page" - } - } - } - } -} -``` - -Now, if the field were configured to allow multiple values, the field would be added to the Schema as a `listOf`, returning an Array of the Union. - -If the field were set with a value of one Page, and one Post, like so: - -![Post Object field in the Edit Post screen](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/post-object-field-input-multi.png?raw=true) - -Then the results of the same query as above would be: - -```json -{ - "data": { - "post": { - "acfDocs": { - "postObject": [ - { - "__typename": "Page", - "id": "cGFnZToy", - "title": "Sample Page" - }, - { - "__typename": "Post", - "id": "cG9zdDox", - "title": "Hello world!", - "date": "2020-02-20T23:12:21" - } - ] - } - } - } -} -``` - -### Page Link Field - -Page Link fields are added to the WPGraphQL Schema as a field with a [Union](https://graphql.org/learn/schema/#union-types) of Possible Types the field is configured to allow. - -Since Page Link fields can be configured to be limited to certain Post Types, the Union will represent those Types. - -For example, if the Post Object field is configured to allow Posts of the `post` and `page` types to be selected: - -![Page Link field Post Type Config](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/page-link-field-post-type-config.png?raw=true) - -Then the Union type for the field will allow `Post` and `Page` types to be returned, as seen in the Schema via GraphiQL: - -![Page Link field Union Possible Types](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/page-link-field-possible-types.png?raw=true) - -Here, we have a Page Link field named `page_link` on the Post Edit screen within the "ACF Docs" Field Group, and the value is set to the "Sample Page" page. - -![Page Link field in the Edit Post screen](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/page-link-field-input.png?raw=true) - -This field can be Queried in GraphQL like so: - -```graphql -{ - post(id: "acf-example-test", idType: URI) { - acfDocs { - pageLink { - __typename - ... on Post { - id - title - date - } - ... on Page { - id - title - } - } - } - } -} -``` - -and the results of the query would be: - -```json -{ - "data": { - "post": { - "acfDocs": { - "pageLink": { - "__typename": "Page", - "id": "cGFnZToy", - "title": "Sample Page" - } - } - } - } -} -``` - -Here, we set the value to the "Hello World" Post: - -![Page Link field in the Edit Post screen](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/page-link-field-input-2.png?raw=true) - -And the results of the same query are now: - -```json -{ - "data": { - "post": { - "acfDocs": { - "pageLink": { - "__typename": "Post", - "id": "cG9zdDox", - "title": "Hello world!", - "date": "2020-02-20T23:12:21" - } - } - } - } -} -``` - -### Relationship Field - -Relationship fields are added to the WPGraphQL Schema as a field with a [Union](https://graphql.org/learn/schema/#union-types) of Possible Types the field is configured to allow. - -Since Relationship fields can be configured to be limited to certain Post Types, the Union will represent those Types. - -For example, if the Post Object field is configured to allow Posts of the `post` and `page` types to be selected: - -![Relationship field Post Type Config](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/relationship-field-post-type-config.png?raw=true) - -Then the Union type for the field will allow `Post` and `Page` types to be returned, as seen in the Schema via GraphiQL: - -![Relationship field Union Possible Types](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/relationship-field-possible-types.png?raw=true) - -Here, we have a Relationship field named `relationship` on the Post Edit screen within the "ACF Docs" Field Group, and the value is set to "Hello World!" post, and the "Sample Page" page. - -![Relationship field in the Edit Post screen](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/relationship-field-input.png?raw=true) - -This field can be Queried in GraphQL like so: - -```graphql -{ - post(id: "acf-example-test", idType: URI) { - acfDocs { - relationship { - __typename - ... on Post { - id - title - date - } - ... on Page { - id - title - } - } - } - } -} -``` - -and the results of the query would be: - -```json -{ - "data": { - "post": { - "acfDocs": { - "relationship": [ - { - "__typename": "Post", - "id": "cG9zdDox", - "title": "Hello world!", - "date": "2020-02-20T23:12:21" - }, - { - "__typename": "Page", - "id": "cGFnZToy", - "title": "Sample Page" - } - ] - } - } - } -} -``` - -### Taxonomy Field - -The Taxonomy field is added to the GraphQL Schema as a List Of the Taxonomy Type. - -For example, if the field is configured to the "Category" taxonomy, then the field in the Schema will be a List of the Category type. - -![Taxonomy field Taxonomy Config](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/taxonomy-field-taxonomy-config.png?raw=true) - -Here, we have a Taxonomy field named `taxonomy` on the Post Edit screen within the "ACF Docs" Field Group, configured with the Category "Test Category". - -![Taxonomy field in the Edit Post screen](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/taxonomy-field-input.png?raw=true) - -This field can be queried like so: - -```graphql -{ - post(id: "acf-example-test", idType: URI) { - acfDocs { - taxonomy { - __typename - id - name - } - } - } -} -``` - -and the results of the query would be: - -```json -{ - "data": { - "post": { - "acfDocs": { - "taxonomy": [ - { - "__typename": "Category", - "id": "Y2F0ZWdvcnk6Mg==", - "name": "Test Category" - } - ] - } - } - } -} -``` - -### 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](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/user-field-input.png?raw=true) - -This field can be queried in GraphQL like so: - -```graphql -{ - post(id: "acf-example-test", idType: URI) { - acfDocs { - user { - id - username - firstName - lastName - } - } - } -} -``` - -and the response would look like: - -```json -{ - "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](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/user-field-input-multiple.png?raw=true) - -and the response to the same query would look like: - -```json -{ - "data": { - "post": { - "acfDocs": { - "user": [ - { - "id": "dXNlcjox", - "username": "jasonbahl", - "firstName": "Jason", - "lastName": "Bahl" - }, - { - "id": "dXNlcjoy", - "username": "WPGraphQL", - "firstName": "WP", - "lastName": "GraphQL" - } - ] - } - } - } -} -``` - -### Google Map Field - -Google Map fields are added to the WPGraphQL Schema as the `ACF_GoogleMap` Type. - -The `ACF_GoogleMap` Type has fields that expose location data. The available fields are: - -- **city** (String): The city associated with the location -- **country** (String): The country associated with the location -- **countryShort** (String): The country abbreviation associated with the location -- **latitude** (String): The latitude associated with the location -- **longitude** (String): The longitude associated with the location -- **placeId** (String): Place IDs uniquely identify a place in the Google Places database and on Google Maps. -- **postCode** (String): The post code associated with the location -- **state** (String): The state associated with the location -- **stateShort** (String): The state abbreviation associated with the location -- **streetAddress** (String): The street address associated with the location -- **streetName** (String): The street name associated with the location -- **streetNumber** (String): The street number associated with the location -- **zoom** (String): The zoom defined with the location - -Here, we have a Google Map field named `google_map` on the Post Edit screen within the "ACF Docs" Field Group, set with the Address "1 Infinite Loop, Cupertino, CA 95014, USA" as the value. - -![Google Map field in the Edit Post screen](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/map-field-input.png?raw=true) - -This field can be queried in GraphQL like so: - -```graphql -{ - post(id: "acf-example-test", idType: URI) { - acfDocs { - googleMap { - streetAddress - streetNumber - streetName - city - state - postCode - countryShort - } - } - } -} -``` - -and the response would look like: - -```json -{ - "data": { - "post": { - "acfDocs": { - "googleMap": { - "streetAddress": "1 Infinite Loop, Cupertino, CA 95014, USA", - "streetNumber": "1", - "streetName": "Infinite Loop", - "city": "Cupertino", - "state": "California", - "postCode": "95014", - "placeId": "ChIJHTRqF7e1j4ARzZ_Fv8VA4Eo", - "countryShort": "US" - } - } - } - } -} -``` - -### Date Picker Field - -The Date Picker field is added to the WPGraphQL Schema as field with the Type `String`. - -Date Picker fields can be queried and a String will be returned. - -Here, we have a Date Picker field named `date_picker` on the Post Edit screen within the "ACF Docs" Field Group, and "13/03/2020" is the date set. - -![Date Picker field in the Edit Post screen](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/date-picker-field-input.png?raw=true) - -This field can be queried in GraphQL like so: - -```graphql -{ - post(id: "acf-example-test", idType: URI) { - acfDocs { - datePicker - } - } -} -``` - -and the result of the query would be: - -```json -{ - "data": { - "post": { - "acfDocs": { - "datePicker": "13/03/2020" - } - } - } -} -``` - -### Date/Time Picker Field - -The Date/Time Picker field is added to the WPGraphQL Schema as field with the Type `String`. - -Date/Time Picker fields can be queried and a String will be returned. - -Here, we have a Date/Time Picker field named `date_time_picker` on the Post Edit screen within the "ACF Docs" Field Group, and "20/03/2020 8:15 am" is the value. - -![Date Picker field in the Edit Post screen](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/date-time-picker-field-input.png?raw=true) - -This field can be queried in GraphQL like so: - -```graphql -{ - post(id: "acf-example-test", idType: URI) { - acfDocs { - dateTimePicker - } - } -} -``` - -and the result of the query would be: - -```json -{ - "data": { - "post": { - "acfDocs": { - "dateTimePicker": "20/03/2020 8:15 am" - } - } - } -} -``` - -### Time Picker Field - -The Time Picker field is added to the WPGraphQL Schema as field with the Type `String`. - -Time Picker fields can be queried and a String will be returned. - -Here, we have a Time Picker field named `time_picker` on the Post Edit screen within the "ACF Docs" Field Group, and "12:30 am" is the value. - -![Time Picker field in the Edit Post screen](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/time-picker-field-input.png?raw=true) - -This field can be queried in GraphQL like so: - -```graphql -{ - post(id: "acf-example-test", idType: URI) { - acfDocs { - timePicker - } - } -} -``` - -and the result of the query would be: - -```json -{ - "data": { - "post": { - "acfDocs": { - "timePicker": "12:30 am" - } - } - } -} -``` - -### Color Picker Field - -The Color Picker field is added to the WPGraphQL Schema as field with the Type `String`. - -Color Picker fields can be queried and a String will be returned. - -Here, we have a Color Picker field named `color_picker` on the Post Edit screen within the "ACF Docs" Field Group, and "#dd3333" is the value. - -![Color Picker field in the Edit Post screen](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/color-picker-field-input.png?raw=true) - -This field can be queried in GraphQL like so: - -```graphql -{ - post(id: "acf-example-test", idType: URI) { - acfDocs { - colorPicker - } - } -} -``` - -and the result of the query would be: - -```json -{ - "data": { - "post": { - "acfDocs": { - "colorPicker": "12:30 am" - } - } - } -} -``` - -### Message Field - -Message fields are not currently supported. - -### Accordion Field - -Accordion Fields are not currently supported. - -### Tab Field - -Tab fields are not currently supported. - -### Group Field - -Group Fields are added to the WPGraphQL Schema as fields resolving to an Object Type named after the Group. - -Here, we have a Group field named `group` on the Post Edit screen within the "ACF Docs" Field Group. Within the "group" field, we have a Text Field named `text_field_in_group` and a Text Area field named `text_area_field_in_group` - -![Group field in the Edit Post screen](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/group-field-input.png?raw=true) - -We can query the fields within the group like so: - -```graphql -{ - post(id: "acf-example-test", idType: URI) { - acfDocs { - group { - textFieldInGroup - textAreaFieldInGroup - } - } - } -} -``` - -And the results of the query would be: - -```json -{ - "data": { - "post": { - "acfDocs": { - "group": { - "textFieldInGroup": "Text value, in group", - "textAreaFieldInGroup": "Text are value, in group" - } - } - } - } -} -``` - -### Repeater Field - -Repeater Fields are added to the Schema as a List Of the Type of group that makes up the fields. - -For example, we've created a Repeater Field that has a Text Field named `text_field_in_repeater` and an Image Field named `image_field_in_repeater`. - -Here, the Repeater Field is populated with 2 rows: -- Row 1: - - Text Field: Text Value 1 - - Image: 256 -- Row 2: - - Text Field: Text Value 2 - - Image: 255 - -![Repeater field in the Edit Post screen](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/repeater-field-input.png?raw=true) - -This field can be queried in GraphQL like so: - -```graphql -{ - post(id: "acf-example-test", idType: URI) { - acfDocs { - repeater { - textFieldInRepeater - imageFieldInRepeater { - databaseId - id - sourceUrl - } - } - } - } -} -``` - -and the results of the query would be: - -```json -{ - "data": { - "post": { - "acfDocs": { - "repeater": [ - { - "textFieldInRepeater": "Text Value 1", - "imageFieldInRepeater": { - "id": "YXR0YWNobWVudDoyNTY=", - "sourceUrl": "http://acf2.local/wp-content/uploads/2020/02/babe-ruth.jpg" - } - }, - { - "textFieldInRepeater": "Text Value 2", - "imageFieldInRepeater": { - "id": "YXR0YWNobWVudDoyNTU=", - "sourceUrl": "http://acf2.local/wp-content/uploads/2020/02/babe-ruth-baseball-scaled.jpg" - } - } - ] - } - } - } -} -``` - -### Flexible Content Field - -The Flexible Content is a powerful ACF field that allows for groups of fields to be organized into "Layouts". - -These Layouts can be made up of other types of fields, and can be added and arranged in any order. - -Flexible Content Fields are added to the WPGraphQL Schema as a List Of [Unions](https://graphql.org/learn/schema/#union-types). - -The Union for a Flex Field is made up of each Layout in the Flex Field as the possible Types. - -In our example, we've created a Flex Field with 3 layouts named "Layout One", "Layout Two" and "Layout Three". In the Schema, we can see the Flex Field Union's Possible Types are these 3 layouts. - -![Flex Fields Schema Union Possible Types](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/flex-field-union-possible-types.png?raw=true) - -Each of these Layout types will contain the fields defined for the layout and can be queried like fields in any other Group. - -Here's an example of a Flex Field named `flexible_content`, with 3 layouts: - -- Layout One - - Text field named "text" - - Text field named "another_text_field" -- Layout Two - - Image field named "image" -- Layout Three - - Gallery field named "gallery" - -Above are the possible layouts and their fields. These layouts can be added and arranged in any order. While we, as a GraphQL consumer, don't know ahead of time what order they will be in, we _do_ know what the possibilities are. - -Here's an example of a Flex Field named `flexible_content` with the values saved as "Layout One", "Layout Two" and "Layout Three", in that order, all populated with their respective fields. - -![Flex field in the Edit Post screen](https://github.com/wp-graphql/wp-graphql-acf/blob/master/docs/img/flex-field-input.png?raw=true) - -We can query this field like so: - -```graphql -{ - post(id: "acf-example-test", idType: URI) { - acfDocs { - flexibleContent { - __typename - ... on Post_Acfdocs_FlexibleContent_LayoutOne { - text - anotherTextField - } - ... on Post_Acfdocs_FlexibleContent_LayoutTwo { - image { - id - sourceUrl(size: MEDIUM) - } - } - ... on Post_Acfdocs_FlexibleContent_LayoutThree { - gallery { - id - sourceUrl(size: MEDIUM) - } - } - } - } - } -} -``` - -and the results of the query would be: - -```json -{ - "data": { - "post": { - "acfDocs": { - "flexibleContent": [ - { - "__typename": "Post_Acfdocs_FlexibleContent_LayoutOne", - "text": "Text Value One", - "anotherTextField": "Another Text Value" - }, - { - "__typename": "Post_Acfdocs_FlexibleContent_LayoutTwo", - "image": { - "id": "YXR0YWNobWVudDoyNTY=", - "sourceUrl": "http://acf2.local/wp-content/uploads/2020/02/babe-ruth-300x169.jpg" - } - }, - { - "__typename": "Post_Acfdocs_FlexibleContent_LayoutThree", - "gallery": [ - { - "id": "YXR0YWNobWVudDoyNTY=", - "sourceUrl": "http://acf2.local/wp-content/uploads/2020/02/babe-ruth-300x169.jpg" - }, - { - "id": "YXR0YWNobWVudDoyNTU=", - "sourceUrl": "http://acf2.local/wp-content/uploads/2020/02/babe-ruth-baseball-289x300.jpg" - } - ] - } - ] - } - } - } -} -``` - -If we were to re-arrange the layouts, so that the order was "Layout Three", "Layout One", "Layout Two", the results of the query would be: - -```json -"data": { - "post": { - "acfDocs": { - "flexibleContent": [ - { - "__typename": "Post_Acfdocs_FlexibleContent_LayoutThree", - "gallery": [ - { - "id": "YXR0YWNobWVudDoyNTY=", - "sourceUrl": "http://acf2.local/wp-content/uploads/2020/02/babe-ruth-300x169.jpg" - }, - { - "id": "YXR0YWNobWVudDoyNTU=", - "sourceUrl": "http://acf2.local/wp-content/uploads/2020/02/babe-ruth-baseball-289x300.jpg" - } - ] - } - { - "__typename": "Post_Acfdocs_FlexibleContent_LayoutOne", - "text": "Text Value One", - "anotherTextField": "Another Text Value" - }, - { - "__typename": "Post_Acfdocs_FlexibleContent_LayoutTwo", - "image": { - "id": "YXR0YWNobWVudDoyNTY=", - "sourceUrl": "http://acf2.local/wp-content/uploads/2020/02/babe-ruth-300x169.jpg" - } - }, - ] - } - } - } -``` - -### Clone Field - -The clone field is not fully supported (yet). We plan to support it in the future. - ## Options Pages **Reference**: https://www.advancedcustomfields.com/add-ons/options-page/ @@ -1738,11 +179,11 @@ Alternatively, it's you can check the Fields API Reference to learn about exposi ## Location Rules -Advanced Custom Fields field groups are added to the WordPress dashboard by being assigned "Location Rules". +Advanced Custom Fields field groups are added to the WordPress dashboard by being assigned "Location Rules". -WPGraphQL for Advanced Custom Fields uses the Location Rules to determine where in the GraphQL Schema the field groups/fields should be added to the Schema. +WPGraphQL for Advanced Custom Fields uses the Location Rules to determine where in the GraphQL Schema the field groups/fields should be added to the Schema. -For example, if a Field Group were assigned to "Post Type is equal to Post", then the field group would show in the WPGraphQL Schema on the `Post` type, allowing you to query for ACF fields of the Post, anywhere you can interact with the `Post` type in the Schema. +For example, if a Field Group were assigned to "Post Type is equal to Post", then the field group would show in the WPGraphQL Schema on the `Post` type, allowing you to query for ACF fields of the Post, anywhere you can interact with the `Post` type in the Schema. ### Supported Locations @@ -1750,10 +191,10 @@ For example, if a Field Group were assigned to "Post Type is equal to Post", the ### Why aren't all location rules supported? -You might notice that some location rules don't add fields to the Schema. This is because some location rules are based on context that doesn't exist when the GraphQL Schema is generated. +You might notice that some location rules don't add fields to the Schema. This is because some location rules are based on context that doesn't exist when the GraphQL Schema is generated. -For example, if you have a location rule to show a field group only on a specific page, how would that be exposed the the Schema? There's no Type in the Schema for just one specific page. +For example, if you have a location rule to show a field group only on a specific page, how would that be exposed the the Schema? There's no Type in the Schema for just one specific page. -If you're not seeing a field group in the Schema, look at the location rules, and think about _how_ the field group would be added to a Schema that isn't aware of context like which admin page you're on, what category a Post is assigned to, etc. +If you're not seeing a field group in the Schema, look at the location rules, and think about _how_ the field group would be added to a Schema that isn't aware of context like which admin page you're on, what category a Post is assigned to, etc. If you have ideas on how these specific contextual rules should be handled in WPGraphQL, submit an issue so we can consider how to best support it! diff --git a/bin/install-test-env.sh b/bin/install-test-env.sh index 66890d1..009a1c0 100644 --- a/bin/install-test-env.sh +++ b/bin/install-test-env.sh @@ -1,10 +1,17 @@ #!/usr/bin/env bash +if [ ! -f .env ]; then + echo "No .env file was detected. .env.dist has been copied to .env" + echo "Open the .env file and enter values to match your local environment" + cp ./.env.dist ./.env + export $(cat .env | xargs) +fi + source .env print_usage_instruction() { echo "Ensure that .env file exist in project root directory exists." - echo "And run the following 'composer install-wp-tests' in the project root directory" + echo "And run the following 'composer build-test' in the project root directory" exit 1 } @@ -29,7 +36,7 @@ TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//") WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib} WP_CORE_DIR=${TEST_WP_ROOT_FOLDER-$TMPDIR/wordpress/} PLUGIN_DIR=$(pwd) -DB_SERVE_NAME=${DB_SERVE_NAME-wpgatsby_serve} +DB_SERVE_NAME=${DB_SERVE_NAME-wpgraphql_acf_serve} SKIP_DB_CREATE=${SKIP_DB_CREATE-false} download() { @@ -142,7 +149,7 @@ install_db() { configure_wordpress() { cd $WP_CORE_DIR wp config create --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASS" --dbhost="$DB_HOST" --skip-check --force=true - wp core install --url=wp.test --title="WPGraphQL ACF Tests" --admin_user=admin --admin_password=password --admin_email=admin@wp.test + wp core install --url=wp.test --title="WPGraphQL for ACF Tests" --admin_user=admin --admin_password=password --admin_email=admin@wp.test wp rewrite structure '/%year%/%monthnum%/%postname%/' } diff --git a/bin/run-docker.sh b/bin/run-docker.sh index d21e8d1..6c0a8f6 100644 --- a/bin/run-docker.sh +++ b/bin/run-docker.sh @@ -21,7 +21,17 @@ if [ -z "$1" ]; then print_usage_instructions fi -BUILD_NO_CACHE= +TAG=${TAG-latest} +WP_VERSION=${WP_VERSION-5.6} +PHP_VERSION=${PHP_VERSION-7.4} + +BUILD_NO_CACHE=${BUILD_NO_CACHE-} + +if [[ ! -f ".env" ]]; then + echo "No .env file was detected. .env.dist has been copied to .env" + echo "Open the .env file and enter values to match your local environment" + cp .env.dist .env +fi subcommand=$1; shift case "$subcommand" in diff --git a/docker-compose.yml b/docker-compose.yml index 03ea775..877582b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -29,7 +29,7 @@ services: local: app_db: - image: mysql:5.7 + image: mariadb:10.2 environment: MYSQL_ROOT_PASSWORD: root MYSQL_DATABASE: wordpress diff --git a/docker/app.Dockerfile b/docker/app.Dockerfile index 4e0872e..0cde63c 100644 --- a/docker/app.Dockerfile +++ b/docker/app.Dockerfile @@ -1,12 +1,19 @@ ############################################################################### -# Pre-configured WordPress Installation w/ WPGraphQL, WPGraphQL for ACF, ACF Pro # +# Pre-configured WordPress Installation w/ WPGraphQL, WPGatsby # # For testing only, use in production not recommended. # ############################################################################### + +# Use build args to get the right wordpress + php image ARG WP_VERSION ARG PHP_VERSION FROM wordpress:${WP_VERSION}-php${PHP_VERSION}-apache +# Needed to specify the build args again after the FROM command. +ARG WP_VERSION +ARG PHP_VERSION + +# Save the build args for use by the runtime environment ENV WP_VERSION=${WP_VERSION} ENV PHP_VERSION=${PHP_VERSION} @@ -39,13 +46,9 @@ RUN curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli # Set project environmental variables ENV WP_ROOT_FOLDER="/var/www/html" -ENV WORDPRESS_DB_HOST=${DB_HOST} -ENV WORDPRESS_DB_USER=${DB_USER} -ENV WORDPRESS_DB_PASSWORD=${DB_PASSWORD} -ENV WORDPRESS_DB_NAME=${DB_NAME} ENV PLUGINS_DIR="${WP_ROOT_FOLDER}/wp-content/plugins" ENV PROJECT_DIR="${PLUGINS_DIR}/wp-graphql-acf" -ENV WPGRAPHQL_VERSION="${WPGRAPHQL_VERSION}" +ENV DATA_DUMP_DIR="${PROJECT_DIR}/tests/_data" # Remove exec statement from base entrypoint script. RUN sed -i '$d' /usr/local/bin/docker-entrypoint.sh @@ -66,13 +69,16 @@ RUN echo "Installing XDebug 3 (in disabled state)" \ && echo "xdebug.start_with_request=yes" >> /usr/local/etc/php/conf.d/disabled/docker-php-ext-xdebug.ini \ && echo "xdebug.client_host=host.docker.internal" >> /usr/local/etc/php/conf.d/disabled/docker-php-ext-xdebug.ini \ && echo "xdebug.client_port=9003" >> /usr/local/etc/php/conf.d/disabled/docker-php-ext-xdebug.ini \ + && echo "xdebug.max_nesting_level=512" >> /usr/local/etc/php/conf.d/disabled/docker-php-ext-xdebug.ini \ ; # Set xdebug configuration off by default. See the entrypoint.sh. -ENV USING_XDEBUG=${USING_XDEBUG} +ENV USING_XDEBUG=0 # Set up entrypoint WORKDIR /var/www/html +COPY docker/app.setup.sh /usr/local/bin/app-setup.sh +COPY docker/app.post-setup.sh /usr/local/bin/app-post-setup.sh COPY docker/app.entrypoint.sh /usr/local/bin/app-entrypoint.sh RUN chmod 755 /usr/local/bin/app-entrypoint.sh ENTRYPOINT ["app-entrypoint.sh"] diff --git a/docker/app.entrypoint.sh b/docker/app.entrypoint.sh index 1a06d4c..3af289a 100644 --- a/docker/app.entrypoint.sh +++ b/docker/app.entrypoint.sh @@ -1,86 +1,7 @@ #!/bin/bash -if [ "$USING_XDEBUG" == "1" ]; then - echo "Enabling XDebug 3" - mv /usr/local/etc/php/conf.d/disabled/docker-php-ext-xdebug.ini /usr/local/etc/php/conf.d/ -fi - -# Run WordPress docker entrypoint. -. docker-entrypoint.sh 'apache2' - -set +u - -# Ensure mysql is loaded -dockerize -wait tcp://${DB_HOST}:${DB_HOST_PORT:-3306} -timeout 1m - -# Config WordPress -if [ ! -f "${WP_ROOT_FOLDER}/wp-config.php" ]; then - wp config create \ - --path="${WP_ROOT_FOLDER}" \ - --dbname="${DB_NAME}" \ - --dbuser="${DB_USER}" \ - --dbpass="${DB_PASSWORD}" \ - --dbhost="${DB_HOST}" \ - --dbprefix="${WP_TABLE_PREFIX}" \ - --skip-check \ - --quiet \ - --allow-root -fi - -# Install WP if not yet installed -if ! $( wp core is-installed --allow-root ); then - wp core install \ - --path="${WP_ROOT_FOLDER}" \ - --url="${WP_URL}" \ - --title='Test' \ - --admin_user="${ADMIN_USERNAME}" \ - --admin_password="${ADMIN_PASSWORD}" \ - --admin_email="${ADMIN_EMAIL}" \ - --allow-root -fi - -# Install and activate WPGraphQL - -echo "wpgraphql version... ${WPGRAPHQL_VERSION}" -echo "${PLUGINS_DIR}" - -if [ ! -f "${PLUGINS_DIR}/wp-graphql/wp-graphql.php" ]; then - # WPGRAPHQL_VERSION in format like v1.2.3 - echo ${WPGRAPHQL_VERSION} - if [[ -z ${WPGRAPHQL_VERSION} ]]; then - echo "installing latest WPGraphQL from WordPress.org" - wp plugin install wp-graphql --activate --allow-root - else - echo "Installing WPGraphQL from Github" - git clone https://github.com/wp-graphql/wp-graphql.git "${PLUGINS_DIR}/wp-graphql" - cd "${PLUGINS_DIR}/wp-graphql" - echo "checking out WPGraphQL tag/${WPGRAPHQL_VERSION}" - git checkout tags/${WPGRAPHQL_VERSION} -b master - composer install --no-dev - cd ${WP_ROOT_FOLDER} - echo "activating WPGraphQL" - wp plugin activate wp-graphql --allow-root - wp plugin list --allow-root - fi -else - wp plugin activate wp-graphql --allow-root -fi - -# Install and activate ACF Pro -if [ ! -f "${PLUGINS_DIR}/advanced-custom-fields-pro/acf.php" ]; then - wp plugin install \ - https://github.com/wp-premium/advanced-custom-fields-pro/archive/master.zip \ - --activate --allow-root -else - wp plugin activate advanced-custom-fields-pro --allow-root -fi - -# Install and activate WPGatsby -wp plugin activate wp-graphql-acf --allow-root - -# Set pretty permalinks. -wp rewrite structure '/%year%/%monthnum%/%postname%/' --allow-root - -wp db export "${PROJECT_DIR}/tests/_data/dump.sql" --allow-root +# Run app setup script. +. app-setup.sh +. app-post-setup.sh exec "$@" diff --git a/docker/app.post-setup.sh b/docker/app.post-setup.sh new file mode 100644 index 0000000..329a26a --- /dev/null +++ b/docker/app.post-setup.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# Activate wp-graphql +wp plugin install https://github.com/wp-premium/advanced-custom-fields-pro/archive/refs/heads/master.zip --activate --allow-root +wp plugin install wp-graphql --allow-root --activate +wp plugin activate wp-graphql-acf --allow-root + +# Set pretty permalinks. +wp rewrite structure '/%year%/%monthnum%/%postname%/' --allow-root + +wp db export "${DATA_DUMP_DIR}/dump.sql" --allow-root + +# If maintenance mode is active, de-activate it +if $( wp maintenance-mode is-active --allow-root ); then + echo "Deactivating maintenance mode" + wp maintenance-mode deactivate --allow-root +fi diff --git a/docker/app.setup.sh b/docker/app.setup.sh new file mode 100644 index 0000000..93b0c9f --- /dev/null +++ b/docker/app.setup.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +if [ "$USING_XDEBUG" == "1" ]; then + echo "Enabling XDebug 3" + mv /usr/local/etc/php/conf.d/disabled/docker-php-ext-xdebug.ini /usr/local/etc/php/conf.d/ +fi + +# Run WordPress docker entrypoint. +. docker-entrypoint.sh 'apache2' + +set +u + +# Ensure mysql is loaded +dockerize -wait tcp://${DB_HOST}:${DB_HOST_PORT:-3306} -timeout 1m + +# Config WordPress +if [ ! -f "${WP_ROOT_FOLDER}/wp-config.php" ]; then + wp config create \ + --path="${WP_ROOT_FOLDER}" \ + --dbname="${DB_NAME}" \ + --dbuser="${DB_USER}" \ + --dbpass="${DB_PASSWORD}" \ + --dbhost="${DB_HOST}" \ + --dbprefix="${WP_TABLE_PREFIX}" \ + --skip-check \ + --quiet \ + --allow-root +fi + +# Install WP if not yet installed +if ! $( wp core is-installed --allow-root ); then + wp core install \ + --path="${WP_ROOT_FOLDER}" \ + --url="${WP_URL}" \ + --title='Test' \ + --admin_user="${ADMIN_USERNAME}" \ + --admin_password="${ADMIN_PASSWORD}" \ + --admin_email="${ADMIN_EMAIL}" \ + --allow-root +fi + +echo "Running WordPress version: $(wp core version --allow-root) at $(wp option get home --allow-root)" diff --git a/docker/testing.Dockerfile b/docker/testing.Dockerfile index cdec274..c4e80e5 100644 --- a/docker/testing.Dockerfile +++ b/docker/testing.Dockerfile @@ -2,7 +2,9 @@ # Container for running Codeception tests on a WPGraphQL Docker instance. # ############################################################################ -# Using the 'DESIRED_' prefix to avoid confusion with environment variables of the same name. +ARG WP_VERSION +ARG PHP_VERSION + FROM wpgraphql-acf-app:latest LABEL author=jasonbahl @@ -18,8 +20,8 @@ RUN docker-php-ext-install pdo_mysql RUN apt-get install zip unzip -y \ && pecl install pcov -ENV COVERAGE=0 -ENV SUITES=${SUITES:-zz} +ENV COVERAGE= +ENV SUITES=${SUITES:-} # Install composer ENV COMPOSER_ALLOW_SUPERUSER=1 @@ -34,11 +36,8 @@ ENV PATH "$PATH:~/.composer/vendor/bin" # Configure php RUN echo "date.timezone = UTC" >> /usr/local/etc/php/php.ini -# Remove exec statement from base entrypoint script. -RUN sed -i '$d' /usr/local/bin/app-entrypoint.sh - # Set up entrypoint -WORKDIR /var/www/html/wp-content/plugins/wp-graphql-acf +WORKDIR /var/www/html COPY docker/testing.entrypoint.sh /usr/local/bin/testing-entrypoint.sh RUN chmod 755 /usr/local/bin/testing-entrypoint.sh ENTRYPOINT ["testing-entrypoint.sh"] diff --git a/docker/testing.entrypoint.sh b/docker/testing.entrypoint.sh index d812b6b..9bd316e 100644 --- a/docker/testing.entrypoint.sh +++ b/docker/testing.entrypoint.sh @@ -1,5 +1,7 @@ #!/bin/bash +echo "WordPress: ${WP_VERSION} PHP: ${PHP_VERSION}" + # Processes parameters and runs Codeception. run_tests() { if [[ -n "$COVERAGE" ]]; then @@ -15,10 +17,16 @@ run_tests() { exit 1 fi - for suite in $suites ; do - echo "Running Test Suite $suite" - vendor/bin/codecept run -c codeception.dist.yml ${suite} ${coverage:-} ${debug:-} --no-exit - done + # If maintenance mode is active, de-activate it + if $( wp maintenance-mode is-active --allow-root ); then + echo "Deactivating maintenance mode" + wp maintenance-mode deactivate --allow-root + fi + + + # Suites is the comma separated list of suites/tests to run. + echo "Running Test Suite $suites" + vendor/bin/codecept run -c codeception.dist.yml "${suites}" ${coverage:-} ${debug:-} --no-exit } # Exits with a status of 0 (true) if provided version number is higher than proceeding numbers. @@ -40,17 +48,25 @@ RewriteRule . /index.php [L] # Move to WordPress root folder workdir="$PWD" -echo "Moving to WordPress root directory." +echo "Moving to WordPress root directory ${WP_ROOT_FOLDER}." cd ${WP_ROOT_FOLDER} -# Run app entrypoint script. -. app-entrypoint.sh +# Because we are starting apache independetly of the docker image, +# we set WORDPRESS environment variables so apache see them and used in the wp-config.php +echo "export WORDPRESS_DB_HOST=${WORDPRESS_DB_HOST}" >> /etc/apache2/envvars +echo "export WORDPRESS_DB_USER=${WORDPRESS_DB_USER}" >> /etc/apache2/envvars +echo "export WORDPRESS_DB_PASSWORD=${WORDPRESS_DB_PASSWORD}" >> /etc/apache2/envvars +echo "export WORDPRESS_DB_NAME=${WORDPRESS_DB_NAME}" >> /etc/apache2/envvars + +# Run app setup scripts. +. app-setup.sh +. app-post-setup.sh write_htaccess # Return to PWD. -echo "Moving back to project working directory." -cd ${workdir} +echo "Moving back to project working directory ${PROJECT_DIR}" +cd ${PROJECT_DIR} # Ensure Apache is running service apache2 start @@ -78,8 +94,8 @@ if version_gt $PHP_VERSION 7.0 && [[ -n "$COVERAGE" ]] && [[ -z "$USING_XDEBUG" echo "Using pcov/clobber for codecoverage" docker-php-ext-enable pcov echo "pcov.enabled=1" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini - echo "pcov.directory = /var/www/html/wp-content/plugins/wp-graphql" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini - COMPOSER_MEMORY_LIMIT=-1 composer require --dev pcov/clobber + echo "pcov.directory = ${PROJECT_DIR}" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini + COMPOSER_MEMORY_LIMIT=-1 composer require pcov/clobber --dev vendor/bin/pcov clobber elif [[ -n "$COVERAGE" ]] && [[ -n "$USING_XDEBUG" ]]; then echo "Using XDebug for codecoverage" diff --git a/docs/fields/accordion.md b/docs/fields/accordion.md new file mode 100644 index 0000000..d5aa667 --- /dev/null +++ b/docs/fields/accordion.md @@ -0,0 +1,10 @@ +# Accordion + +The Accordion Field in Advanced Custom Fields that lets users separate other fields in collapsible +sections. + +This field is for administrative display purposes and is not exposed in WPGraphQL. + +---- + +- **Next Field:** [Button Group](./button-group.md) diff --git a/docs/fields/button-group.md b/docs/fields/button-group.md new file mode 100644 index 0000000..142b774 --- /dev/null +++ b/docs/fields/button-group.md @@ -0,0 +1,41 @@ +# Button Group Field + +Button Group fields are added to the WPGraphQL Schema as a field with the Type `String`. + +Button Group fields can be queried and a String will be returned. + +Here, we have a Button Group field named `button_group` on the Post Edit screen within the "ACF Docs" Field Group, and "Choice 2" is selected. + +![Button Group field in the Edit Post screen](../img/button-group-field-input.png?raw=true) + +This field can be Queried in GraphQL like so: + +```graphql +{ + post(id: "acf-example-test", idType: URI) { + acfDocs { + buttonGroup + } + } +} +``` + +and the results of the query would be: + +```json +{ + "data": { + "post": { + "acfDocs": { + "buttonGroup": "choice_2" + } + } + } +} +``` + +---- + +- **Previous Field:** [Accordion](./accordion.md) +- **Next Field:** [Checkbox](./checkbox.md) + diff --git a/docs/fields/checkbox.md b/docs/fields/checkbox.md new file mode 100644 index 0000000..c95c0c9 --- /dev/null +++ b/docs/fields/checkbox.md @@ -0,0 +1,43 @@ +# Checkbox Field + +Checkbox fields are added to the WPGraphQL Schema as a field with the Type `[ 'list_of' => 'String' ]`. + +Checkbox fields can be queried and a list (array) of Strings (the selected values) will be returned. + +Here, we have a Checkbox field named `checkbox` on the Post Edit screen within the "ACF Docs" Field Group, and "Choice 1" is selected. + +![Checkbox field in the Edit Post screen](../img/checkbox-field-input.png?raw=true) + +This field can be Queried in GraphQL like so: + +```graphql +{ + post(id: "acf-example-test", idType: URI) { + acfDocs { + checkbox + } + } +} +``` + +and the results of the query would be: + +```json +{ + "data": { + "post": { + "acfDocs": { + "checkbox": [ + "choice_1" + ] + } + } + } +} +``` + +---- + +- **Previous Field:** [Button Group](./button-group.md) +- **Next Field:** [Clone](./clone.md) + diff --git a/docs/fields/clone.md b/docs/fields/clone.md new file mode 100644 index 0000000..93ff021 --- /dev/null +++ b/docs/fields/clone.md @@ -0,0 +1,9 @@ +# Clone Field + +The clone field is not fully supported (yet). We plan to support it in the future. + +---- + +- **Previous Field:** [Checkbox](./checkbox.md) +- **Next Field:** [Color Picker](./color-picker.md) + diff --git a/docs/fields/color-picker.md b/docs/fields/color-picker.md new file mode 100644 index 0000000..73fee41 --- /dev/null +++ b/docs/fields/color-picker.md @@ -0,0 +1,40 @@ +# Color Picker Field + +The Color Picker field is added to the WPGraphQL Schema as field with the Type `String`. + +Color Picker fields can be queried and a String will be returned. + +Here, we have a Color Picker field named `color_picker` on the Post Edit screen within the "ACF Docs" Field Group, and "#dd3333" is the value. + +![Color Picker field in the Edit Post screen](../img/color-picker-field-input.png?raw=true) + +This field can be queried in GraphQL like so: + +```graphql +{ + post(id: "acf-example-test", idType: URI) { + acfDocs { + colorPicker + } + } +} +``` + +and the result of the query would be: + +```json +{ + "data": { + "post": { + "acfDocs": { + "colorPicker": "12:30 am" + } + } + } +} +``` + +---- + +- **Previous Field:** [Clone](./clone.md) +- **Next Field:** [Date Picker](./date-picker.md) diff --git a/docs/fields/date-picker.md b/docs/fields/date-picker.md new file mode 100644 index 0000000..4ac098c --- /dev/null +++ b/docs/fields/date-picker.md @@ -0,0 +1,40 @@ +# Date Picker Field + +The Date Picker field is added to the WPGraphQL Schema as field with the Type `String`. + +Date Picker fields can be queried and a String will be returned. + +Here, we have a Date Picker field named `date_picker` on the Post Edit screen within the "ACF Docs" Field Group, and "13/03/2020" is the date set. + +![Date Picker field in the Edit Post screen](../img/date-picker-field-input.png?raw=true) + +This field can be queried in GraphQL like so: + +```graphql +{ + post(id: "acf-example-test", idType: URI) { + acfDocs { + datePicker + } + } +} +``` + +and the result of the query would be: + +```json +{ + "data": { + "post": { + "acfDocs": { + "datePicker": "13/03/2020" + } + } + } +} +``` + +---- + +- **Previous Field:** [Color Picker](./color-picker.md) +- **Next Field:** [Date/Time Picker](./date-time-picker.md) diff --git a/docs/fields/date-time-picker.md b/docs/fields/date-time-picker.md new file mode 100644 index 0000000..5188ff4 --- /dev/null +++ b/docs/fields/date-time-picker.md @@ -0,0 +1,40 @@ +# Date/Time Picker Field + +The Date/Time Picker field is added to the WPGraphQL Schema as field with the Type `String`. + +Date/Time Picker fields can be queried, and a String will be returned. + +Here, we have a Date/Time Picker field named `date_time_picker` on the Post Edit screen within the "ACF Docs" Field Group, and "20/03/2020 8:15 am" is the value. + +![Date Picker field in the Edit Post screen](../img/date-time-picker-field-input.png?raw=true) + +This field can be queried in GraphQL like so: + +```graphql +{ + post(id: "acf-example-test", idType: URI) { + acfDocs { + dateTimePicker + } + } +} +``` + +and the result of the query would be: + +```json +{ + "data": { + "post": { + "acfDocs": { + "dateTimePicker": "20/03/2020 8:15 am" + } + } + } +} +``` + +---- + +- **Previous Field:** [Date Picker](./date-picker.md) +- **Next Field:** [Email](./email.md) diff --git a/docs/fields/email.md b/docs/fields/email.md new file mode 100644 index 0000000..112b167 --- /dev/null +++ b/docs/fields/email.md @@ -0,0 +1,40 @@ +# Email Field + +Email fields are added to the WPGraphQL Schema as a field with the Type `String`. + +Email fields can be queried and a String will be returned. + +Here, we have an Email field named `email` on the Post Edit screen within the "ACF Docs" Field Group. + +![Email field in the Edit Post screen](../img/email-field-input.png?raw=true) + +This field can be Queried in GraphQL like so: + +```graphql +{ + post( id: "acf-example-test" idType: URI ) { + acfDocs { + email + } + } +} +``` + +and the results of the query would be: + +```json +{ + "data": { + "post": { + "acfDocs": { + "email": "test@example.com" + } + } + } +} +``` + +---- + +- **Previous Field:** [Date/Time Picker](./date-time-picker.md) +- **Next Field:** [File](./file.md) diff --git a/docs/fields/file.md b/docs/fields/file.md new file mode 100644 index 0000000..4010a14 --- /dev/null +++ b/docs/fields/file.md @@ -0,0 +1,48 @@ +# File Field + +File fields are added to the WPGraphQL Schema as a field with the Type `MediaItem`. + +File fields can be queried and a MediaItem will be returned. + +The `MediaItem` type is an Object type that has it's own fields that can be selected. So, instead of _just_ getting the File ID returned and having to ask for the MediaItem object in a follow-up request, we can ask for fields available on the MediaItem Type. For this example, we ask for the `id` and `mediaItemUrl`. + +Here, we have a File field named `file` on the Post Edit screen within the "ACF Docs" Field Group. + +![File field in the Edit Post screen](../img/file-field-input.png?raw=true) + +This field can be Queried in GraphQL like so: + +```graphql +{ + post(id: "acf-example-test", idType: URI) { + acfDocs { + file { + id + mediaItemUrl + } + } + } +} +``` + +And the results of the query would be: + +```json +{ + "data": { + "post": { + "acfDocs": { + "file": { + "id": "YXR0YWNobWVudDozMjQ=", + "mediaItemUrl": "http://acf2.local/wp-content/uploads/2020/03/little-ceasars-receipt-01282020.pdf" + } + } + } + } +} +``` + +---- + +- **Previous Field:** [Email](./email.md) +- **Next Field:** [Flexible Content](./flexible-content.md) diff --git a/docs/fields/flexible-content.md b/docs/fields/flexible-content.md new file mode 100644 index 0000000..8c90d07 --- /dev/null +++ b/docs/fields/flexible-content.md @@ -0,0 +1,144 @@ +# Flexible Content Field + +The Flexible Content is a powerful ACF field that allows for groups of fields to be organized into "Layouts". + +These Layouts can be made up of other types of fields, and can be added and arranged in any order. + +Flexible Content Fields are added to the WPGraphQL Schema as a List Of [Unions](https://graphql.org/learn/schema/#union-types). + +The Union for a Flex Field is made up of each Layout in the Flex Field as the possible Types. + +In our example, we've created a Flex Field with 3 layouts named "Layout One", "Layout Two" and "Layout Three". In the Schema, we can see the Flex Field Union's Possible Types are these 3 layouts. + +![Flex Fields Schema Union Possible Types](../img/flex-field-union-possible-types.png?raw=true) + +Each of these Layout types will contain the fields defined for the layout and can be queried like fields in any other Group. + +Here's an example of a Flex Field named `flexible_content`, with 3 layouts: + +- Layout One + - Text field named "text" + - Text field named "another_text_field" +- Layout Two + - Image field named "image" +- Layout Three + - Gallery field named "gallery" + +Above are the possible layouts and their fields. These layouts can be added and arranged in any order. While we, as a GraphQL consumer, don't know ahead of time what order they will be in, we _do_ know what the possibilities are. + +Here's an example of a Flex Field named `flexible_content` with the values saved as "Layout One", "Layout Two" and "Layout Three", in that order, all populated with their respective fields. + +![Flex field in the Edit Post screen](../img/flex-field-input.png?raw=true) + +We can query this field like so: + +```graphql +{ + post(id: "acf-example-test", idType: URI) { + acfDocs { + flexibleContent { + __typename + ... on Post_Acfdocs_FlexibleContent_LayoutOne { + text + anotherTextField + } + ... on Post_Acfdocs_FlexibleContent_LayoutTwo { + image { + id + sourceUrl(size: MEDIUM) + } + } + ... on Post_Acfdocs_FlexibleContent_LayoutThree { + gallery { + id + sourceUrl(size: MEDIUM) + } + } + } + } + } +} +``` + +and the results of the query would be: + +```json +{ + "data": { + "post": { + "acfDocs": { + "flexibleContent": [ + { + "__typename": "Post_Acfdocs_FlexibleContent_LayoutOne", + "text": "Text Value One", + "anotherTextField": "Another Text Value" + }, + { + "__typename": "Post_Acfdocs_FlexibleContent_LayoutTwo", + "image": { + "id": "YXR0YWNobWVudDoyNTY=", + "sourceUrl": "http://acf2.local/wp-content/uploads/2020/02/babe-ruth-300x169.jpg" + } + }, + { + "__typename": "Post_Acfdocs_FlexibleContent_LayoutThree", + "gallery": [ + { + "id": "YXR0YWNobWVudDoyNTY=", + "sourceUrl": "http://acf2.local/wp-content/uploads/2020/02/babe-ruth-300x169.jpg" + }, + { + "id": "YXR0YWNobWVudDoyNTU=", + "sourceUrl": "http://acf2.local/wp-content/uploads/2020/02/babe-ruth-baseball-289x300.jpg" + } + ] + } + ] + } + } + } +} +``` + +If we were to re-arrange the layouts, so that the order was "Layout Three", "Layout One", "Layout Two", the results of the query would be: + +```json +"data": { + "post": { + "acfDocs": { + "flexibleContent": [ + { + "__typename": "Post_Acfdocs_FlexibleContent_LayoutThree", + "gallery": [ + { + "id": "YXR0YWNobWVudDoyNTY=", + "sourceUrl": "http://acf2.local/wp-content/uploads/2020/02/babe-ruth-300x169.jpg" + }, + { + "id": "YXR0YWNobWVudDoyNTU=", + "sourceUrl": "http://acf2.local/wp-content/uploads/2020/02/babe-ruth-baseball-289x300.jpg" + } + ] + } + { + "__typename": "Post_Acfdocs_FlexibleContent_LayoutOne", + "text": "Text Value One", + "anotherTextField": "Another Text Value" + }, + { + "__typename": "Post_Acfdocs_FlexibleContent_LayoutTwo", + "image": { + "id": "YXR0YWNobWVudDoyNTY=", + "sourceUrl": "http://acf2.local/wp-content/uploads/2020/02/babe-ruth-300x169.jpg" + } + }, + ] + } + } + } +``` + +---- + +- **Previous Field:** [File](./file.md) +- **Next Field:** [Gallery](./gallery.md) diff --git a/docs/fields/gallery.md b/docs/fields/gallery.md new file mode 100644 index 0000000..2eb3cd7 --- /dev/null +++ b/docs/fields/gallery.md @@ -0,0 +1,55 @@ +# Gallery Field + +Gallery fields are added to the WPGraphQL Schema as a field with the Type of `['list_of' => 'MediaItem']`. + +Gallery fields can be queried and a list of MediaItem types will be returned. + +Since the type is a list, we can expect an array to be returned. And since the Type within the list is `MediaItem`, we can ask for fields we want returned for each `MediaItem` in the list. In this case, let's say we want to ask for the `id` of each image and the `sourceUrl`, (size large). + +Here, we have a Gallery field named `gallery` on the Post Edit screen within the "ACF Docs" Field Group. + +![Gallery field in the Edit Post screen](../img/gallery-field-input.png?raw=true) + +This field can be Queried in GraphQL like so: + +```graphql +{ + post(id: "acf-example-test", idType: URI) { + acfDocs { + gallery { + id + sourceUrl(size: LARGE) + } + } + } +} +``` + +and the results of the query would be: + +```json +{ + "data": { + "post": { + "acfDocs": { + "gallery": [ + { + "id": "YXR0YWNobWVudDoyNTY=", + "sourceUrl": "http://wpgraphql.local/wp-content/uploads/2020/02/babe-ruth.jpg" + }, + { + "id": "YXR0YWNobWVudDoyNTU=", + "sourceUrl": "http://wpgraphql.local/wp-content/uploads/2020/02/babe-ruth-baseball-986x1024.jpg" + } + ] + } + } + } +} +``` + +---- + +- **Previous Field:** [Flexible Content](./flexible-content.md) +- **Next Field:** [Google Map](./google-map.md) + diff --git a/docs/fields/google-map.md b/docs/fields/google-map.md new file mode 100644 index 0000000..f99b8fc --- /dev/null +++ b/docs/fields/google-map.md @@ -0,0 +1,71 @@ +# Google Map Field + +Google Map fields are added to the WPGraphQL Schema as the `ACF_GoogleMap` Type. + +The `ACF_GoogleMap` Type has fields that expose location data. The available fields are: + +- **city** (String): The city associated with the location +- **country** (String): The country associated with the location +- **countryShort** (String): The country abbreviation associated with the location +- **latitude** (String): The latitude associated with the location +- **longitude** (String): The longitude associated with the location +- **placeId** (String): Place IDs uniquely identify a place in the Google Places database and on Google Maps. +- **postCode** (String): The post code associated with the location +- **state** (String): The state associated with the location +- **stateShort** (String): The state abbreviation associated with the location +- **streetAddress** (String): The street address associated with the location +- **streetName** (String): The street name associated with the location +- **streetNumber** (String): The street number associated with the location +- **zoom** (String): The zoom defined with the location + +Here, we have a Google Map field named `google_map` on the Post Edit screen within the "ACF Docs" Field Group, set with the Address "1 Infinite Loop, Cupertino, CA 95014, USA" as the value. + +![Google Map field in the Edit Post screen](../img/map-field-input.png?raw=true) + +This field can be queried in GraphQL like so: + +```graphql +{ + post(id: "acf-example-test", idType: URI) { + acfDocs { + googleMap { + streetAddress + streetNumber + streetName + city + state + postCode + countryShort + } + } + } +} +``` + +and the response would look like: + +```json +{ + "data": { + "post": { + "acfDocs": { + "googleMap": { + "streetAddress": "1 Infinite Loop, Cupertino, CA 95014, USA", + "streetNumber": "1", + "streetName": "Infinite Loop", + "city": "Cupertino", + "state": "California", + "postCode": "95014", + "placeId": "ChIJHTRqF7e1j4ARzZ_Fv8VA4Eo", + "countryShort": "US" + } + } + } + } +} +``` + +---- + +- **Previous Field:** [Gallery](./gallery.md) +- **Next Field:** [Group](./group.md) diff --git a/docs/fields/group.md b/docs/fields/group.md new file mode 100644 index 0000000..8e38227 --- /dev/null +++ b/docs/fields/group.md @@ -0,0 +1,44 @@ +# Group Field + +Group Fields are added to the WPGraphQL Schema as fields resolving to an Object Type named after the Group. + +Here, we have a Group field named `group` on the Post Edit screen within the "ACF Docs" Field Group. Within the "group" field, we have a Text Field named `text_field_in_group` and a Text Area field named `text_area_field_in_group` + +![Group field in the Edit Post screen](../img/group-field-input.png?raw=true) + +We can query the fields within the group like so: + +```graphql +{ + post(id: "acf-example-test", idType: URI) { + acfDocs { + group { + textFieldInGroup + textAreaFieldInGroup + } + } + } +} +``` + +And the results of the query would be: + +```json +{ + "data": { + "post": { + "acfDocs": { + "group": { + "textFieldInGroup": "Text value, in group", + "textAreaFieldInGroup": "Text are value, in group" + } + } + } + } +} +``` + +---- + +- **Previous Field:** [Google Map](./google-map.md) +- **Next Field:** [image](./image.md) diff --git a/docs/fields/image.md b/docs/fields/image.md new file mode 100644 index 0000000..4f34999 --- /dev/null +++ b/docs/fields/image.md @@ -0,0 +1,48 @@ +# Image Field + +Image fields are added to the WPGraphQL Schema as a field with the Type `MediaItem`. + +Image fields can be queried and a MediaItem will be returned. + +The `MediaItem` type is an Object type that has it's own fields that can be selected. So, instead of _just_ getting the Image ID returned and having to ask for the MediaItem object in a follow-up request, we can ask for fields available on the MediaItem Type. For this example, we ask for the `id` and `sourceUrl`. + +Here, we have an Image field named `image` on the Post Edit screen within the "ACF Docs" Field Group. + +![Image field in the Edit Post screen](../img/image-field-input.png?raw=true) + +This field can be Queried in GraphQL like so: + +```graphql +{ + post( id: "acf-example-test" idType: URI ) { + acfDocs { + image { + id + sourceUrl(size: MEDIUM) + } + } + } +} +``` + +And the results of the query would be: + +```json +{ + "data": { + "post": { + "acfDocs": { + "image": { + "id": "YXR0YWNobWVudDozMjM=", + "sourceUrl": "http://wpgraphql.local/wp-content/uploads/2020/03/babe-ruth-300x169.jpg" + } + } + } + } +} +``` + +---- + +- **Previous Field:** [Group](./group.md) +- **Next Field:** [Link](./link.md) diff --git a/docs/fields/link.md b/docs/fields/link.md new file mode 100644 index 0000000..fa6ab5e --- /dev/null +++ b/docs/fields/link.md @@ -0,0 +1,55 @@ +# Link Field + +Link fields are added to the WPGraphQL Schema as a field with the Type `ACF_Link`. + +Link fields can be queried and a `ACF_Link` will be returned. The ACF Link is an object with fields that can be selected. + +The available fields on the `ACF_Link` Type are: + +- **target** (String): The target of the link +- **title** (String): The target of the link +- **url** (String): The url of the link + +Here, we have a Link field named `link` on the Post Edit screen within the "ACF Docs" Field Group. + +![Link field in the Edit Post screen](../img/link-field-input.png?raw=true) + +This field can be Queried in GraphQL like so: + +```graphql +{ + post(id: "acf-example-test", idType: URI) { + acfDocs { + link { + target + title + url + } + } + } +} +``` + +and the results of the query would be: + +```json +{ + "data": { + "post": { + "acfDocs": { + "link": { + "target": "", + "title": "Hello world!", + "url": "http://acf2.local/hello-world/" + } + } + } + } +} +``` + +---- + +- **Previous Field:** [Image](./image.md) +- **Next Field:** [Message](./message.md) + diff --git a/docs/fields/message.md b/docs/fields/message.md new file mode 100644 index 0000000..bbefeab --- /dev/null +++ b/docs/fields/message.md @@ -0,0 +1,8 @@ +# Message Field + +Message fields are not currently supported. + +---- + +- **Previous Field:** [Link](./link.md) +- **Next Field:** [Number](./number.md) diff --git a/docs/fields/number.md b/docs/fields/number.md new file mode 100644 index 0000000..71e4d99 --- /dev/null +++ b/docs/fields/number.md @@ -0,0 +1,40 @@ +# Number Field + +Number fields are added to the WPGraphQL Schema as a field with the Type `Float`. + +Number fields can be queried, and a Float will be returned. + +Here, we have a Number field named `number` on the Post Edit screen within the "ACF Docs" Field Group. + +![Number field in the Edit Post screen](../img/number-field-input.png?raw=true) + +This field can be Queried in GraphQL like so: + +```graphql +{ + post( id: "acf-example-test" idType: URI ) { + acfDocs { + number + } + } +} +``` + +and the results of the query would be: + +```json +{ + "data": { + "post": { + "acfDocs": { + "number": 5 + } + } + } +} +``` + +---- + +- **Previous Field:** [Message](./message.md) +- **Next Field:** [Oembed](./oembed.md) diff --git a/docs/fields/oembed.md b/docs/fields/oembed.md new file mode 100644 index 0000000..07604c2 --- /dev/null +++ b/docs/fields/oembed.md @@ -0,0 +1,41 @@ +# oEmbed Field + +oEmbed fields are added to the WPGraphQL Schema as a field with the Type `String`. + +oEmbed fields can be queried, and a String will be returned. + +Here, we have a oEmbed field named `oembed` on the Post Edit screen within the "ACF Docs" Field Group. + +![oEmbed field in the Edit Post screen](../img/oEmbed-field-input.png?raw=true) + +This field can be Queried in GraphQL like so: + +```graphql +{ + post(id: "acf-example-test", idType: URI) { + acfDocs { + oembed + } + } +} +``` + +and the results of the query would be: + +```json +{ + "data": { + "post": { + "acfDocs": { + "oembed": "https://www.youtube.com/watch?v=ZEytXfaWwcc" + } + } + } +} +``` + +---- + +- **Previous Field:** [Number](./number.md) +- **Next Field:** [Page Link](./page-link.md) + diff --git a/docs/fields/page-link.md b/docs/fields/page-link.md new file mode 100644 index 0000000..49a3747 --- /dev/null +++ b/docs/fields/page-link.md @@ -0,0 +1,87 @@ +# Page Link Field + +Page Link fields are added to the WPGraphQL Schema as a field with a [Union](https://graphql.org/learn/schema/#union-types) of Possible Types the field is configured to allow. + +Since Page Link fields can be configured to be limited to certain Post Types, the Union will represent those Types. + +For example, if the Post Object field is configured to allow Posts of the `post` and `page` types to be selected: + +![Page Link field Post Type Config](../img/page-link-field-post-type-config.png?raw=true) + +Then the Union type for the field will allow `Post` and `Page` types to be returned, as seen in the Schema via GraphiQL: + +![Page Link field Union Possible Types](../img/page-link-field-possible-types.png?raw=true) + +Here, we have a Page Link field named `page_link` on the Post Edit screen within the "ACF Docs" Field Group, and the value is set to the "Sample Page" page. + +![Page Link field in the Edit Post screen](../img/page-link-field-input.png?raw=true) + +This field can be Queried in GraphQL like so: + +```graphql +{ + post(id: "acf-example-test", idType: URI) { + acfDocs { + pageLink { + __typename + ... on Post { + id + title + date + } + ... on Page { + id + title + } + } + } + } +} +``` + +and the results of the query would be: + +```json +{ + "data": { + "post": { + "acfDocs": { + "pageLink": { + "__typename": "Page", + "id": "cGFnZToy", + "title": "Sample Page" + } + } + } + } +} +``` + +Here, we set the value to the "Hello World" Post: + +![Page Link field in the Edit Post screen](../img/page-link-field-input-2.png?raw=true) + +And the results of the same query are now: + +```json +{ + "data": { + "post": { + "acfDocs": { + "pageLink": { + "__typename": "Post", + "id": "cG9zdDox", + "title": "Hello world!", + "date": "2020-02-20T23:12:21" + } + } + } + } +} +``` + +---- + +- **Previous Field:** [Oembed](./oembed.md) +- **Next Field:** [Checkbox](./password.md) + diff --git a/docs/fields/password.md b/docs/fields/password.md new file mode 100644 index 0000000..8b89f7b --- /dev/null +++ b/docs/fields/password.md @@ -0,0 +1,40 @@ +# Password Field + +Password fields are added to the WPGraphQL Schema as a field with the Type `String`. + +Password fields can be queried, and a String will be returned. + +Here, we have a Password field named `password` on the Post Edit screen within the "ACF Docs" Field Group. + +![Password field in the Edit Post screen](../img/password-field-input.png?raw=true) + +This field can be Queried in GraphQL like so: + +```graphql +{ + post( id: "acf-example-test" idType: URI ) { + acfDocs { + password + } + } +} +``` + +and the results of the query would be: + +```json +{ + "data": { + "post": { + "acfDocs": { + "password": "123456" + } + } + } +} +``` + +---- + +- **Previous Field:** [Page Link](./page-link.md) +- **Next Field:** [Post Object](./post-object.md) diff --git a/docs/fields/post-object.md b/docs/fields/post-object.md new file mode 100644 index 0000000..deed218 --- /dev/null +++ b/docs/fields/post-object.md @@ -0,0 +1,125 @@ +# Post Object Field + +Post Object fields are added to the WPGraphQL Schema as a field with a [Union](https://graphql.org/learn/schema/#union-types) of Possible Types the field is configured to allow. + +If the field is configured to allow multiple selections, it will be added to the Schema as a List Of the Union Type. + +Since Post Object fields can be configured to be limited to certain Post Types, the Union will represent those Types. + +For example, if the Post Object field is configured to allow Posts of the `post` and `page` types to be selected: + +![Post Object field Post Type Config](../img/post-object-field-post-type-config.png?raw=true) + +Then the Union type for the field will allow `Post` and `Page` types to be returned, as seen in the Schema via GraphiQL: + +![Post Object field Union Possible Types](../img/post-object-field-possible-types.png?raw=true) + +Here, we have a Post Object field named `post_object` on the Post Edit screen within the "ACF Docs" Field Group, configured with the Post "Hello World!". + +![Post Object field in the Edit Post screen](../img/post-object-field-input-post.png?raw=true) + +As a GraphQL consumer, we don't know in advance if the value is going to be a Page or a Post. + +So we can specify, via GraphQL fragment, what fields we want if the object is a Post, or if it is a Page. + +This field can be Queried in GraphQL like so: + +```graphql +{ + post(id: "acf-example-test", idType: URI) { + acfDocs { + postObject { + __typename + ... on Post { + id + title + date + } + ... on Page { + id + title + } + } + } + } +} +``` + +and the results of the query would be: + +```json +{ + "data": { + "post": { + "acfDocs": { + "postObject": { + "__typename": "Post", + "id": "cG9zdDox", + "title": "Hello world!", + "date": "2020-02-20T23:12:21" + } + } + } + } +} +``` + +If the input of the field was saved as a Page, instead of a Post, like so: + +![Post Object field in the Edit Post screen](../img/post-object-field-input-page.png?raw=true) + +Then the same query above, would return the following results: + +```json +{ + "data": { + "post": { + "acfDocs": { + "postObject": { + "__typename": "Page", + "id": "cGFnZToy", + "title": "Sample Page" + } + } + } + } +} +``` + +Now, if the field were configured to allow multiple values, the field would be added to the Schema as a `listOf`, returning an Array of the Union. + +If the field were set with a value of one Page, and one Post, like so: + +![Post Object field in the Edit Post screen](../img/post-object-field-input-multi.png?raw=true) + +Then the results of the same query as above would be: + +```json +{ + "data": { + "post": { + "acfDocs": { + "postObject": [ + { + "__typename": "Page", + "id": "cGFnZToy", + "title": "Sample Page" + }, + { + "__typename": "Post", + "id": "cG9zdDox", + "title": "Hello world!", + "date": "2020-02-20T23:12:21" + } + ] + } + } + } +} +``` + +---- + +- **Previous Field:** [Password](./password.md) +- **Next Field:** [Radio](./radio.md) + diff --git a/docs/fields/radio.md b/docs/fields/radio.md new file mode 100644 index 0000000..a11d9b5 --- /dev/null +++ b/docs/fields/radio.md @@ -0,0 +1,40 @@ +# Radio Button Field + +Radio Button fields are added to the WPGraphQL Schema as a field with the Type `String`. + +Radio Button fields can be queried and a String will be returned. + +Here, we have a Radio Button field named `radio_button` on the Post Edit screen within the "ACF Docs" Field Group, and "Choice 2" is selected. + +![Radio Button field in the Edit Post screen](../img/radio-button-field-input.png?raw=true) + +This field can be Queried in GraphQL like so: + +```graphql +{ + post(id: "acf-example-test", idType: URI) { + acfDocs { + radioButton + } + } +} +``` + +and the results of the query would be: + +```json +{ + "data": { + "post": { + "acfDocs": { + "radioButton": "choice_2" + } + } + } +} +``` + +---- + +- **Previous Field:** [Post Object](./post-object.md) +- **Next Field:** [Range](./range.md) diff --git a/docs/fields/range.md b/docs/fields/range.md new file mode 100644 index 0000000..2768acd --- /dev/null +++ b/docs/fields/range.md @@ -0,0 +1,40 @@ +# Range Field + +Range fields are added to the WPGraphQL Schema as a field with the Type `Float`. + +Range fields can be queried, and a Float will be returned. + +Here, we have a Range field named `range` on the Post Edit screen within the "ACF Docs" Field Group. + +![Range field in the Edit Post screen](../img/range-field-input.png?raw=true) + +This field can be Queried in GraphQL like so: + +```graphql +{ + post( id: "acf-example-test" idType: URI ) { + acfDocs { + range + } + } +} +``` + +and the results of the query would be: + +```json +{ + "data": { + "post": { + "acfDocs": { + "range": 5 + } + } + } +} +``` + +---- + +- **Previous Field:** [Radio](./radio.md) +- **Next Field:** [Relationship](./relationship.md) diff --git a/docs/fields/relationship.md b/docs/fields/relationship.md new file mode 100644 index 0000000..5c0fb30 --- /dev/null +++ b/docs/fields/relationship.md @@ -0,0 +1,72 @@ +# Relationship Field + +Relationship fields are added to the WPGraphQL Schema as a field with a [Union](https://graphql.org/learn/schema/#union-types) of Possible Types the field is configured to allow. + +Since Relationship fields can be configured to be limited to certain Post Types, the Union will represent those Types. + +For example, if the Post Object field is configured to allow Posts of the `post` and `page` types to be selected: + +![Relationship field Post Type Config](../img/relationship-field-post-type-config.png?raw=true) + +Then the Union type for the field will allow `Post` and `Page` types to be returned, as seen in the Schema via GraphiQL: + +![Relationship field Union Possible Types](../img/relationship-field-possible-types.png?raw=true) + +Here, we have a Relationship field named `relationship` on the Post Edit screen within the "ACF Docs" Field Group, and the value is set to "Hello World!" post, and the "Sample Page" page. + +![Relationship field in the Edit Post screen](../img/relationship-field-input.png?raw=true) + +This field can be Queried in GraphQL like so: + +```graphql +{ + post(id: "acf-example-test", idType: URI) { + acfDocs { + relationship { + __typename + ... on Post { + id + title + date + } + ... on Page { + id + title + } + } + } + } +} +``` + +and the results of the query would be: + +```json +{ + "data": { + "post": { + "acfDocs": { + "relationship": [ + { + "__typename": "Post", + "id": "cG9zdDox", + "title": "Hello world!", + "date": "2020-02-20T23:12:21" + }, + { + "__typename": "Page", + "id": "cGFnZToy", + "title": "Sample Page" + } + ] + } + } + } +} +``` + +---- + +- **Previous Field:** [Range](./range.md) +- **Next Field:** [Repeater](./repeater.md) + diff --git a/docs/fields/repeater.md b/docs/fields/repeater.md new file mode 100644 index 0000000..f57d5bb --- /dev/null +++ b/docs/fields/repeater.md @@ -0,0 +1,68 @@ +# Repeater Field + +Repeater Fields are added to the Schema as a List Of the Type of group that makes up the fields. + +For example, we've created a Repeater Field that has a Text Field named `text_field_in_repeater` and an Image Field named `image_field_in_repeater`. + +Here, the Repeater Field is populated with 2 rows: +- Row 1: + - Text Field: Text Value 1 + - Image: 256 +- Row 2: + - Text Field: Text Value 2 + - Image: 255 + +![Repeater field in the Edit Post screen](../img/repeater-field-input.png?raw=true) + +This field can be queried in GraphQL like so: + +```graphql +{ + post(id: "acf-example-test", idType: URI) { + acfDocs { + repeater { + textFieldInRepeater + imageFieldInRepeater { + databaseId + id + sourceUrl + } + } + } + } +} +``` + +and the results of the query would be: + +```json +{ + "data": { + "post": { + "acfDocs": { + "repeater": [ + { + "textFieldInRepeater": "Text Value 1", + "imageFieldInRepeater": { + "id": "YXR0YWNobWVudDoyNTY=", + "sourceUrl": "http://acf2.local/wp-content/uploads/2020/02/babe-ruth.jpg" + } + }, + { + "textFieldInRepeater": "Text Value 2", + "imageFieldInRepeater": { + "id": "YXR0YWNobWVudDoyNTU=", + "sourceUrl": "http://acf2.local/wp-content/uploads/2020/02/babe-ruth-baseball-scaled.jpg" + } + } + ] + } + } + } +} +``` + +---- + +- **Previous Field:** [Relationship](./relationship.md) +- **Next Field:** [Select](./select.md) diff --git a/docs/fields/select.md b/docs/fields/select.md new file mode 100644 index 0000000..cf3b566 --- /dev/null +++ b/docs/fields/select.md @@ -0,0 +1,40 @@ +# Select Field + +Select fields (when configured to _not_ allow mutliple selections) are added to the WPGraphQL Schema as a field with the Type `String`. + +Select fields, without multiple selections allowed, can be queried and a String will be returned. + +Here, we have a Select field named `select` on the Post Edit screen within the "ACF Docs" Field Group, and "Choice 1" is selected. + +![Select field in the Edit Post screen](../img/select-field-input.png?raw=true) + +This field can be Queried in GraphQL like so: + +```graphql +{ + post(id: "acf-example-test", idType: URI) { + acfDocs { + select + } + } +} +``` + +and the results of the query would be: + +```json +{ + "data": { + "post": { + "acfDocs": { + "select": "choice_1" + } + } + } +} +``` + +---- + +- **Previous Field:** [Repeater](./repeater.md) +- **Next Field:** [Tab](./tab.md) diff --git a/docs/fields/tab.md b/docs/fields/tab.md new file mode 100644 index 0000000..481486b --- /dev/null +++ b/docs/fields/tab.md @@ -0,0 +1,8 @@ +# Tab Field + +Tab fields are not currently supported. + +---- + +- **Previous Field:** [Select](./select.md) +- **Next Field:** [Taxonomy](./taxonomy.md) diff --git a/docs/fields/taxonomy.md b/docs/fields/taxonomy.md new file mode 100644 index 0000000..69593c1 --- /dev/null +++ b/docs/fields/taxonomy.md @@ -0,0 +1,53 @@ +# Taxonomy Field + +The Taxonomy field is added to the GraphQL Schema as a List Of the Taxonomy Type. + +For example, if the field is configured to the "Category" taxonomy, then the field in the Schema will be a List of the Category type. + +![Taxonomy field Taxonomy Config](../img/taxonomy-field-taxonomy-config.png?raw=true) + +Here, we have a Taxonomy field named `taxonomy` on the Post Edit screen within the "ACF Docs" Field Group, configured with the Category "Test Category". + +![Taxonomy field in the Edit Post screen](../img/taxonomy-field-input.png?raw=true) + +This field can be queried like so: + +```graphql +{ + post(id: "acf-example-test", idType: URI) { + acfDocs { + taxonomy { + __typename + id + name + } + } + } +} +``` + +and the results of the query would be: + +```json +{ + "data": { + "post": { + "acfDocs": { + "taxonomy": [ + { + "__typename": "Category", + "id": "Y2F0ZWdvcnk6Mg==", + "name": "Test Category" + } + ] + } + } + } +} +``` + +---- + +- **Previous Field:** [Tab](./tab.md) +- **Next Field:** [Text](./text.md) + diff --git a/docs/fields/text-area.md b/docs/fields/text-area.md new file mode 100644 index 0000000..c3b20a5 --- /dev/null +++ b/docs/fields/text-area.md @@ -0,0 +1,41 @@ +# Text Area Field + +Text Area fields are added to the WPGraphQL Schema as a field with the Type `String`. + +Text Area fields can be queried and a String will be returned. + +Here, we have a Text Area field named `text_area` on the Post Edit screen within the "ACF Docs" Field Group. + +![Text Area field in the Edit Post screen](../img/text-area-field-input.png?raw=true) + +This field can be Queried in GraphQL like so: + +```graphql +{ + post( id: "acf-example-test" idType: URI ) { + acfDocs { + textArea + } + } +} +``` + +and the results of the query would be: + +```json +{ + "data": { + "post": { + "acfDocs": { + "textArea": "Text value" + } + } + } +} +``` + +---- + +- **Previous Field:** [Text](./text.md) +- **Next Field:** [Time Picker](./time-picker.md) + diff --git a/docs/fields/text.md b/docs/fields/text.md new file mode 100644 index 0000000..5c437ec --- /dev/null +++ b/docs/fields/text.md @@ -0,0 +1,41 @@ +# Text Field + +Text fields are added to the WPGraphQL Schema as a field with the Type `String`. + +Text fields can be queried and a String will be returned. + +Here, we have a Text field named `text` on the Post Edit screen within the "ACF Docs" Field Group. + +![Text field in the Edit Post screen](../img/text-field-input.png?raw=true) + +This field can be Queried in GraphQL like so: + +```graphql +{ + post( id: "acf-example-test" idType: URI ) { + acfDocs { + text + } + } +} +``` + +and the results of the query would be: + +```json +{ + "data": { + "post": { + "acfDocs": { + "text": "Text Value" + } + } + } +} +``` + +---- + +- **Previous Field:** [Taxonomy](./taxonomy.md) +- **Next Field:** [Text Area](./text-area.md) + diff --git a/docs/fields/time-picker.md b/docs/fields/time-picker.md new file mode 100644 index 0000000..4f9ada3 --- /dev/null +++ b/docs/fields/time-picker.md @@ -0,0 +1,41 @@ +# Time Picker Field + +The Time Picker field is added to the WPGraphQL Schema as field with the Type `String`. + +Time Picker fields can be queried and a String will be returned. + +Here, we have a Time Picker field named `time_picker` on the Post Edit screen within the "ACF Docs" Field Group, and "12:30 am" is the value. + +![Time Picker field in the Edit Post screen](../img/time-picker-field-input.png?raw=true) + +This field can be queried in GraphQL like so: + +```graphql +{ + post(id: "acf-example-test", idType: URI) { + acfDocs { + timePicker + } + } +} +``` + +and the result of the query would be: + +```json +{ + "data": { + "post": { + "acfDocs": { + "timePicker": "12:30 am" + } + } + } +} +``` + +---- + +- **Previous Field:** [Text Area](text-area.md) +- **Next Field:** [True/False](true-false.md) + diff --git a/docs/fields/true-false.md b/docs/fields/true-false.md new file mode 100644 index 0000000..887f556 --- /dev/null +++ b/docs/fields/true-false.md @@ -0,0 +1,41 @@ +# True/False Field + +True/False fields are added to the WPGraphQL Schema as a field with the Type `Boolean`. + +True/False fields can be queried and a Boolean will be returned. + +Here, we have a True/False field named `true_false` on the Post Edit screen within the "ACF Docs" Field Group, and "true" is selected. + +![True/False field in the Edit Post screen](../img/true-false-field-input.png?raw=true) + +This field can be Queried in GraphQL like so: + +```graphql +{ + post(id: "acf-example-test", idType: URI) { + acfDocs { + trueFalse + } + } +} +``` + +and the results of the query would be: + +```json +{ + "data": { + "post": { + "acfDocs": { + "trueFalse": true + } + } + } +} +``` + +---- + +- **Previous Field:** [Time Picker](./time-picker.md) +- **Next Field:** [url](./url.md) + diff --git a/docs/fields/url.md b/docs/fields/url.md new file mode 100644 index 0000000..1290924 --- /dev/null +++ b/docs/fields/url.md @@ -0,0 +1,41 @@ +# URL Field + +Url fields are added to the WPGraphQL Schema as a field with the Type `String`. + +Url fields can be queried and a String will be returned. + +Here, we have a URL field named `url` on the Post Edit screen within the "ACF Docs" Field Group. + +![Url field in the Edit Post screen](../img/url-field-input.png?raw=true) + +This field can be Queried in GraphQL like so: + +```graphql +{ + post( id: "acf-example-test" idType: URI ) { + acfDocs { + url + } + } +} +``` + +and the results of the query would be: + +```json +{ + "data": { + "post": { + "acfDocs": { + "url": "https://wpgraphql.com" + } + } + } +} +``` + +---- + +- **Previous Field:** [True/False](./true-false.md) +- **Next Field:** [User](./user.md) + diff --git a/docs/fields/user.md b/docs/fields/user.md new file mode 100644 index 0000000..3fa00fe --- /dev/null +++ b/docs/fields/user.md @@ -0,0 +1,81 @@ +# 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](../img/user-field-input.png?raw=true) + +This field can be queried in GraphQL like so: + +```graphql +{ + post(id: "acf-example-test", idType: URI) { + acfDocs { + user { + id + username + firstName + lastName + } + } + } +} +``` + +and the response would look like: + +```json +{ + "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](../img/user-field-input-multiple.png?raw=true) + +and the response to the same query would look like: + +```json +{ + "data": { + "post": { + "acfDocs": { + "user": [ + { + "id": "dXNlcjox", + "username": "jasonbahl", + "firstName": "Jason", + "lastName": "Bahl" + }, + { + "id": "dXNlcjoy", + "username": "WPGraphQL", + "firstName": "WP", + "lastName": "GraphQL" + } + ] + } + } + } +} +``` + +---- + +- **Previous Field:** [Url](./url.md) +- **Next Field:** [WYSIWYG](./wysiwyg.md) diff --git a/docs/fields/wysiwyg.md b/docs/fields/wysiwyg.md new file mode 100644 index 0000000..d9742fb --- /dev/null +++ b/docs/fields/wysiwyg.md @@ -0,0 +1,39 @@ +# WYSIWYG Editor Field + +WYSIWYG fields are added to the WPGraphQL Schema as a field with the Type `String`. + +WYSIWYG fields can be queried and a String will be returned. + +Here, we have a WYSIWYG field named `wysiwyg` on the Post Edit screen within the "ACF Docs" Field Group. + +![WYSIWYG field in the Edit Post screen](../img/wysiwyg-field-input.png?raw=true) + +This field can be Queried in GraphQL like so: + +```graphql +{ + post( id: "acf-example-test" idType: URI ) { + acfDocs { + wysiwyg + } + } +} +``` + +and the results of the query would be: + +```json +{ + "data": { + "post": { + "acfDocs": { + "wysiwyg": "Some content in a WYSIWYG field
\n" + } + } + } +} +``` + +---- + +- **Previous Field:** [User](./user.md) diff --git a/vendor/autoload.php b/vendor/autoload.php index f128e0f..d36db58 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -4,4 +4,4 @@ require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInit9e804fc6f45415f83dd03aeed86e33f0::getLoader(); +return ComposerAutoloaderInit9ad3088e87bfaece4c49e4950c016732::getLoader(); diff --git a/vendor/composer/InstalledVersions.php b/vendor/composer/InstalledVersions.php index 2a3c352..808e680 100644 --- a/vendor/composer/InstalledVersions.php +++ b/vendor/composer/InstalledVersions.php @@ -30,7 +30,7 @@ class InstalledVersions 'aliases' => array ( ), - 'reference' => '87fb6ecc2ca38d4c8064d95f8bd91ca368e5b7e0', + 'reference' => '697d5dd8d31883a4b8c0f333ad2abd23850097ff', 'name' => 'wp-graphql/wp-graphql-acf', ), 'versions' => @@ -42,7 +42,7 @@ class InstalledVersions 'aliases' => array ( ), - 'reference' => '87fb6ecc2ca38d4c8064d95f8bd91ca368e5b7e0', + 'reference' => '697d5dd8d31883a4b8c0f333ad2abd23850097ff', ), ), ); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 3be627f..2066d6f 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInit9e804fc6f45415f83dd03aeed86e33f0 +class ComposerAutoloaderInit9ad3088e87bfaece4c49e4950c016732 { private static $loader; @@ -24,15 +24,15 @@ public static function getLoader() require __DIR__ . '/platform_check.php'; - spl_autoload_register(array('ComposerAutoloaderInit9e804fc6f45415f83dd03aeed86e33f0', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit9ad3088e87bfaece4c49e4950c016732', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__))); - spl_autoload_unregister(array('ComposerAutoloaderInit9e804fc6f45415f83dd03aeed86e33f0', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit9ad3088e87bfaece4c49e4950c016732', 'loadClassLoader')); $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); if ($useStaticLoader) { require __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInit9e804fc6f45415f83dd03aeed86e33f0::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInit9ad3088e87bfaece4c49e4950c016732::getInitializer($loader)); } else { $map = require __DIR__ . '/autoload_namespaces.php'; foreach ($map as $namespace => $path) { diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 23d10df..aaf5864 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInit9e804fc6f45415f83dd03aeed86e33f0 +class ComposerStaticInit9ad3088e87bfaece4c49e4950c016732 { public static $prefixLengthsPsr4 = array ( 'W' => @@ -31,9 +31,9 @@ class ComposerStaticInit9e804fc6f45415f83dd03aeed86e33f0 public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInit9e804fc6f45415f83dd03aeed86e33f0::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInit9e804fc6f45415f83dd03aeed86e33f0::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInit9e804fc6f45415f83dd03aeed86e33f0::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInit9ad3088e87bfaece4c49e4950c016732::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit9ad3088e87bfaece4c49e4950c016732::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInit9ad3088e87bfaece4c49e4950c016732::$classMap; }, null, ClassLoader::class); } diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index 594c6fd..81c84b5 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -6,7 +6,7 @@ 'aliases' => array ( ), - 'reference' => '87fb6ecc2ca38d4c8064d95f8bd91ca368e5b7e0', + 'reference' => '697d5dd8d31883a4b8c0f333ad2abd23850097ff', 'name' => 'wp-graphql/wp-graphql-acf', ), 'versions' => @@ -18,7 +18,7 @@ 'aliases' => array ( ), - 'reference' => '87fb6ecc2ca38d4c8064d95f8bd91ca368e5b7e0', + 'reference' => '697d5dd8d31883a4b8c0f333ad2abd23850097ff', ), ), ); diff --git a/vendor/composer/platform_check.php b/vendor/composer/platform_check.php index f79e574..6d3407d 100644 --- a/vendor/composer/platform_check.php +++ b/vendor/composer/platform_check.php @@ -4,8 +4,8 @@ $issues = array(); -if (!(PHP_VERSION_ID >= 70000)) { - $issues[] = 'Your Composer dependencies require a PHP version ">= 7.0.0". You are running ' . PHP_VERSION . '.'; +if (!(PHP_VERSION_ID >= 70100)) { + $issues[] = 'Your Composer dependencies require a PHP version ">= 7.1.0". You are running ' . PHP_VERSION . '.'; } if ($issues) {