Skip to content

Commit

Permalink
Improve error messages + add release.md requirements (#3361)
Browse files Browse the repository at this point in the history
* Improve error messages on after and before argument + add release.me requirement to README

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* add tests + refer to contribution page for contributers

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add working test for the new error messages

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* remove commented out code

---------

Co-authored-by: Sascha Dobbelaere <sd@tweave.tech>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 28, 2024
1 parent c2273ba commit 153cc7b
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ poetry install --with integrations
poetry run pytest
```

This will install all the dependencies (including dev ones) and run the tests.
For all further detail, check out the [Contributing Page](CONTRIBUTING.md)


### Pre commit

Expand Down
4 changes: 4 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Release type: patch

- Improved error message when supplying in incorrect before or after argument with using relay and pagination.
- Add extra PR requirement in README.md
13 changes: 11 additions & 2 deletions strawberry/relay/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,11 +808,20 @@ def resolve_connection(

if after:
after_type, after_parsed = from_base64(after)
assert after_type == PREFIX
if after_type != PREFIX:
# When the base64 hash doesnt exist, the after_type seems to return
# arrayconnEction instead of PREFIX. Let's raise a predictable
# instead of "An unknown error occurred."
raise TypeError("Argument 'after' contains a non-existing value.")

start = int(after_parsed) + 1
if before:
before_type, before_parsed = from_base64(before)
assert before_type == PREFIX
if before_type != PREFIX:
# When the base64 hash doesnt exist, the after_type seems to return
# arrayconnEction instead of PREFIX. Let's raise a predictable
# instead of "An unknown error occurred.
raise TypeError("Argument 'before' contains a non-existing value.")
end = int(before_parsed)

if isinstance(first, int):
Expand Down
50 changes: 50 additions & 0 deletions tests/relay/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -1574,3 +1574,53 @@ class Query:
}
'''
assert str(schema) == textwrap.dedent(expected).strip()


before_after_test_query = """
query fruitsBeforeAfterTest (
$before: String = null,
$after: String = null,
) {
fruits (
before: $before
after: $after
) {
edges {
cursor
node {
id
}
}
}
}
"""


async def test_query_before_error():
"""
Verify if the error raised on a non-existing before hash
raises the correct error
"""
# with pytest.raises(ValueError):
index = to_base64("Fake", 9292292)
result = await schema.execute(
before_after_test_query,
variable_values={"before": index},
)
assert result.errors is not None
assert "Argument 'before' contains a non-existing value" in str(result.errors)


def test_query_after_error():
"""
Verify if the error raised on a non-existing before hash
raises the correct error
"""
index = to_base64("Fake", 9292292)
result = schema.execute_sync(
before_after_test_query,
variable_values={"after": index},
)

assert result.errors is not None
assert "Argument 'after' contains a non-existing value" in str(result.errors)

0 comments on commit 153cc7b

Please sign in to comment.