Skip to content

Commit e93cb5e

Browse files
authored
πŸ§‘β€πŸ’» Improve GraphQL typings (#70)
2 parents 6383f01 + 202653c commit e93cb5e

File tree

13 files changed

+127
-127
lines changed

13 files changed

+127
-127
lines changed

β€Ž.github/workflows/compatibility.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,20 @@ jobs:
1111
strategy:
1212
matrix:
1313
operating-system: [ubuntu-latest]
14-
php-versions: ['7.4', '8.0']
14+
php-versions: ['8.2']
1515
name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}
1616
steps:
1717
- name: Checkout
1818
uses: actions/checkout@v2
19+
1920
- name: Setup PHP, with composer and extensions
2021
uses: shivammathur/setup-php@v2
2122
with:
2223
php-version: ${{ matrix.php-versions }}
2324
coverage: xdebug
2425
env:
2526
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27+
2628
- name: Get composer cache directory
2729
id: composercache
2830
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
@@ -31,7 +33,9 @@ jobs:
3133
path: ${{ steps.composercache.outputs.dir }}
3234
key: ${{ runner.os }}-${{ matrix.php-versions }}-composer-${{ hashFiles('**/composer.json') }}
3335
restore-keys: ${{ runner.os }}-${{ matrix.php-versions }}-composer-
36+
3437
- name: Install Composer dependencies
3538
run: composer install --no-progress --prefer-dist --optimize-autoloader --no-suggest
36-
- name: PHP lint
37-
run: composer run-script lint
39+
40+
- name: Run Pint
41+
run: vendor/bin/pint --test

β€Ž.github/workflows/main.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,26 @@ jobs:
88
steps:
99
- name: Checkout
1010
uses: actions/checkout@v2
11+
1112
- name: Setup PHP
1213
uses: shivammathur/setup-php@v2
1314
with:
14-
php-version: '7.3'
15+
php-version: '8.2'
1516
coverage: xdebug
1617
env:
1718
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19+
1820
- name: Get composer cache directory
1921
id: composercache
2022
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
2123
- uses: actions/cache@v2
2224
with:
2325
path: ${{ steps.composercache.outputs.dir }}
24-
key: ${{ runner.os }}-7.3.x-composer-${{ hashFiles('**/composer.json') }}
25-
restore-keys: ${{ runner.os }}-7.3.x-composer-
26+
key: ${{ runner.os }}-8.2.x-composer-${{ hashFiles('**/composer.json') }}
27+
restore-keys: ${{ runner.os }}-8.2.x-composer-
28+
2629
- name: Install Composer dependencies
2730
run: composer install --no-progress --prefer-dist --optimize-autoloader --no-suggest
28-
- name: PHP lint
29-
run: composer run-script lint
31+
32+
- name: Run Pint
33+
run: vendor/bin/pint --test

β€Ž.github/workflows/release.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,27 @@ jobs:
2020
coverage: xdebug
2121
env:
2222
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23+
2324
- name: Install Composer dependencies
2425
run: composer install --no-progress --prefer-dist --optimize-autoloader --no-suggest --no-dev
26+
2527
- name: Cleanup unnecessary files
2628
run: rm -rf .git .github .editorconfig .prettierrc .gitattributes .gitignore assets composer.json composer.lock package.json yarn.lock webpack.mix.js tailwind.config.js
29+
2730
- name: Get the version
2831
id: get_version
2932
run: echo ::set-output name=version::${GITHUB_REF/refs\/tags\//}
3033
shell: bash
34+
3135
- name: Create subfolder
3236
run: mkdir acf-editor-palette && mv ./* acf-editor-palette/ 2>/dev/null
3337
continue-on-error: true
38+
3439
- name: Create distributable zip file
3540
uses: montudor/action-zip@v0.1.0
3641
with:
3742
args: zip -qq -r9 acf-editor-palette.zip acf-editor-palette
43+
3844
- name: Upload zip as release asset
3945
uses: svenstaro/upload-release-action@v2
4046
with:

β€Žcomposer.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,13 @@
1414
"php": ">=7.2"
1515
},
1616
"require-dev": {
17-
"squizlabs/php_codesniffer": "^3.10"
17+
"laravel/pint": "^1.21"
1818
},
1919
"autoload": {
2020
"psr-4": {
2121
"Log1x\\AcfEditorPalette\\": "src/"
2222
}
2323
},
24-
"scripts": {
25-
"lint": [
26-
"phpcs --ignore=vendor --exclude=PSR1.Methods.CamelCapsMethodName --extensions=php --standard=PSR12 ."
27-
]
28-
},
2924
"config": {
3025
"optimize-autoloader": true,
3126
"preferred-install": "dist",

β€Žcomposer.lock

Lines changed: 40 additions & 54 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žplugin.php

Lines changed: 53 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Plugin Name: Advanced Custom Fields: Editor Palette Field
55
* Plugin URI: https://github.com/log1x/acf-editor-palette
66
* Description: A Gutenberg-like editor palette color picker field for Advanced Custom Fields.
7-
* Version: 1.2.0
7+
* Version: 1.2.1
88
* Author: Brandon Nifong
99
* Author URI: https://github.com/log1x
1010
*/
@@ -59,15 +59,14 @@ public function __invoke()
5959
return;
6060
}
6161

