当前位置: 首页>>代码示例>>Python>>正文


Python graphql.graphql_sync方法代码示例

本文整理汇总了Python中graphql.graphql_sync方法的典型用法代码示例。如果您正苦于以下问题:Python graphql.graphql_sync方法的具体用法?Python graphql.graphql_sync怎么用?Python graphql.graphql_sync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在graphql的用法示例。


在下文中一共展示了graphql.graphql_sync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_executing_mutation_takes_scalar_args_and_returns_scalar_sum

# 需要导入模块: import graphql [as 别名]
# 或者: from graphql import graphql_sync [as 别名]
def test_executing_mutation_takes_scalar_args_and_returns_scalar_sum():
    type_defs = """
        type Query {
            _: String
        }

        type Mutation {
            sum(a: Int, b: Int): Int
        }
    """

    mutation = MutationType()
    mutation.set_field("sum", lambda *_, a, b: a + b)

    schema = make_executable_schema(type_defs, mutation)

    result = graphql_sync(schema, "mutation { sum(a: 1, b: 2) }")
    assert result.errors is None
    assert result.data == {"sum": 3} 
开发者ID:mirumee,项目名称:ariadne,代码行数:21,代码来源:test_mutations.py

示例2: test_same_type_resolver_maps_are_merged_into_executable_schema

# 需要导入模块: import graphql [as 别名]
# 或者: from graphql import graphql_sync [as 别名]
def test_same_type_resolver_maps_are_merged_into_executable_schema():
    type_defs = """
        type Query {
            hello: String
            test(data: Int): Boolean
        }
    """

    query = QueryType()
    query.set_field("hello", lambda *_: "World!")

    extending_query = QueryType()

    @extending_query.field("test")
    def resolve_test(*_, data):  # pylint: disable=unused-variable
        assert data == 4
        return True

    schema = make_executable_schema(type_defs, [query, extending_query])

    result = graphql_sync(schema, "{ hello test(data: 4) }")
    assert result.errors is None
    assert result.data == {"hello": "World!", "test": True} 
开发者ID:mirumee,项目名称:ariadne,代码行数:25,代码来源:test_modularization.py

示例3: test_different_types_resolver_maps_are_merged_into_executable_schema

# 需要导入模块: import graphql [as 别名]
# 或者: from graphql import graphql_sync [as 别名]
def test_different_types_resolver_maps_are_merged_into_executable_schema():
    type_defs = """
        type Query {
            user: User
        }

        type User {
            username: String
        }
    """

    query = QueryType()
    query.set_field("user", lambda *_: Mock(first_name="Joe"))

    user = ObjectType("User")
    user.set_alias("username", "first_name")

    schema = make_executable_schema(type_defs, [query, user])

    result = graphql_sync(schema, "{ user { username } }")
    assert result.errors is None
    assert result.data == {"user": {"username": "Joe"}} 
开发者ID:mirumee,项目名称:ariadne,代码行数:24,代码来源:test_modularization.py

示例4: test_multiple_bindables_can_be_passed_as_separate_args

# 需要导入模块: import graphql [as 别名]
# 或者: from graphql import graphql_sync [as 别名]
def test_multiple_bindables_can_be_passed_as_separate_args():
    type_defs = """
        type Query {
            user: User
        }

        type User {
            username: String
        }
    """

    query = QueryType()
    query.set_field("user", lambda *_: Mock(first_name="Joe"))

    user = ObjectType("User")
    user.set_alias("username", "first_name")

    schema = make_executable_schema(type_defs, query, user)

    result = graphql_sync(schema, "{ user { username } }")
    assert result.errors is None
    assert result.data == {"user": {"username": "Joe"}} 
开发者ID:mirumee,项目名称:ariadne,代码行数:24,代码来源:test_modularization.py

示例5: test_reference_resolver_can_be_set_using_decorator

# 需要导入模块: import graphql [as 别名]
# 或者: from graphql import graphql_sync [as 别名]
def test_reference_resolver_can_be_set_using_decorator(schema):
    obj = FederatedObjectType("Product")
    obj.reference_resolver()(lambda *_: {"name": "Malbec"})
    obj.bind_to_schema(schema)

    result = graphql_sync(
        schema,
        """
            query GetEntities($representations: [_Any!]!) {
                _entities(representations: $representations) {
                    ... on Product {
                        name
                    }
                }
            }
        """,
        variable_values={"representations": [{"__typename": "Product", "upc": 1}]},
    )

    assert result.errors is None
    assert result.data["_entities"] == [{"name": "Malbec"}] 
开发者ID:mirumee,项目名称:ariadne,代码行数:23,代码来源:test_objects.py

示例6: test_reference_resolver_can_be_set_using_setter

# 需要导入模块: import graphql [as 别名]
# 或者: from graphql import graphql_sync [as 别名]
def test_reference_resolver_can_be_set_using_setter(schema):
    obj = FederatedObjectType("Product")
    obj.reference_resolver(lambda *_: {"name": "Malbec"})
    obj.bind_to_schema(schema)

    result = graphql_sync(
        schema,
        """
            query GetEntities($representations: [_Any!]!) {
                _entities(representations: $representations) {
                    ... on Product {
                        name
                    }
                }
            }
        """,
        variable_values={"representations": [{"__typename": "Product", "upc": 1}]},
    )

    assert result.errors is None
    assert result.data["_entities"] == [{"name": "Malbec"}] 
开发者ID:mirumee,项目名称:ariadne,代码行数:23,代码来源:test_objects.py

示例7: test_multiple_field_definition_directives_replace_field_resolver_with_chainable_resolvers

# 需要导入模块: import graphql [as 别名]
# 或者: from graphql import graphql_sync [as 别名]
def test_multiple_field_definition_directives_replace_field_resolver_with_chainable_resolvers():
    type_defs = """
        directive @upper on FIELD_DEFINITION
        directive @reverse on FIELD_DEFINITION

        type Query {
            hello: String @upper @reverse
        }
    """

    query = QueryType()
    query.set_field("hello", lambda *_: "hello world")

    schema = make_executable_schema(
        type_defs,
        [query],
        directives={"upper": UpperDirective, "reverse": ReverseDirective},
    )

    result = graphql_sync(schema, "{ hello }")
    assert result.errors is None
    assert result.data == {"hello": "DLROW OLLEH"} 
开发者ID:mirumee,项目名称:ariadne,代码行数:24,代码来源:test_directives.py

示例8: test_directive_can_have_optional_argument

# 需要导入模块: import graphql [as 别名]
# 或者: from graphql import graphql_sync [as 别名]
def test_directive_can_have_optional_argument():
    type_defs = """
        directive @test(arg: String) on FIELD_DEFINITION

        type Query {
            hello: String @test
        }
    """

    query = QueryType()
    query.set_field("hello", lambda *_: "hello world")

    schema = make_executable_schema(
        type_defs, [query], directives={"test": ReturnValueDirective}
    )

    result = graphql_sync(schema, "{ hello }")
    assert result.errors is None
    assert result.data == {"hello": None} 
开发者ID:mirumee,项目名称:ariadne,代码行数:21,代码来源:test_directives.py

示例9: test_directive_can_have_required_argument

# 需要导入模块: import graphql [as 别名]
# 或者: from graphql import graphql_sync [as 别名]
def test_directive_can_have_required_argument():
    type_defs = """
        directive @test(arg: String) on FIELD_DEFINITION

        type Query {
            hello: String @test(arg: "OK!")
        }
    """

    query = QueryType()
    query.set_field("hello", lambda *_: "hello world")

    schema = make_executable_schema(
        type_defs, [query], directives={"test": ReturnValueDirective}
    )

    result = graphql_sync(schema, "{ hello }")
    assert result.errors is None
    assert result.data == {"hello": "OK!"} 
开发者ID:mirumee,项目名称:ariadne,代码行数:21,代码来源:test_directives.py

示例10: test_default_resolver_resolves_value_from_dict_item

# 需要导入模块: import graphql [as 别名]
# 或者: from graphql import graphql_sync [as 别名]
def test_default_resolver_resolves_value_from_dict_item():
    type_defs = """
        type Query {
            test: Custom
        }

        type Custom {
            node: String
        }
    """

    query = QueryType()
    query.set_field("test", lambda *_: {"node": "custom"})

    schema = make_executable_schema(type_defs, query)

    result = graphql_sync(schema, "{ test { node } }")
    assert result.errors is None
    assert result.data == {"test": {"node": "custom"}} 
开发者ID:mirumee,项目名称:ariadne,代码行数:21,代码来源:test_queries.py

