-
Notifications
You must be signed in to change notification settings - Fork 819
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add default param _variables to parse_literal #1419
- Loading branch information
Showing
7 changed files
with
64 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import pytest | ||
|
||
from ...types.base64 import Base64 | ||
from ...types.datetime import Date, DateTime | ||
from ...types.decimal import Decimal | ||
from ...types.generic import GenericScalar | ||
from ...types.json import JSONString | ||
from ...types.objecttype import ObjectType | ||
from ...types.scalars import ID, BigInt, Boolean, Float, Int, String | ||
from ...types.schema import Schema | ||
from ...types.uuid import UUID | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"input_type,input_value", | ||
[ | ||
(Date, '"2022-02-02"'), | ||
(GenericScalar, '"foo"'), | ||
(Int, "1"), | ||
(BigInt, "12345678901234567890"), | ||
(Float, "1.1"), | ||
(String, '"foo"'), | ||
(Boolean, "true"), | ||
(ID, "1"), | ||
(DateTime, '"2022-02-02T11:11:11"'), | ||
(UUID, '"cbebbc62-758e-4f75-a890-bc73b5017d81"'), | ||
(Decimal, "1.1"), | ||
(JSONString, '{key:"foo",value:"bar"}'), | ||
(Base64, '"Q2hlbG8gd29ycmxkCg=="'), | ||
], | ||
) | ||
def test_parse_literal_with_variables(input_type, input_value): | ||
# input_b needs to be evaluated as literal while the variable dict for | ||
# input_a is passed along. | ||
|
||
class Query(ObjectType): | ||
generic = GenericScalar(input_a=GenericScalar(), input_b=input_type()) | ||
|
||
def resolve_generic(self, info, input_a=None, input_b=None): | ||
return input | ||
|
||
schema = Schema(query=Query) | ||
|
||
query = f""" | ||
query Test($a: GenericScalar){{ | ||
generic(inputA: $a, inputB: {input_value}) | ||
}} | ||
""" | ||
result = schema.execute( | ||
query, | ||
variables={"a": "bar"}, | ||
) | ||
assert not result.errors |
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
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