Exemplo n.º 1
0
def test_parses_null_value_in_list():
    result = parse('{ fieldWithObjectInput(input: {b: ["A", null, "C"], c: "C"}) }')
    assert result == ast.Document(
        definitions=[
            ast.OperationDefinition(
                operation='query', name=None, variable_definitions=None, directives=[],
                selection_set=ast.SelectionSet(
                    selections=[
                        ast.Field(
                            alias=None,
                            name=ast.Name(value=u'fieldWithObjectInput'),
                            directives=[],
                            selection_set=None,
                            arguments=[
                                ast.Argument(
                                    name=ast.Name(value=u'input'),
                                    value=ast.ObjectValue(
                                        fields=[
                                            ast.ObjectField(
                                                name=ast.Name(value=u'b'),
                                                value=ast.ListValue(
                                                    values=[
                                                        ast.StringValue(value=u'A'),
                                                        ast.NullValue(),
                                                        ast.StringValue(value=u'C'),
                                                    ],
                                                ),
                                            ),
                                            ast.ObjectField(
                                                name=ast.Name(value=u'c'),
                                                value=ast.StringValue(value=u'C'),
                                            ),
                                        ]
                                    ),
                                ),
                            ],
                        ),
                    ],
                ),
            ),
        ],
    )
Exemplo n.º 2
0
def value_node_from_pyvalue(val: object):
    if isinstance(val, str):
        val = val.replace('\\', '\\\\')
        value = eql_quote.quote_literal(val)
        return gql_ast.StringValue(value=value[1:-1])
    elif isinstance(val, bool):
        return gql_ast.BooleanValue(value=bool(val))
    elif isinstance(val, int):
        return gql_ast.IntValue(value=str(val))
    elif isinstance(val, float):
        return gql_ast.FloatValue(value=str(val))
    elif isinstance(val, list):
        return gql_ast.ListValue(
            values=[value_node_from_pyvalue(v) for v in val])
    elif isinstance(val, dict):
        return gql_ast.ObjectValue(fields=[
            gql_ast.ObjectField(name=n, value=value_node_from_pyvalue(v))
            for n, v in val.items()
        ])
    else:
        raise ValueError(f'unexpected constant type: {type(val)!r}')
Exemplo n.º 3
0
def test_converts_array_values_to_list_asts():
    assert ast_from_value(["FOO", "BAR"]) == ast.ListValue(
        values=[ast.StringValue("FOO"),
                ast.StringValue("BAR")])
Exemplo n.º 4
0
def serialize_list(serializer, list_values):
    assert isinstance(list_values,
                      Iterable), 'Expected iterable, received "{}"'.format(
                          repr(list_values))
    return ast.ListValue(values=[serializer(v) for v in list_values])
def test_converts_array_values_to_list_asts():
    assert ast_from_value(['FOO', 'BAR']) == ast.ListValue(
        values=[ast.StringValue('FOO'),
                ast.StringValue('BAR')])