コード例 #1
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
コード例 #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
コード例 #3
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
コード例 #4
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
コード例 #5
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
コード例 #6
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
コード例 #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
コード例 #8
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
コード例 #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
コード例 #10
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
コード例 #11
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
コード例 #12
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
コード例 #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
コード例 #14
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
コード例 #15
0
ファイル: test_executor.py プロジェクト: rawls238/graphql-py
def test_raises_the_inline_operation_if_no_operation_is_provided():
    doc = 'query Example { a } query OtherExample { a }'
    class Data(object):
        a = 'b'
    ast = parse(doc)
    Type = GraphQLObjectType('Type', {
        'a': GraphQLField(GraphQLString)
    })
    with raises(GraphQLError) as excinfo:
        execute(GraphQLSchema(Type), Data(), ast)
    assert 'Must provide operation name if query contains multiple operations' in str(excinfo.value)
コード例 #16
0
ファイル: test_executor.py プロジェクト: faassen/graphql-core
def test_raises_the_inline_operation_if_no_operation_is_provided():
    doc = 'query Example { a } query OtherExample { a }'

    class Data(object):
        a = 'b'

    ast = parse(doc)
    Type = GraphQLObjectType('Type', {'a': GraphQLField(GraphQLString)})
    with raises(GraphQLError) as excinfo:
        execute(GraphQLSchema(Type), Data(), ast)
    assert 'Must provide operation name if query contains multiple operations' in str(
        excinfo.value)
def test_fails_to_execute_a_query_containing_a_type_definition():
    query = parse('''
    { foo }

    type Query { foo: String }
    ''')

    schema = GraphQLSchema(
        GraphQLObjectType(name='Query',
                          fields={'foo': GraphQLField(GraphQLString)}))

    with raises(GraphQLError) as excinfo:
        execute(schema, None, query)

    assert excinfo.value.message == 'GraphQL cannot execute a request containing a ObjectTypeDefinition.'
コード例 #18
0
ファイル: test_executor.py プロジェクト: faassen/graphql-core
def test_fails_when_an_is_type_of_check_is_not_met():
    class Special(object):
        def __init__(self, value):
            self.value = value

    class NotSpecial(object):
        def __init__(self, value):
            self.value = value

    SpecialType = GraphQLObjectType(
        "SpecialType",
        fields={"value": GraphQLField(GraphQLString)},
        is_type_of=lambda obj, info: isinstance(obj, Special),
    )

    schema = GraphQLSchema(
        GraphQLObjectType(
            name="Query",
            fields={"specials": GraphQLField(GraphQLList(SpecialType), resolver=lambda root, *_: root["specials"])},
        )
    )

    query = parse("{ specials { value } }")
    value = {"specials": [Special("foo"), NotSpecial("bar")]}

    result = execute(schema, value, query)

    assert result.data == {"specials": [{"value": "foo"}, None]}

    assert 'Expected value of type "SpecialType" but got NotSpecial.' in str(result.errors)
コード例 #19
0
def test_nulls_out_error_subtrees():
    doc = '''{
        ok,
        error
    }'''

    class Data(object):

        def ok(self):
            return 'ok'

        def error(self):
            raise Exception('Error getting error')

    doc_ast = parse(doc)

    Type = GraphQLObjectType('Type', {
        'ok': GraphQLField(GraphQLString),
        'error': GraphQLField(GraphQLString),
    })

    result = execute(GraphQLSchema(Type), Data(), doc_ast)
    assert result.data == {'ok': 'ok', 'error': None}
    assert len(result.errors) == 1
    assert result.errors[0].message == 'Error getting error'
コード例 #20
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"'}
コード例 #21
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"'}
コード例 #22
0
def test_gets_execution_info_in_resolver():
    encountered_schema = [None]
    encountered_root_value = [None]

    def resolve_type(obj, info):
        encountered_schema[0] = info.schema
        encountered_root_value[0] = info.root_value
        return PersonType2

    NamedType2 = GraphQLInterfaceType(
        name='Named',
        fields={'name': GraphQLField(GraphQLString)},
        resolve_type=resolve_type)

    PersonType2 = GraphQLObjectType(name='Person',
                                    interfaces=[NamedType2],
                                    fields={
                                        'name':
                                        GraphQLField(GraphQLString),
                                        'friends':
                                        GraphQLField(GraphQLList(NamedType2))
                                    })

    schema2 = GraphQLSchema(query=PersonType2)
    john2 = Person('John', [], [liz])
    ast = parse('''{ name, friends { name } }''')

    result = execute(schema2, john2, ast)
    assert result.data == {'name': 'John', 'friends': [{'name': 'Liz'}]}

    assert encountered_schema[0] == schema2
    assert encountered_root_value[0] == john2
