the-events-calendar / ql-events

The Events Calendar binding to WPGraphQL
15 stars 7 forks source link

Issue retrieving event id from recurring events, `hide_subsequent_recurrences` or `tribeHideRecurrenceDefault` not affecting queries #60

Open hcavanaugh opened 11 months ago

hcavanaugh commented 11 months ago

Tested in both: TEC 6.1.3 + Pro 6.1.1 (with ql-events/feature/events-query-fix PR, otherwise events query returns empty, see #59 ) TEC 6.0.3.1 + Pro 6.0.2

QL events 0.3.0

When using graphQL to retrieve recurring events, the eventId is depreciated for the databaseId, but the databaseId field gives the occurrence id. In the database, occurrence_ids are associated with the parent event_id post ID that originally created the event. There is currently no registered graphql field that gets the event_id associated with an occurrence.

For example, if you want to retrieve the event series ID associated with a given recurring event to run a separate tribeEventSerie query, the only event data retrieved in the events query that contains that event_id is the &p=x or 038;p parameter value in the guid field.

It's definitely a hacky way to go about getting the series id, but it does work when using tec_event_series:

register_graphql_field( 'Event', 'series', [
    'type' => 'Integer',
    'description' => __( 'The id of the event series associated with this event', 'wp-graphql' ),
    'resolve' => function( $source ) {
            // Get the parent event ID from the guid for now....
            $guid = parse_url($source->guid, PHP_URL_FRAGMENT);
            parse_str($guid, $parent_id);   
            $series = tec_event_series( $parent_id['038;p'] );
            return ! empty( $series ) ? $series->ID : 0;
    }
] );

The other issue is that when tribeHideRecurrenceDefault is set to true in TEC Settings, this setting is not applied to the GQL queries. I tried the fork in #22, but this did not hide recurring events beyond the next upcoming recurring event in a series.

There is no hide_subsequent_recurrences in the where arguments. I tried to create a hide_subsequent_recurrences where arg and call the Condense_Events_Series class controller in Event_Connection_Resolver::sanitize_input_fields if that where arg is true, but was receiving an Undefined constant graphql error when calling that controller.

This latter issue is imperative for our work: We want to be able to query all single events and only the next upcoming recurring event in series within a given date.

hcavanaugh commented 10 months ago

To update on this: The first issue with retrieving the series id was cleaned up by using the ORM function tec_series() to get the id by the event_post_id: $series_id = tec_series()->where( 'event_post_id', $source->databaseId )->first()->ID;

However, the second issue on hiding subsequent recurrences persists. For now, we are using the Event Calendar's REST API to retrieve events, using the tribe_events_archive_get_args hook to set the tribeHideRecurrence query argument to true.

kidunot89 commented 7 months ago

@hcavanaugh Is this issue persisting in v0.3.1?

hcavanaugh commented 6 months ago

@kidunot89 Tested using GraphQL queries with tribeHideRecurrenceDefault set to true in TEC settings, recurring events return as expected: Only return the next upcoming recurring event in a series. Thank you for the fix and checking on this!

To other readers, note that where: startsAfter must be set to "now" in the query:

events(where: {startsAfter: "now"}) {
    nodes {
      title
      link
      startDate
    }
  }