Ejemplo n.º 1
0
def test_does_not_allow_unknown_types_to_be_used_as_values():
    doc = '''
        query q($input: UnknownType!) {
          fieldWithObjectInput(input: $input)
        }
    '''
    ast = parse(doc)
    with raises(GraphQLError) as excinfo:
        execute(schema, None, ast)
    e = excinfo.value
Ejemplo n.º 2
0
def test_does_not_allow_non_null_lists_to_be_null():
    doc = '''
        query q($input:[String]!) {
          nnList(input: $input)
        }
    '''
    ast = parse(doc)
    with raises(GraphQLError) as excinfo:
        execute(schema, None, ast, None, {'input': None})
    e = excinfo.value
Ejemplo n.º 3
0
def test_does_not_allow_unknown_types_to_be_used_as_values():
    doc = '''
        query q($input: UnknownType!) {
          fieldWithObjectInput(input: $input)
        }
    '''
    ast = parse(doc)
    with raises(GraphQLError) as excinfo:
        execute(schema, None, ast)
    e = excinfo.value
Ejemplo n.º 4
0
def test_does_not_allow_non_null_lists_of_non_nulls_to_contain_null():
    doc = '''
        query q($input:[String!]!) {
          nnListNN(input: $input)
        }
    '''
    ast = parse(doc)
    with raises(GraphQLError) as excinfo:
        execute(schema, None, ast, None, {'input': ['A', None, 'B']})
    e = excinfo.value
Ejemplo n.º 5
0
def test_does_not_allow_non_null_lists_to_be_null():
    doc = '''
        query q($input:[String]!) {
          nnList(input: $input)
        }
    '''
    ast = parse(doc)
    with raises(GraphQLError) as excinfo:
        execute(schema, None, ast, None, {'input': None})
    e = excinfo.value
Ejemplo n.º 6
0
def test_does_not_allow_non_nullable_inputs_to_be_set_to_null_in_a_variable():
    doc = '''
        query SetsNonNullable($value: String!) {
          fieldWithNonNullableStringInput(input: $value)
        }
    '''
    ast = parse(doc)
    with raises(GraphQLError) as excinfo:
        execute(schema, None, ast, None, {'value': None})
    e = excinfo.value
Ejemplo n.º 7
0
def test_does_not_allow_non_nullable_inputs_to_be_set_to_null_in_a_variable():
    doc = '''
        query SetsNonNullable($value: String!) {
          fieldWithNonNullableStringInput(input: $value)
        }
    '''
    ast = parse(doc)
    with raises(GraphQLError) as excinfo:
        execute(schema, None, ast, None, {'value': None})
    e = excinfo.value
Ejemplo n.º 8
0
def test_does_not_allow_non_null_lists_of_non_nulls_to_contain_null():
    doc = '''
        query q($input:[String!]!) {
          nnListNN(input: $input)
        }
    '''
    ast = parse(doc)
    with raises(GraphQLError) as excinfo:
        execute(schema, None, ast, None, {'input': ['A', None, 'B']})
    e = excinfo.value
Ejemplo n.º 9
0
def test_errors_on_incorrect_type():
    doc = '''
    query q($input:TestInputObject) {
        fieldWithObjectInput(input: $input)
    }
    '''
    params = {'input': 'foo bar'}
    ast = parse(doc)
    with raises(GraphQLError) as excinfo:
        execute(schema, None, ast, None, params)
    e = excinfo.value
Ejemplo n.º 10
0
def test_errors_on_omission_of_nested_non_null():
    doc = '''
    query q($input:TestInputObject) {
        fieldWithObjectInput(input: $input)
    }
    '''
    params = {'input': {'a': 'foo', 'b': 'bar'}}
    ast = parse(doc)
    with raises(GraphQLError) as excinfo:
        execute(schema, None, ast, None, params)
    e = excinfo.value
Ejemplo n.º 11
0
def test_errors_on_addition_of_unknown_input_field():
    doc = '''
    query q($input:TestInputObject) {
        fieldWithObjectInput(input: $input)
    }
    '''
    params = {'input': {'a': 'foo', 'b': 'bar', 'c': 'baz', 'd': 'dog'}}
    ast = parse(doc)
    with raises(GraphQLError) as excinfo:
        execute(schema, None, ast, None, params)
    e = excinfo.value
