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 16 forks source link

GraphQL : Can't query for events accross multiple sites #154

Closed denisyilmaz closed 2 years ago

denisyilmaz commented 2 years ago

Hi @kjmartens i just checked the new siteId mentioned in #135 and the problem still exists: if querying for multipel sites in the same request, only one of the sites gets returned. Thus its not possible to get the event from all sites in the same array:

query GetAllRoutes{
  solspace_calendar {
    events(
      siteId: [1,2]
      loadOccurrences: false
    ) {
        id
        siteId
        calendarId
        url
    }
  }
}

Current Response:

{
  "data": {
    "solspace_calendar": {
      "events": [
        {
          "id": 1234,
          "siteId": 2,
          "calendarId": 1,
          "url": "http://localhost/en/some-event"
        }
      ]
    }
  }
}

Expected response:

{
  "data": {
    "solspace_calendar": {
      "events": [
        {
          "id": 1234,
          "siteId": 1,
          "calendarId": 1,
          "url": "http://localhost/de/some-event"
        },
        {
          "id": 1234,
          "siteId": 2,
          "calendarId": 1,
          "url": "http://localhost/en/some-event"
        }
      ]
    }
  }
}
kjmartens commented 2 years ago

Hi @denisyilmaz,

I'm wondering if you noticed this part in the other issue:

While we're aware siteId does not yet work, I've had a developer check into this one, and he's able to make that query (events(site: ["site_one", "site_two"], loadOccurrences: false) {) pull events from both Site 1 and Site 2. He's wondering if maybe you have disabled Site 1 for some of these events? How big is the data you're working with (e.g. 3 events, 300 events, etc) and how sure are you there's nothing else like that or something else interfering? 🙂

denisyilmaz commented 2 years ago

I just tried both variations (siteId and site: []) in our production server again and got an even more unexpected behaviour.

While both languages have around 30 events (without occurences), which I confirmed I am able to query them separately (so both languages are active and available via GraphQL) I actually get one single event of the site: 1 while getting all events of site: 2 when querying for both at the same time.

To make it more clear:

Query 1:

query GetAllRoutes {
  solspace_calendar {
    events(siteId: [2], loadOccurrences: false, limit: 99999) {
      id
      siteId
      calendarId
      url
    }
  }
}

Result: ~30 events for site: 2 being loaded.

Query 2:

query GetAllRoutes {
  solspace_calendar {
    events(siteId: [1], loadOccurrences: false, limit: 99999) {
      id
      siteId
      calendarId
      url
    }
  }
}

Result: ~30 events for site: 1 being loaded.

Query 3:

query GetAllRoutes {
  solspace_calendar {
    events(siteId: [1, 2], loadOccurrences: false, limit: 99999) {
      id
      siteId
      calendarId
      url
    }
  }
}

Result: ~30 events for site: 2 being loaded, only one event from site: 1 being shown

Query 4:

query GetAllRoutes {
  solspace_calendar {
    events(siteId: [2, 1], loadOccurrences: false, limit: 99999) {
      id
      siteId
      calendarId
      url
    }
  }
}

Result: ~30 events for site: 2 being loaded, only one event from site: 1 being shown (same as Query 3)

Edit: the limit: 99999 was added just to be sure that events might not be shown because of pagination. The results are the same when limit is not set

denisyilmaz commented 2 years ago

any updates on this issue?

seandelaney commented 2 years ago

Sorry for the delay @denisyilmaz

I've spent some time looking into your question and what you are wanting to do isn't possible.

That type of query - where users can grab events based on site info doesn't exist. The DB / schema isn't setup to allow us to query at the site level yet. So yeah, this functionality has never actually existed. It's not even possible within the CP. Changing the current site doesn't filter the events list. It's all based on the current calendar.

Events can only be queried by their own GraphQL defined arguments or at the calendar level.

Looking at what arguments exist for queries calendars... it's also not possible to query calendars based on site info either as again that functionality has never existed. The DB / schema relationship between a site and a calendar exists, but there is not code in place for GraphQL to query calendars at the site level.

Could this functionality be added - querying events at the site level? It's doable but having looked at the codebase, it's not a simple or quick change. There is a bit of work involved at the DB / schema level so I can't see it being added in the next release as focus is on bug fixing rather than adding new features. I have spoke to the lead dev though. We'll add this to the backlog. However I don't have any ETA for when it will be done though.

denisyilmaz commented 2 years ago

Hi @seandelaney , thanks for the thorough feedback on this. I already figured that this is contrary to how the calendar is setup. But good to know that my solution aka workaround is the way to go until this feature is implemented:

query GetAllRoutes {
  solspace_calendar {
    events_en: events(siteId: [1], loadOccurrences: false, limit: 99999) {
      id
      siteId
      calendarId
      url
    }
    events_de: events(siteId: [2], loadOccurrences: false, limit: 99999) {
      id
      siteId
      calendarId
      url
    }
  }
}

Edit: maybe the GraphQL Schema could/should be updated that siteId does not allow for an [QueryArgument] but rather a single sideId Int?!

image
kjmartens commented 1 year ago

Hi @denisyilmaz,

We have finally added support for querying multiple site ID's as of Calendar 4.0.7:

query GetAllRoutes {
  solspace_calendar {
    events: events(siteId: ["1", "2", "3"], loadOccurrences: false, limit: 99999) {
      id
      siteId
      title
    }
  }
}