gatsbyjs / gatsby-source-wordpress-experimental

The upcoming v4 of gatsby-source-wordpress, currently in beta
MIT License
385 stars 100 forks source link

Feature Request: Add custom Date fields #420

Closed chrispytoes closed 3 years ago

chrispytoes commented 3 years ago

I have an ACF DateTime field that I need to query by using gte and lte. However, unless the ACF field is explicitly named date, it does not get recognized as a date. I've tried several different date formats and none of them work. Unless my date field is named date, GraphQL reads it as a string.

TylerBarnes commented 3 years ago

This is because WPGraphQL doesn't have a date time scalar so there's no way to programatically determine which fields are date fields by analyzing the remote schema. If you look at this file

You can see where it's hardcoded to date, dateGmt and modified.

I would recommend opening an issue on the WPGraphQL repo requesting a DateTime scalar 👍

Alternatively we would accept a PR adding a plugin option like so:

{
  options: {
    schema: {
      addDateFields: [`yourFieldName`]
    }
  }
}

That option could be made to add additional fields to the Date type-filter so that you can set additional fields as Date fields.

chrispytoes commented 3 years ago

@TylerBarnes Thanks for the response. That's interesting, I would have thought that WPGraphQL would know the types based off of the field settings in ACF.

I did manage to get it working by overriding the type myself using createTypes within the createSchemaCustomization hook. Looks like a newer feature, docs here. This works and serves my purposes for now.

TylerBarnes commented 3 years ago

Great to hear that that works :) WPGraphQL does know the types but isn't exposing that one yet. Once it's added to WPGQL we'll be adding automatic support on the Gatsby side for sure.

TylerBarnes commented 3 years ago

I'm cleaning up this repo and so I'm moving this to our internal backlog - we're still waiting on WPGQL support for this so we can't do anything yet.