Ejemplo n.º 12
0
def test_errors_on_addition_of_unknown_input_field():
    doc = '''
    query q($input:TestInputObject) {
        fieldWithObjectInput(input: $input)
    }
    '''
    params = {'input': {'a': 'foo', 'b': 'bar', 'c': 'baz', 'd': 'dog'}}
    ast = parse(doc)
    with raises(GraphQLError) as excinfo:
        execute(schema, None, ast, None, params)
    e = excinfo.value
Ejemplo n.º 13
0
def test_errors_on_omission_of_nested_non_null():
    doc = '''
    query q($input:TestInputObject) {
        fieldWithObjectInput(input: $input)
    }
    '''
    params = {'input': {'a': 'foo', 'b': 'bar'}}
    ast = parse(doc)
    with raises(GraphQLError) as excinfo:
        execute(schema, None, ast, None, params)
    e = excinfo.value
Ejemplo n.º 14
0
def test_errors_on_incorrect_type():
    doc = '''
    query q($input:TestInputObject) {
        fieldWithObjectInput(input: $input)
    }
    '''
    params = {'input': 'foo bar'}
    ast = parse(doc)
    with raises(GraphQLError) as excinfo:
        execute(schema, None, ast, None, params)
    e = excinfo.value
Ejemplo n.º 15
0
def test_when_nullable_variable_provided():
    ast = parse('''query optionalVariable($optional: String) {
        fieldWithDefaultArgumentValue(input: $optional)
    }''')
    result = execute(schema, None, ast)
    assert not result.errors
    assert result.data == {'fieldWithDefaultArgumentValue': '"Hello World"'}
Ejemplo n.º 16
0
def test_when_argument_provided_cannot_be_coerced():
    ast = parse('''{
        fieldWithDefaultArgumentValue(input: WRONG_TYPE)
    }''')
    result = execute(schema, None, ast)
    assert not result.errors
    assert result.data == {'fieldWithDefaultArgumentValue': '"Hello World"'}
Ejemplo n.º 17
0
def test_when_argument_provided_cannot_be_coerced():
    ast = parse('''{
        fieldWithDefaultArgumentValue(input: WRONG_TYPE)
    }''')
    result = execute(schema, None, ast)
    assert not result.errors
    assert result.data == {'fieldWithDefaultArgumentValue': '"Hello World"'}
Ejemplo n.º 18
0
def test_when_nullable_variable_provided():
    ast = parse('''query optionalVariable($optional: String) {
        fieldWithDefaultArgumentValue(input: $optional)
    }''')
    result = execute(schema, None, ast)
    assert not result.errors
    assert result.data == {'fieldWithDefaultArgumentValue': '"Hello World"'}
Ejemplo n.º 19
0
def test_allows_non_null_lists_to_contain_null():
    doc = '''
        query q($input:[String]!) {
          nnList(input: $input)
        }
    '''
    ast = parse(doc)
    result = execute(schema, None, ast, None, {'input': ['A', None, 'B']})
    assert not result.errors
    assert result.data == {'nnList': '["A", null, "B"]'}
Ejemplo n.º 20
0
def test_allows_lists_to_contain_values():
    doc = '''
        query q($input:[String]) {
          list(input: $input)
        }
    '''
    ast = parse(doc)
    result = execute(schema, None, ast, None, {'input': ['A']})
    assert not result.errors
    assert result.data == {'list': '["A"]'}
Ejemplo n.º 21
0
def test_allows_non_null_lists_of_non_nulls_to_contain_values():
    doc = '''
        query q($input:[String!]!) {
          nnListNN(input: $input)
        }
    '''
    ast = parse(doc)
    result = execute(schema, None, ast, None, {'input': ['A']})
    assert not result.errors
    assert result.data == {'nnListNN': '["A"]'}
Ejemplo n.º 22
0
def test_allows_lists_of_non_nulls_to_be_null():
    doc = '''
        query q($input:[String!]) {
          listNN(input: $input)
        }
    '''
    ast = parse(doc)
    result = execute(schema, None, ast, None, {'input': None})
    assert not result.errors
    assert result.data == {'listNN': 'null'}
Ejemplo n.º 23
0
def test_inline_does_not_use_incorrect_value():
    doc = '''
    {
        fieldWithObjectInput(input: ["foo", "bar", "baz"])
    }
    '''
    ast = parse(doc)
    result = execute(schema, None, ast)
    assert not result.errors
    assert json.loads(result.data['fieldWithObjectInput']) is None
Ejemplo n.º 24
0
def test_allows_lists_of_non_nulls_to_be_null():
    doc = '''
        query q($input:[String!]) {
          listNN(input: $input)
        }
    '''
    ast = parse(doc)
    result = execute(schema, None, ast, None, {'input': None})
    assert not result.errors
    assert result.data == {'listNN': 'null'}
Ejemplo n.º 25
0
def test_allows_non_null_lists_of_non_nulls_to_contain_values():
    doc = '''
        query q($input:[String!]!) {
          nnListNN(input: $input)
        }
    '''
    ast = parse(doc)
    result = execute(schema, None, ast, None, {'input': ['A']})
    assert not result.errors
    assert result.data == {'nnListNN': '["A"]'}
Ejemplo n.º 26
0
def test_inline_does_not_use_incorrect_value():
    doc = '''
    {
        fieldWithObjectInput(input: ["foo", "bar", "baz"])
    }
    '''
    ast = parse(doc)
    result = execute(schema, None, ast)
    assert not result.errors
    assert json.loads(result.data['fieldWithObjectInput']) is None
Ejemplo n.º 27
0
def test_allows_lists_to_contain_values():
    doc = '''
        query q($input:[String]) {
          list(input: $input)
        }
    '''
    ast = parse(doc)
    result = execute(schema, None, ast, None, {'input': ['A']})
    assert not result.errors
    assert result.data == {'list': '["A"]'}
Ejemplo n.º 28
0
def test_allows_non_null_lists_to_contain_null():
    doc = '''
        query q($input:[String]!) {
          nnList(input: $input)
        }
    '''
    ast = parse(doc)
    result = execute(schema, None, ast, None, {'input': ['A', None, 'B']})
    assert not result.errors
    assert result.data == {'nnList': '["A", null, "B"]'}
Ejemplo n.º 29
0
def test_passes_along_null_for_non_nullable_inputs_if_explicitly_set_in_the_query():
    doc = '''
    {
        fieldWithNonNullableStringInput
    }
    '''
    ast = parse(doc)
    result = execute(schema, None, ast)
    assert not result.errors
    assert result.data == \
           {"fieldWithNonNullableStringInput": 'null'}
Ejemplo n.º 30
0
def test_allows_non_nullable_inputs_to_be_set_to_a_value_directly():
    doc = '''
        {
          fieldWithNonNullableStringInput(input: "a")
        }
    '''
    ast = parse(doc)
    result = execute(schema, None, ast)
    assert not result.errors
    assert result.data == \
           {"fieldWithNonNullableStringInput": '"a"'}
Ejemplo n.º 31
0
def test_allows_non_nullable_inputs_to_be_set_to_a_value_in_a_variable():
    doc = '''
        query SetsNonNullable($value: String!) {
          fieldWithNonNullableStringInput(input: $value)
        }
    '''
    ast = parse(doc)
    result = execute(schema, None, ast, None, {'value': 'a'})
    assert not result.errors
    assert result.data == \
           {"fieldWithNonNullableStringInput": '"a"'}
Ejemplo n.º 32
0
def test_allows_nullable_inputs_to_be_omitted():
    doc = '''
    {
        fieldWithNullableStringInput
    }
    '''
    ast = parse(doc)
    result = execute(schema, None, ast)
    assert not result.errors
    assert result.data == \
           {"fieldWithNullableStringInput": "null"}