コード例 #23
0
ファイル: test_executor.py プロジェクト: faassen/graphql-core
def test_fails_when_an_is_type_of_check_is_not_met():
    class Special(object):
        def __init__(self, value):
            self.value = value

    class NotSpecial(object):
        def __init__(self, value):
            self.value = value

    SpecialType = GraphQLObjectType(
        'SpecialType',
        fields={
            'value': GraphQLField(GraphQLString),
        },
        is_type_of=lambda obj, info: isinstance(obj, Special))

    schema = GraphQLSchema(
        GraphQLObjectType(name='Query',
                          fields={
                              'specials':
                              GraphQLField(
                                  GraphQLList(SpecialType),
                                  resolver=lambda root, *_: root['specials'])
                          }))

    query = parse('{ specials { value } }')
    value = {'specials': [Special('foo'), NotSpecial('bar')]}

    result = execute(schema, value, query)

    assert result.data == {'specials': [{'value': 'foo'}, None]}

    assert 'Expected value of type "SpecialType" but got NotSpecial.' in str(
        result.errors)
コード例 #24
0
def test_executes_using_union_types():
    # NOTE: This is an *invalid* query, but it should be an *executable* query.
    ast = parse('''
        {
            __typename
            name
            pets {
                __typename
                name
                barks
                meows
            }
        }
    ''')
    result = execute(schema, john, ast)
    assert not result.errors
    assert result.data == {
        '__typename':
        'Person',
        'name':
        'John',
        'pets': [{
            '__typename': 'Cat',
            'name': 'Garfield',
            'meows': False
        }, {
            '__typename': 'Dog',
            'name': 'Odie',
            'barks': True
        }]
    }
コード例 #25
0
ファイル: test_executor.py プロジェクト: faassen/graphql-core
def test_correctly_threads_arguments():
    doc = """
        query Example {
            b(numArg: 123, stringArg: "foo")
        }
    """

    def resolver(_, args, *_args):
        assert args["numArg"] == 123
        assert args["stringArg"] == "foo"
        resolver.got_here = True

    resolver.got_here = False

    doc_ast = parse(doc)

    Type = GraphQLObjectType(
        "Type",
        {
            "b": GraphQLField(
                GraphQLString,
                args={"numArg": GraphQLArgument(GraphQLInt), "stringArg": GraphQLArgument(GraphQLString)},
                resolver=resolver,
            )
        },
    )

    result = execute(GraphQLSchema(Type), None, doc_ast, "Example", {})
    assert not result.errors
    assert resolver.got_here
コード例 #26
0
def test_executes_using_interface_types():
    # NOTE: This is an *invalid* query, but it should be an *executable* query.
    ast = parse('''
      {
        __typename
        name
        friends {
          __typename
          name
          barks
          meows
        }
      }
    ''')
    result = execute(schema, john, ast)
    assert not result.errors
    assert result.data == {
        '__typename':
        'Person',
        'name':
        'John',
        'friends': [{
            '__typename': 'Person',
            'name': 'Liz'
        }, {
            '__typename': 'Dog',
            'name': 'Odie',
            'barks': True
        }]
    }
コード例 #27
0
def test_executes_union_types_with_inline_fragment():
    # This is the valid version of the query in the above test.
    ast = parse('''
      {
        __typename
        name
        pets {
          __typename
          ... on Dog {
            name
            barks
          }
          ... on Cat {
            name
            meows
          }
        }
      }
    ''')
    result = execute(schema, john, ast)
    assert not result.errors
    assert result.data == {
        '__typename': 'Person',
        'name': 'John',
        'pets': [
            {'__typename': 'Cat', 'name': 'Garfield', 'meows': False},
            {'__typename': 'Dog', 'name': 'Odie', 'barks': True}
        ]
    }
コード例 #28
0
def test_executes_interface_types_with_inline_fragment():
    # This is the valid version of the query in the above test.
    ast = parse('''
      {
        __typename
        name
        friends {
          __typename
          name
          ... on Dog {
            barks
          }
          ... on Cat {
            meows
          }
        }
      }
    ''')
    result = execute(schema, john, ast)
    assert not result.errors
    assert result.data == {
        '__typename':
        'Person',
        'name':
        'John',
        'friends': [{
            '__typename': 'Person',
            'name': 'Liz'
        }, {
            '__typename': 'Dog',
            'name': 'Odie',
            'barks': True
        }]
    }
コード例 #29
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"'}
コード例 #30
0
def test_nulls_a_complex_tree_of_nullable_fields_that_returns_null():
    doc = '''
      query Q {
        nest {
          sync
          #promise
          nest {
            sync
            #promise
          }
          #promiseNest {
          #  sync
          #  promise
          #}
        }
        #promiseNest {
        #  sync
        #  promise
        #  nest {
        #    sync
        #    promise
        #  }
        #  promiseNest {
        #    sync
        #    promise
        #  }
        #}
      }
    '''
    ast = parse(doc)
    result = execute(schema, NullingData(), ast, 'Q', {})
    assert not result.errors
    assert result.data == {'nest': {'sync': None, 'nest': {'sync': None}}}
