|
| 1 | +import pytest |
| 2 | + |
| 3 | +from ...types.base64 import Base64 |
| 4 | +from ...types.datetime import Date, DateTime |
| 5 | +from ...types.decimal import Decimal |
| 6 | +from ...types.generic import GenericScalar |
| 7 | +from ...types.json import JSONString |
| 8 | +from ...types.objecttype import ObjectType |
| 9 | +from ...types.scalars import ID, BigInt, Boolean, Float, Int, String |
| 10 | +from ...types.schema import Schema |
| 11 | +from ...types.uuid import UUID |
| 12 | + |
| 13 | + |
| 14 | +@pytest.mark.parametrize( |
| 15 | + "input_type,input_value", |
| 16 | + [ |
| 17 | + (Date, '"2022-02-02"'), |
| 18 | + (GenericScalar, '"foo"'), |
| 19 | + (Int, "1"), |
| 20 | + (BigInt, "12345678901234567890"), |
| 21 | + (Float, "1.1"), |
| 22 | + (String, '"foo"'), |
| 23 | + (Boolean, "true"), |
| 24 | + (ID, "1"), |
| 25 | + (DateTime, '"2022-02-02T11:11:11"'), |
| 26 | + (UUID, '"cbebbc62-758e-4f75-a890-bc73b5017d81"'), |
| 27 | + (Decimal, "1.1"), |
| 28 | + (JSONString, '{key:"foo",value:"bar"}'), |
| 29 | + (Base64, '"Q2hlbG8gd29ycmxkCg=="'), |
| 30 | + ], |
| 31 | +) |
| 32 | +def test_parse_literal_with_variables(input_type, input_value): |
| 33 | + # input_b needs to be evaluated as literal while the variable dict for |
| 34 | + # input_a is passed along. |
| 35 | + |
| 36 | + class Query(ObjectType): |
| 37 | + generic = GenericScalar(input_a=GenericScalar(), input_b=input_type()) |
| 38 | + |
| 39 | + def resolve_generic(self, info, input_a=None, input_b=None): |
| 40 | + return input |
| 41 | + |
| 42 | + schema = Schema(query=Query) |
| 43 | + |
| 44 | + query = f""" |
| 45 | + query Test($a: GenericScalar){{ |
| 46 | + generic(inputA: $a, inputB: {input_value}) |
| 47 | + }} |
| 48 | + """ |
| 49 | + result = schema.execute( |
| 50 | + query, |
| 51 | + variables={"a": "bar"}, |
| 52 | + ) |
| 53 | + assert not result.errors |
0 commit comments