Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a way to query for posts before or after a specific time (not just date) #1234

Open
kellenmace opened this issue Apr 13, 2020 · 14 comments · May be fixed by #1239
Open

Provide a way to query for posts before or after a specific time (not just date) #1234

kellenmace opened this issue Apr 13, 2020 · 14 comments · May be fixed by #1239
Labels
Compat: Breaking Change This is a breaking change to existing functionality Component: Input Component: Query Type: Enhancement New feature or request
Milestone

Comments

@kellenmace
Copy link
Contributor

In my app, I need the ability to fire off a request every few minutes to the WP backend to get any posts that have beed added or edited since the last time I checked. Currently though, WPGraphQL only supports doing date queries using day, month and year. You can't get more specific than that and narrow it down to a certain hour/minute/second. Example:

query getPosts {
  posts(
    first: 10,
    where: {
      dateQuery: {
        column: MODIFIED
        after: {
          # Need to add hour, minute & second here.
          day: 13
          month: 4
          year: 2020
        }
      }
    }
  ) {
    nodes {
      postId
      modifiedGmt
    }
  }
}

WP_Query() does provide that ability by accepting a strtotime() compatible string as the before/after argument. Documentation: https://developer.wordpress.org/reference/classes/wp_query/#date-parameters

Even if we want to avoid accepting an arbitrary string like WP_Query() does, I think this can still be accomplished by accepting hour, minute, and second input args for before and after. Then apps like mine that need to query for published/modified posts on a frequent interval would be able to do so.

Who's with me?

@jasonbahl
Copy link
Collaborator

@kellenmace ya, I actually think it would be better if the input was a timestamp instead of a day/month/year input like it is now.

Like, we could accept a timestamp as the input, and let the conversion happen behind the scenes via something like strtotime() or whatever.

I definitely think this would be valuable for a lot of folks.

@jasonbahl
Copy link
Collaborator

Like, we could deprecate day, month, and year and introduce a timestamp field.

So the query could become:

dateQuery: {
        column: MODIFIED
        after: {
          timestamp: "2020-04-13T20:39:42+00:00"
        }
      }

or something like that.

We'd need to specify the format(s) allowed for input. The above example is ISO 8601, for example.

@kellenmace
Copy link
Contributor Author

@jasonbahl Yeah, accepting a timestamp would work beautifully for me. 👍

@kellenmace
Copy link
Contributor Author

@jasonbahl Just added a PR. Rather than a timestamp field nested inside of the DateQueryInput, I opted to remove DateQueryInput and have the before and after fields accept strtotime()-compatible strings. I did that for consistency with WP_Query(), since it accepts strings for the before and after args themselves. Docs: https://developer.wordpress.org/reference/classes/wp_query/#date-parameters. That way our 'dateQuery' => 'date_query' mapping still works as expected.

We had talked about throwing an error if a non-strtotime()-compatible string was provided, but it doesn't look like we're doing that for many of the other args. Like if you fire off a query like this:

posts(where: {in: [999999]}) {
    nodes {
      title
    }
  }

...and there is no post with an ID of 999999, no error is thrown. You just get back an empty nodes array. And the same is true for most other fields that ultimately get passed into WP_Query().

If a non-strtotime()-compatible string is passed into WP_Query() as the date query before or after arg, it simply gets ignored. So that's what is happening for WPGraphQL queries in this PR branch currently, as well. Please let me know if you think we should throw an error instead, though. Thanks.

P.S. Issue number 1234 FTW!

@jasonbahl jasonbahl added this to the 1.0 release milestone Apr 24, 2020
@CodeProKid CodeProKid added Compat: Breaking Change This is a breaking change to existing functionality Component: Input Component: Query labels Apr 27, 2020
@jasonbahl jasonbahl removed this from the 1.0 release milestone Jun 24, 2020
@rgevrek
Copy link

rgevrek commented Oct 2, 2021

Dear All

It seams that there is no activity for more than one year on this topic.
I think this feature request will be very valuable. Are there any plans to continue or to merge the respective pull request.

Thank you in advance.
Kind regards.

@jasonbahl jasonbahl added this to the v2.0 milestone Apr 4, 2022
@stale
Copy link

stale bot commented Aug 2, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Aug 2, 2022
@stale
Copy link

stale bot commented Sep 1, 2022

This issue has been automatically closed because it has not had recent activity. If you believe this issue is still valid, please open a new issue and mark this as a related issue.

@stale stale bot closed this as completed Sep 1, 2022
@rgevrek
Copy link

rgevrek commented Sep 2, 2022

I think this issue shall not be ignored while it is also solved within a PR. This useful feature avoids inefficient calls and responses.

@justlevine
Copy link
Collaborator

No worries @rgevrek this is still on the radar for v2, got closed by an overzealous 'stale-bot' 😅

@justlevine justlevine reopened this Sep 2, 2022
@stale stale bot removed stale labels Sep 2, 2022
@bhardie bhardie added the not stale Short-circuits stalebot. USE SPARINGLY label Dec 13, 2022
@justlevine justlevine removed the not stale Short-circuits stalebot. USE SPARINGLY label Mar 3, 2023
@matepaiva
Copy link

sorry, but any updates on this? I really could use this feature...

@ailishmc
Copy link

Like, we could deprecate day, month, and year and introduce a timestamp field.

So the query could become:

dateQuery: {
        column: MODIFIED
        after: {
          timestamp: "2020-04-13T20:39:42+00:00"
        }
      }

or something like that.

We'd need to specify the format(s) allowed for input. The above example is ISO 8601, for example.

yes plsssssss 🙏

@matepaiva
Copy link

i need that!

@igormsg
Copy link

igormsg commented Nov 27, 2023

looking forward to it

@jasonbahl
Copy link
Collaborator

related: #1713

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compat: Breaking Change This is a breaking change to existing functionality Component: Input Component: Query Type: Enhancement New feature or request
Projects
Status: 🛑 On Hold
Development

Successfully merging a pull request may close this issue.

10 participants