Skip to content

Commit

Permalink
Use consistent ID type for pages and page queries (#350)
Browse files Browse the repository at this point in the history
`pages` expected `graphene.ID` whereas `page` was using `graphene.Int`
  • Loading branch information
estyxx authored Aug 30, 2023
1 parent 37df8d6 commit 8cfb88a
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion docs/general-usage/graphql-types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ The singular ``page`` field accepts the following arguments:

.. code-block:: graphql
id: Int # Can be used on it's own
id: ID # Can be used on it's own
slug: String # Can be used on it's own
urlPath: String # Can be used on it's own
token: String # Must be used with one of the others. Usually contentType
Expand Down
4 changes: 2 additions & 2 deletions grapple/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def inner(cls):
field_type = lambda: registry.models[cls] # noqa: E731
field_query_params = query_params
if field_query_params is None:
field_query_params = {"id": graphene.Int()}
field_query_params = {"id": graphene.ID()}

if issubclass(cls, Page):
field_query_params["slug"] = graphene.Argument(
Expand Down Expand Up @@ -194,7 +194,7 @@ def inner(cls):
field_type = lambda: registry.models[cls] # noqa: E731
field_query_params = query_params
if field_query_params is None:
field_query_params = {"id": graphene.Int()}
field_query_params = {"id": graphene.ID()}

if issubclass(cls, Page):
field_query_params["slug"] = graphene.Argument(
Expand Down
2 changes: 1 addition & 1 deletion grapple/types/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ class Mixin:
)
page = graphene.Field(
PageInterface,
id=graphene.Int(),
id=graphene.ID(),
slug=graphene.String(),
url_path=graphene.Argument(
graphene.String,
Expand Down
2 changes: 1 addition & 1 deletion grapple/types/sites.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SiteObjectType(DjangoObjectType):
)
page = graphene.Field(
PageInterface,
id=graphene.Int(),
id=graphene.ID(),
slug=graphene.String(),
url_path=graphene.String(),
token=graphene.String(),
Expand Down
20 changes: 10 additions & 10 deletions tests/test_blog.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def setUp(self):

def test_blog_page(self):
query = """
query($id: Int) {
query($id: ID) {
page(id: $id) {
... on BlogPage {
title
Expand All @@ -151,7 +151,7 @@ def test_blog_page(self):

def test_related_author_page(self):
query = """
query($id: Int) {
query($id: ID) {
page(id: $id) {
... on BlogPage {
author {
Expand All @@ -171,7 +171,7 @@ def test_related_author_page(self):

def get_blocks_from_body(self, block_type, block_query="rawValue", page_id=None):
query = f"""
query($id: Int) {{
query($id: ID) {{
page(id: $id) {{
... on BlogPage {{
body {{
Expand Down Expand Up @@ -248,7 +248,7 @@ def test_streamfield_richtextblock(self):

def test_richtext(self):
query = """
query($id: Int) {
query($id: ID) {
page(id: $id) {
... on BlogPage {
summary
Expand Down Expand Up @@ -471,7 +471,7 @@ def test_blog_body_objectives(self):

def test_blog_embed(self):
query = """
query($id: Int) {
query($id: ID) {
page(id: $id) {
... on BlogPage {
body {
Expand Down Expand Up @@ -656,7 +656,7 @@ def test_blog_body_snippetchooserblock_person(self):
# Next 2 tests are used to test the Collection API, both ForeignKey and nested field extraction.
def test_blog_page_related_links(self):
query = """
query($id: Int) {
query($id: ID) {
page(id: $id) {
... on BlogPage {
relatedLinks {
Expand All @@ -676,7 +676,7 @@ def test_blog_page_related_links(self):

def test_blog_page_related_urls(self):
query = """
query($id: Int) {
query($id: ID) {
page(id: $id) {
... on BlogPage {
relatedUrls
Expand All @@ -696,7 +696,7 @@ def test_blog_page_paginated_authors(self):
per_page = 5

query = """
query ($id: Int, $page: PositiveInt, $perPage: PositiveInt) {
query ($id: ID, $page: PositiveInt, $perPage: PositiveInt) {
page(id: $id) {
... on BlogPage {
paginatedAuthors(page: $page, perPage: $perPage) {
Expand Down Expand Up @@ -905,7 +905,7 @@ def test_singular_blog_page_query(self):

def test_blog_page_tags(self):
query = """
query($id: Int) {
query($id: ID) {
page(id: $id) {
... on BlogPage {
tags {
Expand Down Expand Up @@ -1057,7 +1057,7 @@ def test_graphqlfield_method_with_extra_arg_in_structblock(self):

def test_custom_property(self):
query = """
query($id: Int) {
query($id: ID) {
page(id: $id) {
... on BlogPage {
customProperty
Expand Down
10 changes: 5 additions & 5 deletions tests/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def test_query_field_plural(self):

def test_query_field(self):
query = """
query ($id: Int, $urlPath: String, $slug: String) {
query ($id: ID, $urlPath: String, $slug: String) {
post(id: $id, urlPath: $urlPath, slug: $slug) {
id
urlPath
Expand Down Expand Up @@ -148,7 +148,7 @@ def test_query_field(self):

def test_multiple_middleware(self):
query = """
query ($id: Int) {
query ($id: ID) {
middlewareModel(id: $id) {
id
}
Expand Down Expand Up @@ -178,7 +178,7 @@ def setUp(self):

def test_paginated_query_field(self):
query = """
query ($id: Int, $urlPath: String, $slug: String) {
query ($id: ID, $urlPath: String, $slug: String) {
blogPage(id: $id, urlPath: $urlPath, slug: $slug) {
id
urlPath
Expand Down Expand Up @@ -476,7 +476,7 @@ def test_query_field_with_logged_in_user_should_return_nothing(self):
"""

query = """
query ($id: Int) {
query ($id: ID) {
post(id: $id) {
id
urlPath
Expand Down Expand Up @@ -514,7 +514,7 @@ def test_paginated_query_field_with_logged_in_user_should_return_nothing(self):
The query field was registered with the anonymous middleware, i.e. requires only anonymous users
"""
query = """
query ($id: Int) {
query ($id: ID) {
blogPage(id: $id) {
id
urlPath
Expand Down
2 changes: 1 addition & 1 deletion tests/test_grapple.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def test_pages_content_type_filter(self):

def test_page(self):
query = """
query($id: Int) {
query($id: ID) {
page(id: $id) {
contentType
parent {
Expand Down

0 comments on commit 8cfb88a

Please sign in to comment.