コード例 #31
0
ファイル: test_mutations.py プロジェクト: rawls238/graphql-py
def test_evaluates_mutations_serially():
    doc = '''mutation M {
      first: immediatelyChangeTheNumber(newNumber: 1) {
        theNumber
      },
      second: promiseToChangeTheNumber(newNumber: 2) {
        theNumber
      },
      third: immediatelyChangeTheNumber(newNumber: 3) {
        theNumber
      }
      fourth: promiseToChangeTheNumber(newNumber: 4) {
        theNumber
      },
      fifth: immediatelyChangeTheNumber(newNumber: 5) {
        theNumber
      }
    }'''
    ast = parse(doc)
    result = execute(schema, Root(6), ast, 'M')
    assert not result.errors
    assert result.data == \
        {
            'first': {'theNumber': 1},
            'second': {'theNumber': 2},
            'third': {'theNumber': 3},
            'fourth': {'theNumber': 4},
            'fifth': {'theNumber': 5},
        }
コード例 #32
0
def test_executes_union_types_with_inline_fragment():
    # This is the valid version of the query in the above test.
    ast = parse('''
      {
        __typename
        name
        pets {
          __typename
          ... on Dog {
            name
            barks
          }
          ... on Cat {
            name
            meows
          }
        }
      }
    ''')
    result = execute(schema, john, ast)
    assert not result.errors
    assert result.data == {
        '__typename': 'Person',
        'name': 'John',
        'pets': [
            {'__typename': 'Cat', 'name': 'Garfield', 'meows': False},
            {'__typename': 'Dog', 'name': 'Odie', 'barks': True}
        ]
    }
コード例 #33
0
def test_correctly_threads_arguments():
    doc = '''
        query Example {
            b(numArg: 123, stringArg: "foo")
        }
    '''

    def resolver(_, args, *_args):
        assert args['numArg'] == 123
        assert args['stringArg'] == 'foo'
        resolver.got_here = True

    resolver.got_here = False

    doc_ast = parse(doc)

    Type = GraphQLObjectType('Type', {
        'b': GraphQLField(
            GraphQLString,
            args={
                'numArg': GraphQLArgument(GraphQLInt),
                'stringArg': GraphQLArgument(GraphQLString),
            },
            resolver=resolver),
    })

    result = execute(GraphQLSchema(Type), None, doc_ast, 'Example', {})
    assert not result.errors
    assert resolver.got_here
コード例 #34
0
def test_supports_the_type_root_field():
    TestType = GraphQLObjectType("TestType", {"testField": GraphQLField(GraphQLString)})
    schema = GraphQLSchema(TestType)
    request = '{ __type(name: "TestType") { name } }'
    result = execute(schema, object(), parse(request))
    assert not result.errors
    assert result.data == {"__type": {"name": "TestType"}}
def test_evaluates_mutations_serially():
    doc = '''mutation M {
      first: immediatelyChangeTheNumber(newNumber: 1) {
        theNumber
      },
      second: promiseToChangeTheNumber(newNumber: 2) {
        theNumber
      },
      third: immediatelyChangeTheNumber(newNumber: 3) {
        theNumber
      }
      fourth: promiseToChangeTheNumber(newNumber: 4) {
        theNumber
      },
      fifth: immediatelyChangeTheNumber(newNumber: 5) {
        theNumber
      }
    }'''
    ast = parse(doc)
    result = execute(schema, Root(6), ast, 'M')
    assert not result.errors
    assert result.data == \
        {
            'first': {'theNumber': 1},
            'second': {'theNumber': 2},
            'third': {'theNumber': 3},
            'fourth': {'theNumber': 4},
            'fifth': {'theNumber': 5},
        }
コード例 #36
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"'}
コード例 #37
0
def test_executes_interface_types_with_inline_fragment():
    # This is the valid version of the query in the above test.
    ast = parse('''
      {
        __typename
        name
        friends {
          __typename
          name
          ... on Dog {
            barks
          }
          ... on Cat {
            meows
          }
        }
      }
    ''')
    result = execute(schema, john, ast)
    assert not result.errors
    assert result.data == {
        '__typename': 'Person',
        'name': 'John',
        'friends': [
            {'__typename': 'Person', 'name': 'Liz'},
            {'__typename': 'Dog', 'name': 'Odie', 'barks': True}
        ]
    }
コード例 #38
0
ファイル: test_executor.py プロジェクト: faassen/graphql-core
def test_does_not_include_illegal_fields_in_output():
    doc = "mutation M { thisIsIllegalDontIncludeMe }"
    ast = parse(doc)
    Q = GraphQLObjectType("Q", {"a": GraphQLField(GraphQLString)})
    M = GraphQLObjectType("M", {"c": GraphQLField(GraphQLString)})
    result = execute(GraphQLSchema(Q, M), None, ast)
    assert not result.errors
    assert result.data == {}
コード例 #39
0
def test_supports_the_type_root_field():
    TestType = GraphQLObjectType('TestType',
                                 {'testField': GraphQLField(GraphQLString)})
    schema = GraphQLSchema(TestType)
    request = '{ __type(name: "TestType") { name } }'
    result = execute(schema, object(), parse(request))
    assert not result.errors
    assert result.data == {'__type': {'name': 'TestType'}}
コード例 #40
0
ファイル: test_executor.py プロジェクト: faassen/graphql-core
def test_does_not_include_illegal_fields_in_output():
    doc = 'mutation M { thisIsIllegalDontIncludeMe }'
    ast = parse(doc)
    Q = GraphQLObjectType('Q', {'a': GraphQLField(GraphQLString)})
    M = GraphQLObjectType('M', {'c': GraphQLField(GraphQLString)})
    result = execute(GraphQLSchema(Q, M), None, ast)
    assert not result.errors
    assert result.data == {}
コード例 #41
0
def test_supports_the_type_root_field():
    TestType = GraphQLObjectType('TestType', {
        'testField': GraphQLField(GraphQLString)
    })
    schema = GraphQLSchema(TestType)
    request = '{ __type(name: "TestType") { name } }'
    result = execute(schema, object(), parse(request))
    assert not result.errors
    assert result.data == {'__type': {'name': 'TestType'}}
コード例 #42
0
def test_can_introspect_on_union_and_intersection_types():
    ast = parse('''
    {
        Named: __type(name: "Named") {
            kind
            name
            fields { name }
            interfaces { name }
            possibleTypes { name }
            enumValues { name }
            inputFields { name }
        }
        Pet: __type(name: "Pet") {
            kind
            name
            fields { name }
            interfaces { name }
            possibleTypes { name }
            enumValues { name }
            inputFields { name }
        }
    }''')

    result = execute(schema, None, ast)
    assert result.data == {
        'Named': {
            'enumValues': None,
            'name': 'Named',
            'kind': 'INTERFACE',
            'interfaces': None,
            'fields': [{
                'name': 'name'
            }],
            'possibleTypes': [{
                'name': 'Dog'
            }, {
                'name': 'Cat'
            }, {
                'name': 'Person'
            }],
            'inputFields': None
        },
        'Pet': {
            'enumValues': None,
            'name': 'Pet',
            'kind': 'UNION',
            'interfaces': None,
            'fields': None,
            'possibleTypes': [{
                'name': 'Dog'
            }, {
                'name': 'Cat'
            }],
            'inputFields': None
        }
    }
コード例 #43
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"]'}
コード例 #44
0
ファイル: test_nonnull.py プロジェクト: rawls238/graphql-py
def test_nulls_the_top_level_if_sync_non_nullable_field_returns_null():
    doc = '''
        query Q { nonNullSync }
    '''
    ast = parse(doc)
    result = execute(schema, NullingData(), ast)
    assert result.data is None
    assert len(result.errors) == 1
    # TODO: check error location
    assert result.errors[0]['message'] == 'Cannot return null for non-nullable type.'
コード例 #45
0
ファイル: test_nonnull.py プロジェクト: rawls238/graphql-py
def test_nulls_the_top_level_if_sync_non_nullable_field_throws():
    doc = '''
        query Q { nonNullSync }
    '''
    ast = parse(doc)
    result = execute(schema, ThrowingData(), ast)
    assert result.data is None
    assert len(result.errors) == 1
    # TODO: check error location
    assert result.errors[0]['message'] == non_null_sync_error.message
コード例 #46
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"]'}
コード例 #47
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"]'}
コード例 #48
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'}
コード例 #49
0
def test_nulls_the_top_level_if_sync_non_nullable_field_throws():
    doc = '''
        query Q { nonNullSync }
    '''
    ast = parse(doc)
    result = execute(schema, ThrowingData(), ast)
    assert result.data is None
    assert len(result.errors) == 1
    # TODO: check error location
    assert result.errors[0]['message'] == str(non_null_sync_error)
コード例 #50
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"]'}
コード例 #51
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
コード例 #52
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'}
コード例 #53
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"]'}
コード例 #54
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
コード例 #55
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"]'}
コード例 #56
0
def test_nulls_a_nullable_field_that_returns_null():
    doc = '''
        query Q {
            sync
        }
    '''
    ast = parse(doc)
    result = execute(schema, NullingData(), ast, 'Q', {})
    assert not result.errors
    assert result.data == {'sync': None}
コード例 #57
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"}
コード例 #58
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'}
コード例 #59
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"}