mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-25 19:13:57 +03:00
Merge pull request #1412 from loft-orbital/issue-#1394_fix-required
This commit is contained in:
commit
03277a5512
|
@ -49,7 +49,7 @@ type Faction implements Node {
|
||||||
name: String
|
name: String
|
||||||
|
|
||||||
"""The ships used by the faction."""
|
"""The ships used by the faction."""
|
||||||
ships(before: String = null, after: String = null, first: Int = null, last: Int = null): ShipConnection
|
ships(before: String, after: String, first: Int, last: Int): ShipConnection
|
||||||
}
|
}
|
||||||
|
|
||||||
"""An object with an ID"""
|
"""An object with an ID"""
|
||||||
|
|
|
@ -86,6 +86,8 @@ class Node(AbstractNode):
|
||||||
def get_node_from_global_id(cls, info, global_id, only_type=None):
|
def get_node_from_global_id(cls, info, global_id, only_type=None):
|
||||||
try:
|
try:
|
||||||
_type, _id = cls.from_global_id(global_id)
|
_type, _id = cls.from_global_id(global_id)
|
||||||
|
if not _type:
|
||||||
|
raise ValueError("Invalid Global ID")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
f'Unable to parse global ID "{global_id}". '
|
f'Unable to parse global ID "{global_id}". '
|
||||||
|
|
36
graphene/tests/issues/test_1394.py
Normal file
36
graphene/tests/issues/test_1394.py
Normal file
|
@ -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."
|
||||||
|
)
|
|
@ -1,4 +1,5 @@
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
from graphql import Undefined
|
||||||
|
|
||||||
from .dynamic import Dynamic
|
from .dynamic import Dynamic
|
||||||
from .mountedtype import MountedType
|
from .mountedtype import MountedType
|
||||||
|
@ -41,7 +42,7 @@ class Argument(MountedType):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
type_,
|
type_,
|
||||||
default_value=None,
|
default_value=Undefined,
|
||||||
description=None,
|
description=None,
|
||||||
name=None,
|
name=None,
|
||||||
required=False,
|
required=False,
|
||||||
|
|
|
@ -229,11 +229,11 @@ def test_query_arguments():
|
||||||
|
|
||||||
result = test_schema.execute("{ test }", None)
|
result = test_schema.execute("{ test }", None)
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
assert result.data == {"test": '[null,{"a_str":null,"a_int":null}]'}
|
assert result.data == {"test": "[null,{}]"}
|
||||||
|
|
||||||
result = test_schema.execute('{ test(aStr: "String!") }', "Source!")
|
result = test_schema.execute('{ test(aStr: "String!") }', "Source!")
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
assert result.data == {"test": '["Source!",{"a_str":"String!","a_int":null}]'}
|
assert result.data == {"test": '["Source!",{"a_str":"String!"}]'}
|
||||||
|
|
||||||
result = test_schema.execute('{ test(aInt: -123, aStr: "String!") }', "Source!")
|
result = test_schema.execute('{ test(aInt: -123, aStr: "String!") }', "Source!")
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
|
@ -258,7 +258,7 @@ def test_query_input_field():
|
||||||
|
|
||||||
result = test_schema.execute("{ test }", None)
|
result = test_schema.execute("{ test }", None)
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
assert result.data == {"test": '[null,{"a_input":null}]'}
|
assert result.data == {"test": "[null,{}]"}
|
||||||
|
|
||||||
result = test_schema.execute('{ test(aInput: {aField: "String!"} ) }', "Source!")
|
result = test_schema.execute('{ test(aInput: {aField: "String!"} ) }', "Source!")
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
from graphql import Undefined
|
||||||
from graphql.type import (
|
from graphql.type import (
|
||||||
GraphQLArgument,
|
GraphQLArgument,
|
||||||
GraphQLEnumType,
|
GraphQLEnumType,
|
||||||
|
@ -244,7 +245,9 @@ def test_objecttype_camelcase():
|
||||||
foo_field = fields["fooBar"]
|
foo_field = fields["fooBar"]
|
||||||
assert isinstance(foo_field, GraphQLField)
|
assert isinstance(foo_field, GraphQLField)
|
||||||
assert foo_field.args == {
|
assert foo_field.args == {
|
||||||
"barFoo": GraphQLArgument(GraphQLString, default_value=None, out_name="bar_foo")
|
"barFoo": GraphQLArgument(
|
||||||
|
GraphQLString, default_value=Undefined, out_name="bar_foo"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -267,7 +270,7 @@ def test_objecttype_camelcase_disabled():
|
||||||
assert isinstance(foo_field, GraphQLField)
|
assert isinstance(foo_field, GraphQLField)
|
||||||
assert foo_field.args == {
|
assert foo_field.args == {
|
||||||
"bar_foo": GraphQLArgument(
|
"bar_foo": GraphQLArgument(
|
||||||
GraphQLString, default_value=None, out_name="bar_foo"
|
GraphQLString, default_value=Undefined, out_name="bar_foo"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -94,6 +94,7 @@ TEST_DATA = {
|
||||||
],
|
],
|
||||||
"movies": {
|
"movies": {
|
||||||
"1198359": {
|
"1198359": {
|
||||||
|
"id": "1198359",
|
||||||
"name": "King Arthur: Legend of the Sword",
|
"name": "King Arthur: Legend of the Sword",
|
||||||
"synopsis": (
|
"synopsis": (
|
||||||
"When the child Arthur's father is murdered, Vortigern, "
|
"When the child Arthur's father is murdered, Vortigern, "
|
||||||
|
@ -159,7 +160,7 @@ def test_example_end_to_end():
|
||||||
"date": "2017-05-19",
|
"date": "2017-05-19",
|
||||||
"movie": {
|
"movie": {
|
||||||
"__typename": "Movie",
|
"__typename": "Movie",
|
||||||
"id": "TW92aWU6Tm9uZQ==",
|
"id": "TW92aWU6MTE5ODM1OQ==",
|
||||||
"name": "King Arthur: Legend of the Sword",
|
"name": "King Arthur: Legend of the Sword",
|
||||||
"synopsis": (
|
"synopsis": (
|
||||||
"When the child Arthur's father is murdered, Vortigern, "
|
"When the child Arthur's father is murdered, Vortigern, "
|
||||||
|
@ -172,7 +173,7 @@ def test_example_end_to_end():
|
||||||
"__typename": "Event",
|
"__typename": "Event",
|
||||||
"id": "RXZlbnQ6MjM0",
|
"id": "RXZlbnQ6MjM0",
|
||||||
"date": "2017-05-20",
|
"date": "2017-05-20",
|
||||||
"movie": {"__typename": "Movie", "id": "TW92aWU6Tm9uZQ=="},
|
"movie": {"__typename": "Movie", "id": "TW92aWU6MTE5ODM1OQ=="},
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user