wp-graphql / wp-graphql-acf

WPGraphQL for Advanced Custom Fields
https://wpgraphql.com/acf
626 stars 123 forks source link

mutation createPost don't support acf input field? #216

Closed shipcake closed 11 months ago

shipcake commented 3 years ago

Hi. I use Wpgraphql and i have problem. how to defind custom acf type in input field?

Yuribtr commented 3 years ago

I have a same question too. Can't find any info. @jasonbahl seems that creation and update is not supported by this plugin, isn't it?

saleebm commented 3 years ago

Hey I have an example repository here wp-acf-mutations. Basically you need to run the filters to add the input fields to the schema based on your acf fields.

Yuribtr commented 3 years ago

Hi @saleebm, many thanks for pointing me out. If ACF and CPT UI is present the problem solves in few lines of code in functions.php. It is amazing!

use WPGraphQL\AppContext;
use WPGraphQL\Model\User;

add_action( 'graphql_input_fields', function ( $fields, $type_name, $config ) { 
    if ( $type_name === 'UpdateArticlesInput') {
        $fields = array_merge( $fields, [       
            'name' => [ 'type' => 'String' ],
        ] );
    }

    return $fields;
}, 20, 3 );

add_action( 'graphql_post_object_mutation_update_additional_data', function ( $post_id, $input, $mutation_name, $context, $info ) {
    if ( isset( $input['name'] ) ) {
        update_field('field_6036d0504e27d', $input['name'], $post_id);
    }
}, 10, 5 ); 
jasonbahl commented 3 years ago

Hello! Mutations are not currently on the near-term roadmap for this plugin. We do hope to add support in the future, but I don't know when. I've labeled this "Future Feature" and moved it to the "ACF Mutations" milestone for future consideration.

nagman commented 2 years ago

Hi @saleebm, many thanks for pointing me out. If ACF and CPT UI is present the problem solves in few lines of code in functions.php. It is amazing!

use WPGraphQL\AppContext;
use WPGraphQL\Model\User;

add_action( 'graphql_input_fields', function ( $fields, $type_name, $config ) {   
  if ( $type_name === 'UpdateArticlesInput') {
      $fields = array_merge( $fields, [       
          'name' => [ 'type' => 'String' ],
      ] );
  }

  return $fields;
}, 20, 3 );

add_action( 'graphql_post_object_mutation_update_additional_data', function ( $post_id, $input, $mutation_name, $context, $info ) {
  if ( isset( $input['name'] ) ) {
      update_field('field_6036d0504e27d', $input['name'], $post_id);
  }
}, 10, 5 ); 

Where do you find the field_6036d0504e27d in the database?

nagman commented 2 years ago

Ok I found it => in the wp_postmeta table, search for _your_acf_field_slug (add the _ at the beginning) in the meta_key column, and take the corresponding meta_value.

Thanks a lot @Yuribtr! You solved my dead end!

jasonbahl commented 11 months ago

👋🏻 We are re-building WPGraphQL for ACF over here: https://github.com/wp-graphql/wpgraphql-acf.

I've created a new issue to track mutation support (and explain some current blockers). see: https://github.com/wp-graphql/wpgraphql-acf/issues/109

I'm going to close this in favor of tracking it in the new repo.