wp-graphql / wpgraphql-acf

Re-architecture of WPGraphQL for ACF
GNU General Public License v3.0
83 stars 12 forks source link

When ACF "Date Picker" field is used inside a "Flexible content" field always return epoch time from WPGraphQL Query #212

Open DenislavPopov opened 4 months ago

DenislavPopov commented 4 months ago

Description

When ACF "Date Picker" field is used inside a "Flexible content" field, the returned value for this date field is always epoch time, disregarding the saved value. ( 1970-01-01T00:00:00+00:00 ).

Setup of the fields in ACF: acf-setup

Saved settings on the page: settings-on-the-page

GraphQL result: graphql-result

Steps to reproduce

  1. Create ACF Field group and assign it to post type of Page
  2. Add "Flexible content" field and inside that field add "Date Picker" field, you can add additional fields just to check, that the data from this flexible field is returned.
  3. Query the fields added, and you'll notice the "Date Picker" field will always return epoch time.

Additional context

No response

WPGraphQL Version

1.27.0

WordPress Version

6.5.4

PHP Version

8.1.23

Additional environment details

WPGraphQL for ACF: version: 2.2.0

Please confirm that you have searched existing issues in the repo.

Please confirm that you have disabled ALL plugins except for WPGraphQL.

justlevine commented 4 months ago

Hey @DenislavPopov

As you noted, this is an issue with WPGraphQL for ACF and however they're resolving their date field, so you should probably file an issue with them

(Marking as invalid? - not because we think you're not experiencing a real issue, but simply because there's no way to address a potential bug in code that exists outside of this repo).

josephfusco commented 4 months ago

Hey @DenislavPopov, I transferred this issue over to WPGraphQL for ACF.

DenislavPopov commented 4 months ago

Hey @DenislavPopov, I transferred this issue over to WPGraphQL for ACF.

Great, thanks! 🍻 I was just about to create new issue there and saw it's there already

justlevine commented 4 months ago

Hey @\DenislavPopov, I transferred this issue over to WPGraphQL for ACF.

Good to know we can do that for next time I send someone to do duplicate work 🤦

jasonbahl commented 3 months ago

@DenislavPopov in my first attempt to reproduce, I was not able to. The date field nested within a flexible content layout is returning the date as expected:

CleanShot 2024-06-10 at 10 21 39@2x

CleanShot 2024-06-10 at 10 19 40@2x

I tried reproducing with the following:

jasonbahl commented 3 months ago

I just tried with WPGraphQL for ACF v2.2.0 as well and same results. A date picker field within a flexible field layout is resolving as expected. Can you check to see that the values stored in the database are what you expect?

Also, can you share your ACF Field Group export to make sure I'm setting things up the same?

jasonbahl commented 3 months ago

@DenislavPopov this logic looks like it might possibly be a culprit? https://github.com/wp-graphql/wpgraphql-acf/blob/develop/src/FieldType/DatePicker.php#L33-L38

jasonbahl commented 3 months ago

@DenislavPopov here's how the data is stored when I tested:

CleanShot 2024-06-10 at 10 36 01@2x

I'm curious if the data is saving differently for you?

DenislavPopov commented 3 months ago

Hi @jasonbahl

Sending the info.

The database entry looks saved in the same format and also when reloading the post page the field is correctly populated with the saved data:

database

The GraphQL result:

graphql

Export of the fields from my end: acf-export-2024-06-10_Denis.json

DenislavPopov commented 3 months ago

Debugged the line pointed, and it looks like the format is correctly passed but the date received is not, hmm, will try to investigate further also.

debug

Addition1: I can see the $root contains correct data, but then somehow the function resolve_field returns the epoch time

debug2

Addition2: Compared the JSON exported files as with your import it works fine and narrowed it to the return format, which in my case is "return_format": "d\/m\/Y", while in your case is "return_format": "F j, Y",. So to narrow it down it looks it doesn't work only with the first return format:

not-working-format
jasonbahl commented 3 months ago

@DenislavPopov I was able to reproduce when the return format is changed. Investigating this further.