torchbox / wagtail-grapple

A Wagtail app that makes building GraphQL endpoints a breeze!
https://wagtail-grapple.readthedocs.io/en/latest/
Other
152 stars 57 forks source link

Multi-site support #114

Closed leewesleyv closed 3 years ago

leewesleyv commented 3 years ago

Issue It would be nice if wagtail-grapple would support a multi-site setup. E.g., there currently is no support for filtering page/pages based on a site. In a multi-site scenario, duplicate slugs can exist, and fetching a page would result in no results from the page query.

My idea Add a filter to the page/pages query. We could for example introduce hostname as an optional parameter for these queries and filter the page QuerySet that way.

Open questions

zerolab commented 3 years ago

The simplest solution would be to do what the REST API does -- filter the querysets based on the request site - https://github.com/wagtail/wagtail/blob/8c306910dd86e09cea11196715da47c6a54c722b/wagtail/api/v2/views.py#L418 that way siteA.com/api returns everything that falls under Site a, wheas siteB.com/api returns pages under Site B

Additionally, add a new site query that you can wrap the other querie in. e.g.

{
    siteA: site(id: 123) {
        pages { ... } 
    }

   siteB: site(hostname: "...") {
        pages { ... }
    }
}
leewesleyv commented 3 years ago

Thank you @zerolab for the input. I will open a PR when I have some time 😃