示例11: test_default_resolver_resolves_value_from_object_attr

# 需要导入模块: import graphql [as 别名]
# 或者: from graphql import graphql_sync [as 别名]
def test_default_resolver_resolves_value_from_object_attr():
    type_defs = """
        type Query {
            test: Custom
        }

        type Custom {
            node: String
        }
    """

    query = QueryType()
    query.set_field("test", lambda *_: Mock(node="custom"))

    schema = make_executable_schema(type_defs, query)

    result = graphql_sync(schema, "{ test { node } }")
    assert result.errors is None
    assert result.data == {"test": {"node": "custom"}} 
开发者ID:mirumee,项目名称:ariadne,代码行数:21,代码来源:test_queries.py

示例12: test_custom_and_default_resolvers_are_combined_to_resolve_custom_type_fields

# 需要导入模块: import graphql [as 别名]
# 或者: from graphql import graphql_sync [as 别名]
def test_custom_and_default_resolvers_are_combined_to_resolve_custom_type_fields():
    type_defs = """
        type Query {
            test: Custom
        }

        type Custom {
            node: String
            default: String
        }
    """

    query = QueryType()
    query.set_field("test", lambda *_: {"node": "custom", "default": "ok"})

    custom = ObjectType("Custom")
    custom.set_field("node", lambda *_: "deep")

    schema = make_executable_schema(type_defs, [query, custom])

    result = graphql_sync(schema, "{ test { node default } }")
    assert result.errors is None
    assert result.data == {"test": {"node": "deep", "default": "ok"}} 
开发者ID:mirumee,项目名称:ariadne,代码行数:25,代码来源:test_queries.py

示例13: test_custom_resolver_is_called_with_arguments_passed_with_query

# 需要导入模块: import graphql [as 别名]
# 或者: from graphql import graphql_sync [as 别名]
def test_custom_resolver_is_called_with_arguments_passed_with_query():
    type_defs = """
        type Query {
            test(returnValue: Int!): Int
        }
    """

    query = QueryType()

    @query.field("test")
    def resolve_test(*_, returnValue):  # pylint: disable=unused-variable
        assert returnValue == 4
        return "42"

    schema = make_executable_schema(type_defs, query)

    result = graphql_sync(schema, "{ test(returnValue: 4) }")
    assert result.errors is None
    assert result.data == {"test": 42} 
开发者ID:mirumee,项目名称:ariadne,代码行数:21,代码来源:test_queries.py

示例14: test_custom_resolver_is_called_with_input_type_value_as_dict

# 需要导入模块: import graphql [as 别名]
# 或者: from graphql import graphql_sync [as 别名]
def test_custom_resolver_is_called_with_input_type_value_as_dict():
    type_defs = """
        type Query {
            test(data: TestInput): Int
        }

        input TestInput {
            value: Int
        }
    """

    query = QueryType()

    @query.field("test")
    def resolve_test(*_, data):  # pylint: disable=unused-variable
        assert data == {"value": 4}
        return "42"

    schema = make_executable_schema(type_defs, query)

    result = graphql_sync(schema, "{ test(data: { value: 4 }) }")
    assert result.errors is None
    assert result.data == {"test": 42} 
开发者ID:mirumee,项目名称:ariadne,代码行数:25,代码来源:test_queries.py

示例15: test_executing_mutation_takes_scalar_arg_and_returns_type

# 需要导入模块: import graphql [as 别名]
# 或者: from graphql import graphql_sync [as 别名]
def test_executing_mutation_takes_scalar_arg_and_returns_type():
    type_defs = """
        type Query {
            _: String
        }

        type Staff {
            name: String
        }

        type Mutation {
            addStaff(name: String): Staff
        }
    """

    mutation = MutationType()

    @mutation.field("addStaff")
    def resolve_add_staff(*_, name):  # pylint: disable=unused-variable
        assert name == "Bob"
        return {"name": name}

    schema = make_executable_schema(type_defs, mutation)

    result = graphql_sync(schema, 'mutation { addStaff(name: "Bob") { name } }')
    assert result.errors is None
    assert result.data == {"addStaff": {"name": "Bob"}} 
开发者ID:mirumee,项目名称:ariadne,代码行数:29,代码来源:test_mutations.py


注:本文中的graphql.graphql_sync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。