Ejemplo n.º 33
0
def test_allows_nullable_inputs_to_be_omitted_in_an_unlisted_variable():
    doc = '''
    query SetsNullable {
        fieldWithNullableStringInput(input: $value)
    }
    '''
    ast = parse(doc)
    result = execute(schema, None, ast)
    assert not result.errors
    assert result.data == \
           {"fieldWithNullableStringInput": "null"}
Ejemplo n.º 34
0
def test_allows_nullable_inputs_to_be_omitted():
    doc = '''
    {
        fieldWithNullableStringInput
    }
    '''
    ast = parse(doc)
    result = execute(schema, None, ast)
    assert not result.errors
    assert result.data == \
           {"fieldWithNullableStringInput": "null"}
Ejemplo n.º 35
0
def test_inline_executes_with_complex_input():
    doc = '''
    {
      fieldWithObjectInput(input: {a: "foo", b: ["bar"], c: "baz"})
    }
    '''
    ast = parse(doc)
    result = execute(schema, None, ast)
    assert not result.errors
    assert json.loads(result.data['fieldWithObjectInput']) == \
        {"a": "foo", "b": ["bar"], "c": "baz"}
Ejemplo n.º 36
0
def test_allows_non_nullable_inputs_to_be_set_to_a_value_in_a_variable():
    doc = '''
        query SetsNonNullable($value: String!) {
          fieldWithNonNullableStringInput(input: $value)
        }
    '''
    ast = parse(doc)
    result = execute(schema, None, ast, None, {'value': 'a'})
    assert not result.errors
    assert result.data == \
           {"fieldWithNonNullableStringInput": '"a"'}
Ejemplo n.º 37
0
def test_allows_non_nullable_inputs_to_be_set_to_a_value_directly():
    doc = '''
        {
          fieldWithNonNullableStringInput(input: "a")
        }
    '''
    ast = parse(doc)
    result = execute(schema, None, ast)
    assert not result.errors
    assert result.data == \
           {"fieldWithNonNullableStringInput": '"a"'}
Ejemplo n.º 38
0
def test_variable_uses_default_value_when_not_provided():
    with_defaults_ast = '''
    query q($input: TestInputObject = {a: "foo", b: ["bar"], c: "baz"}) {
        fieldWithObjectInput(input: $input)
    }
    '''
    ast = parse(with_defaults_ast)
    result = execute(schema, None, ast)
    assert not result.errors
    assert json.loads(result.data['fieldWithObjectInput']) == \
           {"a": "foo", "b": ["bar"], "c": "baz"}
Ejemplo n.º 39
0
def test_allows_nullable_inputs_to_be_omitted_in_an_unlisted_variable():
    doc = '''
    query SetsNullable {
        fieldWithNullableStringInput(input: $value)
    }
    '''
    ast = parse(doc)
    result = execute(schema, None, ast)
    assert not result.errors
    assert result.data == \
           {"fieldWithNullableStringInput": "null"}
Ejemplo n.º 40
0
def test_variable_uses_default_value_when_not_provided():
    with_defaults_ast = '''
    query q($input: TestInputObject = {a: "foo", b: ["bar"], c: "baz"}) {
        fieldWithObjectInput(input: $input)
    }
    '''
    ast = parse(with_defaults_ast)
    result = execute(schema, None, ast)
    assert not result.errors
    assert json.loads(result.data['fieldWithObjectInput']) == \
           {"a": "foo", "b": ["bar"], "c": "baz"}
Ejemplo n.º 41
0
def test_inline_properly_coerces_single_value_to_array():
    doc = '''
    {
        fieldWithObjectInput(input: {a: "foo", b: "bar", c: "baz"})
    }
    '''
    ast = parse(doc)
    result = execute(schema, None, ast)
    assert not result.errors
    assert json.loads(result.data['fieldWithObjectInput']) == \
           {"a": "foo", "b": ["bar"], "c": "baz"}
Ejemplo n.º 42
0
def test_inline_executes_with_complex_input():
    doc = '''
    {
      fieldWithObjectInput(input: {a: "foo", b: ["bar"], c: "baz"})
    }
    '''
    ast = parse(doc)
    result = execute(schema, None, ast)
    assert not result.errors
    assert json.loads(result.data['fieldWithObjectInput']) == \
        {"a": "foo", "b": ["bar"], "c": "baz"}
Ejemplo n.º 43
0
def test_inline_properly_coerces_single_value_to_array():
    doc = '''
    {
        fieldWithObjectInput(input: {a: "foo", b: "bar", c: "baz"})
    }
    '''
    ast = parse(doc)
    result = execute(schema, None, ast)
    assert not result.errors
    assert json.loads(result.data['fieldWithObjectInput']) == \
           {"a": "foo", "b": ["bar"], "c": "baz"}
Ejemplo n.º 44
0
def run(test_type, test_data):
    class Data(object):
        test = test_data

    DataType = GraphQLObjectType('DataType', lambda: {
        'test': GraphQLField(test_type),
        'nest': GraphQLField(DataType, resolver=lambda *_: Data())
    })

    schema = GraphQLSchema(DataType)
    ast = parse('{ nest { test } }')
    return execute(schema, Data(), ast)
Ejemplo n.º 45
0
def test_variable_properly_coerces_single_value_to_array():
    doc = '''
    query q($input:TestInputObject) {
        fieldWithObjectInput(input: $input)
    }
    '''
    params = {'input': {'a': 'foo', 'b': 'bar', 'c': 'baz'}}
    ast = parse(doc)
    result = execute(schema, None, ast, None, params)
    assert not result.errors
    assert json.loads(result.data['fieldWithObjectInput']) == \
           {"a": "foo", "b": ["bar"], "c": "baz"}
Ejemplo n.º 46
0
def test_variable_executes_with_complex_input():
    doc = '''
    query q($input:TestInputObject) {
        fieldWithObjectInput(input: $input)
    }
    '''
    params = {'input': {'a': 'foo', 'b': ['bar'], 'c': 'baz'}}
    ast = parse(doc)
    result = execute(schema, None, ast, None, params)
    assert not result.errors
    assert json.loads(result.data['fieldWithObjectInput']) == \
           {"a": "foo", "b": ["bar"], "c": "baz"}
Ejemplo n.º 47
0
def test_passes_along_null_for_non_nullable_inputs_if_explicitly_set_in_the_query(
):
    doc = '''
    {
        fieldWithNonNullableStringInput
    }
    '''
    ast = parse(doc)
    result = execute(schema, None, ast)
    assert not result.errors
    assert result.data == \
           {"fieldWithNonNullableStringInput": 'null'}
Ejemplo n.º 48
0
def test_variable_executes_with_complex_input():
    doc = '''
    query q($input:TestInputObject) {
        fieldWithObjectInput(input: $input)
    }
    '''
    params = {'input': {'a': 'foo', 'b': ['bar'], 'c': 'baz'}}
    ast = parse(doc)
    result = execute(schema, None, ast, None, params)
    assert not result.errors
    assert json.loads(result.data['fieldWithObjectInput']) == \
           {"a": "foo", "b": ["bar"], "c": "baz"}
Ejemplo n.º 49
0
def test_variable_properly_coerces_single_value_to_array():
    doc = '''
    query q($input:TestInputObject) {
        fieldWithObjectInput(input: $input)
    }
    '''
    params = {'input': {'a': 'foo', 'b': 'bar', 'c': 'baz'}}
    ast = parse(doc)
    result = execute(schema, None, ast, None, params)
    assert not result.errors
    assert json.loads(result.data['fieldWithObjectInput']) == \
           {"a": "foo", "b": ["bar"], "c": "baz"}
Ejemplo n.º 50
0
def test_when_no_argument_provided():
    ast = parse('{ fieldWithDefaultArgumentValue }')
    result = execute(schema, None, ast)
    assert not result.errors
    assert result.data == {'fieldWithDefaultArgumentValue': '"Hello World"'}
Ejemplo n.º 51
0
def test_when_no_argument_provided():
    ast = parse('{ fieldWithDefaultArgumentValue }')
    result = execute(schema, None, ast)
    assert not result.errors
    assert result.data == {'fieldWithDefaultArgumentValue': '"Hello World"'}