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

Add content type filter for the pages query #31

Closed mansrz closed 3 years ago

mansrz commented 4 years ago

Hi, thanks for help me with last problem Now, i don't know if it is a bug or concept error mine, but if you can help me please can be help for other

I tried to get a page specific with filter by contenttype but i got null response, so i have to query "pages" instead "page" and can't filter by contenttype this cause me get many "{}" DeepinScreenshot_select-area_20191103135934 DeepinScreenshot_select-area_20191103135955

Example query: { page(contentType:"home.AboutPage"){ ... on AboutPage { contentType id } }

SamuelTaylor001 commented 4 years ago

@mansrz why did you close this? Did you find a solution? I am getting the same issue with the following query

query MyQuery { wagtail { pages { ... on NewsPage { id intro title } } } }

I realise that this could be fixed on the client side however, it defeats the purpose of GraphQL if we are forced to process unnecessary data.

Can we reopen this?

mansrz commented 4 years ago

I would believe that it should be opened, I closed it because I "solved it" at the moment doing the query by id but isn't the correct solution

NathHorrigan commented 4 years ago

I can see how confusing this could be...

What do you think of the following @SamuelTaylor001:

page (contentType: "blogs.BlogPage") {
    ... on BlogPage {
         title
    }
}

will return the first result based on that contentType and will be the equivalent of the following ORM query: BlogPage.objects.first()

isolationism commented 3 years ago

I've added a PR for a solution that uses the pageType — I think contentType is something slightly different.

I am also filtering out the application prefix (i.e. the 'blog.' part of 'blog.BlogPage') to match the declared pageType returned in a query, but wonder if this isn't going to cause problems if two apps have the same model name.

zerolab commented 3 years ago

The reason the { page(contentType:"home.AboutPage"){ ... on AboutPage { contentType id } } query fails is that the content type filter only kicks in if there is a preview token - https://github.com/GrappleGQL/wagtail-grapple/blob/master/grapple/types/pages.py#L197-L209

@isolationism thank you for #144 -- I think we should stick to content type as a filter to avoid namespace clashes.

Will open a new PR to fix the filter on content type (an credit you on it as well, @isolationism )

zerolab commented 3 years ago

https://github.com/GrappleGQL/wagtail-grapple/pull/147

all reviews are welcome