Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only retrieve the pages that are registered in the settings #226

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

jffr
Copy link

@jffr jffr commented Apr 10, 2022

A small fix for removing pages that are not registered in the GRAPPLE settings.

Having a project with two apps (for example home and blog). You'll get an error when we only expose the 'blog' app. Which returns the following output:

{
  "errors": [
    {
      "message": "Expected value of type \"Page\" but got: HomePage.",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ]
    }
  ],
  "data": null
}

Where we have the following settings:

INSTALLED_APPS = [
    'home',
    'search',
    'blog',
    ....
]

GRAPPLE = {
    "APPS": ["blog"],
    "EXPOSE_GRAPHIQL": True
}

And the query:

{
  pages {
    id
    title
    pageType
    slug
  }
}

@zerolab
Copy link
Member

zerolab commented Apr 10, 2022

Hey @jffr, thank you for this.
Could you add a test for the changes, please?

@jffr
Copy link
Author

jffr commented Apr 10, 2022

@zerolab Thank you for the feedback! I have fixed the failing tests and introduced two new tests for the app setting:

  • Getting no pages when there are no apps configured;
  • Getting all the (home related) pages when the app 'home' is configured;

I think we're missing one last test, which is a query where we get more pages from different apps. But in order to write that test we have to include a new demo app within the example project. Do you think it is worth it or are the test cases explained above good enough?

Copy link
Member

@zerolab zerolab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @jffr,

thank you for this. left a few notes/suggestions

example/example/tests/test_grapple.py Show resolved Hide resolved
Comment on lines +276 to +280
# Retrieve only the pages that are registered in the settings
content_types = ContentType.objects.filter(
app_label__in=grapple_settings.APPS
)
pages = pages.filter(content_type__in=content_types)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be simplified as:

pages = pages.filter(content_type__app_label__in=grapple_settings.APPS)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


pages_data = executed["data"]["pages"]
self.assertEquals(pages_data[0]["contentType"], "home.HomePage")
self.assertEquals(pages_data[1]["contentType"], "home.BlogPage")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest adding news_post = NewsPageFactory(parent=self.home) before the execute and add a check to ensure the news page doesn't appear in the results

@@ -0,0 +1,22 @@
# Generated by Django 3.2.13 on 2022-04-24 07:18
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see the changes that triggered this migration 🤔

@dopry
Copy link
Collaborator

dopry commented May 12, 2023

@jffr do you still have any inclination to work on this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants