acf-icon-picker icon indicating copy to clipboard operation
acf-icon-picker copied to clipboard

Add GraphQL support

Open chrysos opened this issue 2 years ago • 1 comments

Hello, your plugin is great, congratulations.

It would be really nice if you added support for WP-Graphql.

https://www.wpgraphql.com/

chrysos avatar Jan 17 '23 21:01 chrysos

Hey!

I have managed to add the Icon Picker to WPGraphQL. Hopefully this will help someone in the future.

I am using the ACF for WPGraphQl v2, the documentation for this will be here: https://acf.wpgraphql.com/

More specifically I used this example code found on these pages

https://acf.wpgraphql.com/adding-support-for-3rd-party-acf-field-type/ https://github.com/wp-graphql/wpgraphql-acf/tree/develop/src/ThirdParty/AcfExtended/FieldType

        // Add field-resolver
        add_action( 'wpgraphql/acf/registry_init', function() {
            register_graphql_acf_field_type('icon-picker');
        });

        register_graphql_acf_field_type(
            'icon-picker',
            [
                'graphql_type' => static function () {
                    return 'String';
                },
                'resolve' => static function ( $root, $args, $context, $info, $field_type, $field_config ) {
                    $value = $field_config->resolve_field( $root, $args, $context, $info );

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

                    return $value;
                },
            ]
        );

samfrank avatar Apr 09 '24 08:04 samfrank