Log1x / acf-editor-palette

A Gutenberg-like editor palette color picker field for Advanced Custom Fields.
https://github.com/Log1x/acf-editor-palette
MIT License
95 stars 14 forks source link

Add support for editor_palette to WP Graphql schemas #63

Closed erikhartin closed 3 months ago

erikhartin commented 3 months ago

Thanks for this amazing plugin (and all the other ones you make, you're a real lifesaver!)

I use the roots stack along with acf-composer to build headless WP backends, and as useful as this plugin is, it doesn't natively resolve into Graphql fields.

I am presently adding a resolver myself in my themes (usually to setup.php) but am thinking you might want to include this as part of the plugin?


/**
 * Add "editor_palette' to the graphql schema.
 *
 * @return void
 */

 add_action( 'wpgraphql/acf/registry_init', function() {
    register_graphql_acf_field_type( 'editor_palette', [
      'graphql_type' => 'string',
      'resolve' => function ($root, $args, $context, $info, $field_type, $field_config ) {
        $value = $field_config->resolve_field($root, $args, $context, $info);

        if (is_null($value)) {
          return null;
        }

        return $value['slug'];
      },
    ]);
  });

you can see the WP Graphql developer reference for adding support for 3rd party ACf field types here

Log1x commented 3 months ago

hey no problem.

i haven't used ACF with GraphQL but I'm definitely open to a PR.

erikhartin commented 3 months ago

good shout. just opened a PR.