62-
$this->uri = plugin_dir_url(__FILE__) . $this->path;
63-
$this->path = plugin_dir_path(__FILE__) . $this->path;
62+
$this->uri = plugin_dir_url(__FILE__).$this->path;
63+
$this->path = plugin_dir_path(__FILE__).$this->path;
6464

65-
if (file_exists($composer = __DIR__ . '/vendor/autoload.php')) {
65+
if (file_exists($composer = __DIR__.'/vendor/autoload.php')) {
6666
require_once $composer;
6767
}
6868

6969
$this->register();
70-
$this->registerAdminColumns();
7170
}
7271

7372
/**
@@ -84,56 +83,62 @@ protected function register()
8483
}
8584

8685
if (function_exists('register_graphql_acf_field_type')) {
87-
add_action('wpgraphql/acf/registry_init', function () {
88-
register_graphql_acf_field_type($this->name, [
89-
'graphql_type' => 'string',
90-
'resolve' => function ($root, $args, $context, $info, $field_config) {
91-
$value = $field_config->resolve_field($root, $args, $context, $info);
92-
93-
if (is_null($value)) {
94-
return null;
95-
}
96-
97-
return $value['slug'];
98-
},
99-
]);
100-
});
86+
$this->registerGraphQl();
10187
}
10288
}
10389

10490
/**
105-
* Register the field type with ACP.
91+
* Register the field type with WPGraphQL.
10692
*
10793
* @return void
10894
*/
109-
protected function registerAdminColumns()
95+
protected function registerGraphQl()
11096
{
111-
if (! defined('ACP_FILE')) {
112-
return;
113-
}
114-
115-
add_filter('ac/column/value', function ($value, $id, $column) {
116-
if (
117-
! is_a($column, '\ACA\ACF\Column') ||
118-
$column->get_field_type() !== $this->name ||
119-
empty($color = get_field($column->get_meta_key())) ||
120-
! is_array($color)
121-
) {
122-
return $value;
123-
}
124-
125-
return sprintf(
126-
'<div
127-
aria-label="%s"
128-
style="background-color: %s;
129-
width: 24px;
130-
height: 24px;
131-
border: 1px solid #ccd0d4;
132-
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);"
133-
></div>',
134-
$color['name'],
135-
$color['color']
136-
);
137-
}, 10, 3);
97+
add_action('graphql_register_types', function () {
98+
register_graphql_object_type('EditorPaletteColor', [
99+
'description' => __('Editor Palette Color Object', 'acf-editor-palette'),
100+
'fields' => [
101+
'color' => [
102+
'type' => 'String',
103+
'description' => __('The color value', 'acf-editor-palette'),
104+
],
105+
'name' => [
106+
'type' => 'String',
107+
'description' => __('The color name', 'acf-editor-palette'),
108+
],
109+
'slug' => [
110+
'type' => 'String',
111+
'description' => __('The color slug', 'acf-editor-palette'),
112+
],
113+
'text' => [
114+
'type' => 'String',
115+
'description' => __('The text color class', 'acf-editor-palette'),
116+
],
117+
'background' => [
118+
'type' => 'String',
119+
'description' => __('The background color class', 'acf-editor-palette'),
120+
],
121+
],
122+
]);
123+
});
124+
125+
add_action('wpgraphql/acf/registry_init', function () {
126+
register_graphql_acf_field_type($this->name, [
127+
'graphql_type' => 'EditorPaletteColor',
128+
'resolve' => function ($root, $args, $context, $info, $field_config) {
129+
$id = isset($root['node']) && isset($root['node']->ID) ? $root['node']->ID : null;
130+
$field = $info->fieldName ?? null;
131+
132+
if (! $id || ! $field) {
133+
return null;
134+
}
135+
136+
$field = preg_replace('/[A-Z]/', '_$0', $field);
137+
$field = strtolower($field);
138+
139+
return get_field($field, $id);
140+
},
141+
]);
142+
});
138143
}
139144
});

β€Žpublic/entrypoints.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"field": {
33
"js": [
44
"js/runtime.b89547.js",
5-
"js/field.563bb8.js"
5+
"js/field.e4dfc5.js"
66
],
77
"css": [
88
"css/field.d1c65e.css"

β€Žpublic/js/field.563bb8.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

β€Žpublic/js/field.e4dfc5.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
Β (0)