This repository has been archived by the owner on Sep 6, 2023. It is now read-only.
forked from graphql-python/graphene
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from loft-orbital/issue-#1394_fix-required
fix: default value for argument should be Undefined (Issue graphql-python#1394)
- Loading branch information
Showing
7 changed files
with
52 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from ...types import ObjectType, Schema, String, NonNull | ||
|
||
|
||
class Query(ObjectType): | ||
hello = String(input=NonNull(String)) | ||
|
||
def resolve_hello(self, info, input): | ||
if input == "nothing": | ||
return None | ||
return f"Hello {input}!" | ||
|
||
|
||
schema = Schema(query=Query) | ||
|
||
|
||
def test_required_input_provided(): | ||
""" | ||
Test that a required argument works when provided. | ||
""" | ||
input_value = "Potato" | ||
result = schema.execute('{ hello(input: "%s") }' % input_value) | ||
assert not result.errors | ||
assert result.data == {"hello": "Hello Potato!"} | ||
|
||
|
||
def test_required_input_missing(): | ||
""" | ||
Test that a required argument raised an error if not provided. | ||
""" | ||
result = schema.execute("{ hello }") | ||
assert result.errors | ||
assert len(result.errors) == 1 | ||
assert ( | ||
result.errors[0].message | ||
== "Field 'hello' argument 'input' of type 'String!' is required, but it was not provided." | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters