solspace / craft-calendar

Calendar for Craft: The most reliable and powerful event management plugin for Craft.
http://docs.solspace.com/craft/calendar/v5
Other
15 stars 15 forks source link

GraphQL: loadOcurrences on events displays everything even with limit set in calendar #70

Closed lenchantin closed 3 years ago

lenchantin commented 3 years ago

I have an element on my website where I only need the first three events in a query. I didn't want to have to set an endRange on the event. When I use limit: 3 with loadOccurrences set to true, I get the next three events, but if the event is reoccurring, I get every recurrence of that event thereafter.

Conversely, if I have an event that repeats, the event reoccurs today or in the future, and the loadOccurrences option is set to false, then any event that is repeating will not show if the first date in the chain has already passed.

Here's my graphQL schema (this will load EVERY occurrence of a repeating event, even though I need 3 events total):

query calEvents($slugs: [String]) { solspace_calendar { calendar(handle: $slugs, limit: 3) { name handle events(rangeStart: "Today", loadOccurrences: true) { id title startDate @formatDateTime(format: "l, F jS, Y") endDate @formatDateTime(format: "l, F jS, Y") startTime: startDate @formatDateTime(format: "g:i A") endTime: endDate @formatDateTime(format: "g:i A") allDay multiDay freq ... on events_Event { id bannerImage { title url } } } } } }

Steps to reproduce

  1. Have a calendar with one or several repeating events
  2. run GraphQL in explorer above.

Expected behavior I only want it to return 3 events, even if reoccurring events are set to show. Or, at least show upcoming events that are recurrent.

Craft & Plugin Info (please complete the following information):

Additional context This is for a client who has daily repeating events, as well as fundraising events. I'd like to be able to show the next 3 upcoming events.

gustavs-gutmanis commented 3 years ago

Hi @lenchantin

There was a bug in our GQL which didn't let you use an int value for loadOccurrences, which would explicitly tell Calendar how many occurrences to load for each event.

The fix is currently on dev-master but as a workaround for now you can pass limit to the events query:

query calEvents($slugs: [String]) {
  solspace_calendar {
    calendar(handle: $slugs) {
      name
      handle
      events(rangeStart: "Today", loadOccurrences: true, limit: 3) {
        id
        # ...
      }
    }
  }
}

but once the patch is out or you switch to dev-master, you'll be able to do this instead:

query calEvents($slugs: [String]) {
  solspace_calendar {
    calendar(handle: $slugs) {
      name
      handle
      events(rangeStart: "Today", loadOccurrences: 3) {
        id
        # ...
      }
    }
  }
}
kjmartens commented 3 years ago

This is now fixed in v3.3.4.