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

Feature Request: Mutation Support

Open jasonbahl opened this issue 2 years ago • 4 comments

What problem does this address?

As a developer building headless sites and applications with WPGraphQL and Advanced Custom Fields, I would like to be able to mutate ACF data using GraphQL Mutations.

What is your proposed solution?

Similar to how ACF Field Groups and Fields are exposed to the Schema as Types and Fields that can be queried, the field groups and fields should also be exposed to the Schema as Input Types and associated with the corresponding mutations (createPost, etc)


What alternatives have you considered?

  • not supporting this feature
  • allowing users to hook/filter in their own support
  • let the community maintain solutions (ex: https://github.com/zngly/wp-graphql-acf-mutations)

Additional Context

This issue is currently considered blocked for the following reasons:

Access Control

We believe there needs to be a lot more work on the core ACF side to define access control. What fields can be edited by what users (which capabilities, etc)

Of course, WPGraphQL could solve this to some degree, but we believe it's a more central issue as fields could be edited in the admin UI, CLI, REST, GraphQL, etc, so core ACF should provide more ways to formally lock down which fields can/cannot be modified by certain users.

GraphQL oneOf Directive / Input Unions

GraphQL has the concept of Unions and Interfaces for queries, which allows the response to return "one of" many possible types.

For example, we can query contentNode and get "one of" the many Types that represent a WordPress Post Type (Page, Post, etc)

Or we can query nodeByUri() and get "one of" the many possible Types that can be accessed by a uri (Post, Page, User, Category, Tag, etc)

When it comes to inputting data, GraphQL does not (yet) support the concept of inputting "one of" many different possible types.

This is a critical feature, in our mind, to be able to properly support mutations for ACF because the Types of data that can be input could easily be "one of" many different Types. Especially, but certainly not limited to, when inputting data for field Types such as Flexible Content would be needed.

The GraphQL Spec currently has an RFC open for this concept: https://github.com/graphql/graphql-spec/pull/825

Until this feature becomes part of the GraphQL Spec ,and then GraphQL-PHP, and then WPGraphQL, we will not be officially supporting GraphQL mutations for ACF.

jasonbahl avatar Nov 01 '23 14:11 jasonbahl

@jasonbahl The critical feature you are waiting might take years before landing into GraphQL spec, and might never happens, maybe we should not wait for it before supporting this feature as the community extension you linked has proven it's feasible by another way.

nestarz avatar Nov 20 '23 12:11 nestarz

@nestarz If the community extension is working for your projects, I recommend you continue using it!

As a maintainer, I don't want to maintain something I'm not comfortable maintaining long-term, and I don't feel like I want to support mutations until these features are available in GraphQL.

I've built the plugins to be extendable so that users can customize the Schema for their projects.

Hopefully we see more traction on the oneOf directives, etc, but until then I don't feel comfortable building/supporting these features.

jasonbahl avatar Nov 20 '23 18:11 jasonbahl

Currently we are trying to use Wordpress as Headless CMS. If you can add it. it would be helpful for all developer community.

siamahnaf avatar Apr 05 '24 17:04 siamahnaf

Using wordpress as headess CMS as well. This feature would unlock huge potential for wordpress being a great headless CMS for any project!

seifsg avatar Dec 03 '24 10:12 seifsg