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

Choice Fields Should return key and value, not just value

Open jasonbahl opened this issue 2 years ago • 1 comments

What problem does this address?

Currently when querying a choice field, such as checkbox, select, or radio, only the value is returned.

i.e.

CleanShot 2023-10-30 at 13 04 55

Some users would like to be able to query these fields and have both the label and value of the choice returned.

i.e (mocked example).

CleanShot 2023-10-30 at 13 09 46

What is your proposed solution?

I have 2 ideas:

  1. Change choice fields to always return a GraphQL Object Type, something like an AcfChoice type that has a label and value field. (this would be a breaking change)
  2. Leave it as is, but introduce a new GraphQL Return Type (graphql_return_type) setting that allows the return type to be changed. Fields like choice fields could be changed to return a different Type, letting users opt-in at their leisure to a different return type (if it's a breaking change, it would be opt-in). . .This could be a global setting for all fields of xx type, or could be a setting that's determined on a field-by-field basis (or a combination of each)

What alternatives have you considered?

We could document how folks can do this via hooks/filters and leave default behavior as-is 🤷🏻

Additional Context

related: https://github.com/wp-graphql/wp-graphql-acf/issues/44

jasonbahl avatar Oct 30 '23 19:10 jasonbahl

What's the status of this? I would love to see it working. We just ran into this issue.

danimalweb avatar Oct 28 '24 19:10 danimalweb